This is example code for my tutorial Build a query parser.
Each query parser is self-contained to make the tutorial easier to follow. This does mean there's a lot of duplication. In order to keep the classes separate, each query parser is contained in its own module.
The sequence of query parsers is:
You will need Ruby (tested with 2.4) to run the query parsers and Java (tested with 1.8) to run Elasticsearch if you want to try out the parsers for real. I use RVM and jEnv to manage the versions, but you do not have to.
bundle install
bundle exec rake test
The integration tests require Elasticsearch to be started.
elasticsearch/bin/elasticsearch
In another terminal:
bundle exec rake integration_test
The parse
program allows you to test out the different parser and see the parse tree and Elasticsearch DSL that is generated based on a query string you provide.
To run it:
bundle exec bin/parse
The program defaults to the HeuristicParser
because it is the most featureful. To try one of the others, provide it as a command-line argument:
bundle exec bin/parse BooleanTermParser
The source code in this repository is released into the public domain.
The tutorial is under copyright and cannot be republished without my permission.