Build a query parser example code
This is example code for my tutorial Build a query parser.
How the code is organized
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:
Installing and running
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.
Run unit tests
bundle exec rake test
Run integration tests
The integration tests require Elasticsearch to be started.
In another terminal:
bundle exec rake integration_test
Query generation console
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.