PHPackages                             wieni/wmsearch - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. wieni/wmsearch

ActiveDrupal-module[API Development](/categories/api)

wieni/wmsearch
==============

Elasticsearch api

0.13.0(11mo ago)020.6k↓42.4%2[6 issues](https://github.com/wieni/wmsearch/issues)GPL-3.0-onlyPHPPHP &gt;=7.0.0

Since May 5Pushed 11mo ago4 watchersCompare

[ Source](https://github.com/wieni/wmsearch)[ Packagist](https://packagist.org/packages/wieni/wmsearch)[ RSS](/packages/wieni-wmsearch/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (71)Used By (0)

WMSearch
========

[](#wmsearch)

Manages an index with a single document type `page`

The api allows adding different document types but only `page` is 'managed'.

Elasticsearch support
---------------------

[](#elasticsearch-support)

Elasticsearch versionLast releaseDevelopment branch5.x0.9.6release/v0.96.x/feature/elastic-6.x7.x0.11.0mainAPI
===

[](#api)

inject `wmsearch.api.index`

Index
-----

[](#index)

`$api->createIndex();`

`$api->deleteIndex();`

Document
--------

[](#document)

`$api->addDoc(ElasticEntityInterface $entity); // upsert`

`$api->delDoc($id);`

`$api->getDoc($id);`

Search
------

[](#search)

`$api->search(QueryInterface) : SearchResult`

```
// Identical to ->search() but strips html from highlights
$api->highlightSearch(QueryInterface) : SearchResult

```

Misc
----

[](#misc)

`$api->health(); // simple http elastic healthcheck`

`$api->refresh() // reopen lucene index`

`$api->flush() // fsync the lucene index`

JSON
====

[](#json)

GET /search/json?q=lorem%20ipsum&amp;o=0&amp;a=10

```
q  string The query
o  int    The offset
a int    Amount of items

```

Drush
=====

[](#drush)

```
drush wmsp                      # Recreate the current index, removing all documents. Alias for wmsearch:purge
drush wmsq                      # Queue content for indexing. Alias for wmsearch:queue
drush queue:run wmsearch.index  # Index queued content
drush wmsc                      # Create a new index. Alias for wmsearch-index-create
drush wmsri                     # Rename an existing index. Alias for wmsearch-reindex

```

Config
======

[](#config)

```
# The elastic endpoint uri
wmsearch.elastic.endpoint: 'http://localhost:9200'

# Name of the index
wmsearch.elastic.index: 'mysite-staging'

# Serve a quick'n dirty site search on /simple-search
wmsearch.simple_search: false

# Default JSON endpoint
wmsearch.json.path: '/search/json'

# Formatter class for the JSON endpoint
wmsearch.json.formatter.class: 'Drupal\wmsearch\Service\ResultFormatter'

# Query provider for the JSON endpoint
wmsearch.json.query_builder.class: 'Drupal\wmsearch\Service\QueryBuilder'
```

License
=======

[](#license)

GPL

Examples
========

[](#examples)

ElasticEntityInterface
----------------------

[](#elasticentityinterface)

This assumes [wieni/wmmodel](https://github.com/wieni/wmmodel) or something similar.

```
class Article extends Node implements WmModelInterface, ElasticEntityInterface
{
    use EntityPageTrait;

    public function getElasticTypes()
    {
        return ['page'];
    }

    public function getElasticDocumentCollection($type)
    {
        return 'mymodule.elastic.article.collection';
    }
}
```

EntityDocumentCollectionInterface
---------------------------------

[](#entitydocumentcollectioninterface)

```
# mymodule.services.yml
services:
    mymodule.elastic.article.collection:
        class: Drupal\mymodule\Service\Elastic\Collection\ArticleCollection
```

```
namespace Drupal\mymodule\Service\Elastic\Collection;

use Drupal\wmsearch\Entity\Document\EntityDocumentCollection;
use Drupal\wmsearch\Exception\NotIndexableException;

class ArticleCollection extends EntityDocumentCollection
{
    /** @var \Drupal\mymodule\Entity\Node\Article */
    protected $entity;

    public function toElasticArray($elasticId)
    {
        if (!$this->entity->isPublished()) {
            throw new NotIndexableException();
        }

        return [
            'id' => $this->entity->id(), // this isn't the elasticId
            'title' => $this->entity->getTitle(),
            'url' => $this->entity->toUrl()->toString(),
            'language' => $this->entity->language()->getId(),
            // ...
        ];
    }
}
```

Programmatically index
----------------------

[](#programmatically-index)

```
$article = $nodeStorage->load(123);
$api->addDoc($dish);

```

Query
-----

[](#query)

Search

```
$perPage = 10;
$page = (int) $req->query->get('page');
$input = $req->query->get('q', '');

$query = new PageQuery();
$query->from($perPage * $page)
    ->size($perPage)
    ->setHighlight(1, 120, ['title', 'intro'], '', '')
    ->addMultiMatch($input, ['title', 'intro', 'body']);

$formatter->format($api->highlightSearch($query));
```

Completion

```
$query = new PageQuery();
    ->setSource('')
    ->complete($input, 2);

$formatter->format($api->search($query));
```

TODO
====

[](#todo)

- DocumentInterface examples
- wmmodel implementation + reindex

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance50

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~46 days

Recently: every ~157 days

Total

64

Last Release

349d ago

PHP version history (2 changes)0.8.2PHP &gt;=7.0.0

0.9.12PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/734199ae17f8da336fef9ba81f7c37cda09b0f9a952f551235c32ecfad68488b?d=identicon)[Wieni](/maintainers/Wieni)

---

Top Contributors

[![DieterHolvoet](https://avatars.githubusercontent.com/u/3606531?v=4)](https://github.com/DieterHolvoet "DieterHolvoet (68 commits)")[![frizinak](https://avatars.githubusercontent.com/u/823696?v=4)](https://github.com/frizinak "frizinak (33 commits)")[![RobinHoutevelts](https://avatars.githubusercontent.com/u/9056689?v=4)](https://github.com/RobinHoutevelts "RobinHoutevelts (30 commits)")[![akasake](https://avatars.githubusercontent.com/u/32063989?v=4)](https://github.com/akasake "akasake (7 commits)")[![benjamintoussaint](https://avatars.githubusercontent.com/u/7239074?v=4)](https://github.com/benjamintoussaint "benjamintoussaint (3 commits)")[![HnLn](https://avatars.githubusercontent.com/u/5806950?v=4)](https://github.com/HnLn "HnLn (2 commits)")[![ponkiwonki](https://avatars.githubusercontent.com/u/106490855?v=4)](https://github.com/ponkiwonki "ponkiwonki (2 commits)")

### Embed Badge

![Health badge](/badges/wieni-wmsearch/health.svg)

```
[![Health](https://phpackages.com/badges/wieni-wmsearch/health.svg)](https://phpackages.com/packages/wieni-wmsearch)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
