PHPackages                             netgen/query-translator - 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. netgen/query-translator

ActiveLibrary[Search &amp; Filtering](/categories/search)

netgen/query-translator
=======================

Query Translator is a search query translator with AST representation

1.1.0(4y ago)2042.0M↓18.9%11[2 issues](https://github.com/netgen/query-translator/issues)[1 PRs](https://github.com/netgen/query-translator/pulls)5MITPHPPHP ^7.0||^8.0CI passing

Since Mar 23Pushed 3mo ago12 watchersCompare

[ Source](https://github.com/netgen/query-translator)[ Packagist](https://packagist.org/packages/netgen/query-translator)[ Docs](https://github.com/netgen/query-translator)[ RSS](/packages/netgen-query-translator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (7)Used By (5)

Query Translator
================

[](#query-translator)

[![Build Status](https://camo.githubusercontent.com/c36bcf8fd90e20f814106c0311210d45db8a02ccffa53de14a1c5d0acfc5e814/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e657467656e2f71756572792d7472616e736c61746f722f74657374732e796d6c3f6272616e63683d6d617374657226267374796c653d666c61742d737175617265)](https://github.com/netgen/query-translator/actions?query=workflow%3ATests)[![Code Coverage](https://camo.githubusercontent.com/5becb4185f8a01ad4585d5b3ea326a31e6a85da0d08bf336fe52dd2c146ee33b/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6e657467656e2f71756572792d7472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/netgen/query-translator)[![Downloads](https://camo.githubusercontent.com/f9d22ddda778b74a6e0ef0f71206a6149b363f348708b46177de56215f1028d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e657467656e2f71756572792d7472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/netgen/query-translator)[![Latest stable](https://camo.githubusercontent.com/86292a33a87332d0e263b834bf650dec5e6f9fd6be21febc35aac56bc019128b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e657467656e2f71756572792d7472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/netgen/query-translator)[![License](https://camo.githubusercontent.com/adaa062ce4bd48329a2cb96d59c428cfe974be969a2ca4eec2aa5b5c4eede51b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e657467656e2f71756572792d7472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/netgen/query-translator)[![PHP](https://camo.githubusercontent.com/86e7d829a466cacd5658a22073e27d49d39dac72cc18216ac4963ed5463c5bbc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e362d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://secure.php.net/)[![Ask DeepWiki](https://camo.githubusercontent.com/0f5ae213ac378635adeb5d7f13cef055ad2f7d9a47b36de7b1c67dbe09f609ca/68747470733a2f2f6465657077696b692e636f6d2f62616467652e737667)](https://deepwiki.com/netgen/query-translator)

Query Translator takes a search string as user input and converts it into something a search backend can understand. Technically, it's a search query [translator](https://en.wikipedia.org/wiki/Translator_(computing)) with [abstract syntax tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) representation. From the produced syntax tree, translation target can be anything you need. Usually it's a search backend, like Solr and Elasticsearch, or a database abstraction layer.

A set of interfaces for implementing a language processor is provided, with a single implemented language named [Galach](lib/Languages/Galach). Galach implements a syntax that is based on what seems to be the unofficial standard for search query as user input. Quick cheat sheet:

`word` `"phrase"` `(group)` `+mandatory` `-prohibited` `AND` `&&` `OR` `||` `NOT` `!` `#tag` `@user``domain:term`

### Error handling

[](#error-handling)

User input means you have to expect errors and handle them gracefully. Because of that, the parser is completely resistant to errors. Syntax tree will contain detailed information about corrections applied to make sense of the user input. This can be useful to clean up the input or implement rich input interface, with features like suggestions, syntax highlighting and error feedback.

### Customization

[](#customization)

The implementation was made with customization in mind. You can change the special characters which will be used as part of the syntax, pick out elements of the language you want to use, implement your own term clauses, or change how the syntax tree is converted to the target output.

### Some use cases

[](#some-use-cases)

- User-level query language on top of your search backend
- Common query language on top of different search backends
- Control over options of the query language that is already provided by the search backend
- Better error handling than provided by the search backend
- Analysis and manipulation of the query before sending to the backend
- Customized query language (while remaining within the base syntax)
- Implementing rich input interface (with suggestions, syntax highlighting, error feedback)

Note: This implementation is intended as a [library](https://en.wikipedia.org/wiki/Library_(computing)), meaning it doesn't try to solve specific use cases for query translation. Instead, it's meant to be a base that you can use in implementing such a use case.

### How to use

[](#how-to-use)

First add the library to your project:

```
composer require netgen/query-translator:^1.0

```

After that, make use of the features provided out of the box. If those are not enough, use extension points to customize various parts of the translator to fit your needs. See [Galach documentation](lib/Languages/Galach) to find out more.

Run the demo
------------

[](#run-the-demo)

Demo is available as a separate repository at [netgen/query-translator-demo](https://github.com/netgen/query-translator-demo).

Steps for running the demo:

1. Create the demo project using composer `composer create-project netgen/query-translator-demo`
2. Position into the demo project directory `cd query-translator-demo`
3. Start the web server with `src` as the document root `php -S localhost:8005 -t src`
4. Open  in your browser [![Query Translator demo](https://raw.githubusercontent.com/netgen/query-translator-demo/master/src/animation.gif)](https://raw.githubusercontent.com/netgen/query-translator-demo/master/src/animation.gif)

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance54

Moderate activity, may be stable

Popularity57

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 94.7% 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.

###  Release Activity

Cadence

Every ~439 days

Total

5

Last Release

1587d ago

Major Versions

0.9.0 → 1.0.02017-06-21

PHP version history (2 changes)1.0.0PHP ~5.6|~7.0

1.1.0PHP ^7.0||^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/362286?v=4)[Edi Modrić](/maintainers/emodric)[@emodric](https://github.com/emodric)

![](https://avatars.githubusercontent.com/u/594589?v=4)[Netgen](/maintainers/netgen)[@netgen](https://github.com/netgen)

![](https://www.gravatar.com/avatar/9b8e80e94a4e04d5eacbab8fafc067fe332fa5e8a7326b5e55d3005d5df1a360?d=identicon)[petar](/maintainers/petar)

---

Top Contributors

[![pspanja](https://avatars.githubusercontent.com/u/1135425?v=4)](https://github.com/pspanja "pspanja (142 commits)")[![thePanz](https://avatars.githubusercontent.com/u/226021?v=4)](https://github.com/thePanz "thePanz (4 commits)")[![emodric](https://avatars.githubusercontent.com/u/362286?v=4)](https://github.com/emodric "emodric (1 commits)")[![liln00b](https://avatars.githubusercontent.com/u/32959502?v=4)](https://github.com/liln00b "liln00b (1 commits)")[![MarioBlazek](https://avatars.githubusercontent.com/u/6605175?v=4)](https://github.com/MarioBlazek "MarioBlazek (1 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (1 commits)")

---

Tags

astedismaxelasticsearchgeneratorparserphpquerysearchsolrtokenizertranslatorsearchparserelasticsearchgeneratorquerysolrtokenizerasttranslatoredismax

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/netgen-query-translator/health.svg)

```
[![Health](https://phpackages.com/badges/netgen-query-translator/health.svg)](https://phpackages.com/packages/netgen-query-translator)
```

###  Alternatives

[apicart/fql

Filter Query Language

1110.6k](/packages/apicart-fql)[cmsig/seal

Search Engine Abstraction Layer

32207.9k53](/packages/cmsig-seal)[cmsig/seal-symfony-bundle

An integration of CMS-IG SEAL search abstraction into Symfony Framework.

15195.8k5](/packages/cmsig-seal-symfony-bundle)[dmk/mksearch

Generic highly adjustable and extendable search engine framework, using Zend Lucene, Apache Solr or ElasticSearch. But support for other search engines can be provided easily.

1330.6k](/packages/dmk-mksearch)

PHPackages © 2026

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