PHPackages                             modulargaming/search - 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. [Search &amp; Filtering](/categories/search)
4. /
5. modulargaming/search

ActiveModulargaming-module[Search &amp; Filtering](/categories/search)

modulargaming/search
====================

Search module for Modular Gaming

011PHP

Since Mar 22Pushed 12y ago3 watchersCompare

[ Source](https://github.com/modulargaming/search)[ Packagist](https://packagist.org/packages/modulargaming/search)[ RSS](/packages/modulargaming-search/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

[Modular Gaming Search](http://www.modulargaming.com)
=====================================================

[](#modular-gaming-search)

Search is a module for [Modular Gaming](https://github.com/modulargaming/modulargaming), a modular [persistent browser based game](http://www.pbbg.org) framework.

It implements a search system using [ElasticSearch](http://www.elasticsearch.org/).

Requirements
------------

[](#requirements)

- PHP 5.4+
- ElasticSearch
- [Composer](http://getcomposer.org) (Dependency Manager)

Installation
------------

[](#installation)

Search is installed using composer, simply add it as a dependency to your `composer.json` file:

```
{
	"require": {
		"modulargaming/search": "~0.1.0"
	}
}
```

Copy the configuration file, config/search.php to your application directory and edit it to match your settings.

Using
-----

[](#using)

### Models, Saving

[](#models-saving)

Searchable models need to use the Model\_ElasticSearch trait, and implement the functions `get_search_document` and `send_search_mapping`.

```
class Model_User extends MG_Model_User {
	use Model_ElasticSearch;

	/**
	 * @return \Elastica\Document
	 */
	public function get_search_document() {
		return new \Elastica\Document($this->id, array(
			'id'       => $this->id,
			'username' => $this->username
		));
	}

	/**
	 * @return \Elastica\Type\Mapping
	 */
	public function send_search_mapping()
	{
		$type = ElasticSearch::instance()->get_type($this->_search_type());

		$mapping = new \Elastica\Type\Mapping();
		$mapping->setType($type);

		// Set mapping
		$mapping->setProperties(array(
			'id'       => array('type' => 'integer', 'include_in_all' => FALSE),
			'username' => array('type' => 'string', 'include_in_all' => TRUE),
		));

		// Send mapping to type
		$mapping->send();
	}
}
```

The mapping can either be set with the Minion Task `php ./minion Search:mapping --model=User` or manually entered into ElasticSearch.

All changes to a searchable model will also send the matching queries to ElasticSearch to keep them matching.

Worth noting is that ALL changes will trigger a search query update, this can be changed by overwriting the update function to only call the trait::update if related property was changed.

The search indexes can be rebuilt using the Minion Task `php ./minion Search:index --model=User`.

### Search page, Retrieving

[](#search-page-retrieving)

The search page currently searches the whole index for matching records. Each search result gets parsed with a view class matching the search type (\_type).

Examples
--------

[](#examples)

The example User model. Notice we only trigger the update if the username property was changed.

```
class Model_User extends MG_Model_User {
	use Model_ElasticSearch {
		update as _traitUpdate;
	}

	/**
	 * @return \Elastica\Document
	 */
	public function get_search_document() {
		return new \Elastica\Document($this->id, array(
			'id'       => $this->id,
			'username' => $this->username
		));
	}

	/**
	 * @return \Elastica\Type\Mapping
	 */
	public function send_search_mapping()
	{
		$type = ElasticSearch::instance()->get_type($this->_search_type());

		$mapping = new \Elastica\Type\Mapping();
		$mapping->setType($type);

		// Set mapping
		$mapping->setProperties(array(
			'id'       => array('type' => 'integer', 'include_in_all' => FALSE),
			'username' => array('type' => 'string', 'include_in_all' => TRUE),
		));

		// Send mapping to type
		$mapping->send();
	}

	/**
	 * Ensure we only update if the username was changed, to prevent useless queries at login (last_login).
	 *
	 * @param Validation $validation
	 * @return $this|ORM
	 */
	public function update(Validation $validation = NULL)
	{
		if ($this->changed('username'))
		{
			$this->_traitUpdate($validation);
		}
		else
		{
			parent::update($validation);
		}

		return $this;
	}
}
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d8255c65eec7e6cf302650813a90df65b599e35041077f9805185ab2e355a65?d=identicon)[modulargaming](/maintainers/modulargaming)

---

Top Contributors

[![Hinton](https://avatars.githubusercontent.com/u/137855?v=4)](https://github.com/Hinton "Hinton (1 commits)")

### Embed Badge

![Health badge](/badges/modulargaming-search/health.svg)

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

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[shyim/opensearch-php-dsl

OpenSearch/Elasticsearch DSL library

175.9M9](/packages/shyim-opensearch-php-dsl)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)

PHPackages © 2026

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