Giter Club home page Giter Club logo

query-parser's Introduction

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:

  1. TermParser
  2. BooleanTermParser
  3. PhraseParser
  4. HeuristicParser

Installing and running

Prerequisites

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.

Install dependencies

bundle install

Run unit tests

bundle exec rake test

Run integration tests

The integration tests require Elasticsearch to be started.

elasticsearch/bin/elasticsearch

In another terminal:

bundle exec rake integration_test

Query generation console

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

License

The source code in this repository is released into the public domain.

The tutorial is under copyright and cannot be republished without my permission.

query-parser's People

Contributors

look avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

query-parser's Issues

chunk + to_h not working as expected

hey @look, enjoyed your article and used some of your code in own project. Thank you so much! Just wanted to let you know about a possible small mistake here:

grouped = clauses.chunk { |c| c.operator }.to_h
chunk.to_h is only keeping the last element for each group in the array for each operator. To fix I used grouped = clauses.group_by(&:operator) instead. Ruby version is 2.1.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.