Coder Social home page Coder Social logo

mahnunchik / lucene-query-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thoward/lucene-query-parser.js

24.0 2.0 12.0 44 KB

Lucene Query Parser for Javascript created using PEG.js.

Home Page: https://bitbucket.org/thoward/lucene-query-parser.js

JavaScript 100.00%

lucene-query-parser's Introduction

Lucene Query Parser for Javascript

This is an implementation of the Lucene Query Parser developed using PEG.js.

Example

A quick example of how to use it:

// return the expression tree 
var results = lucenequeryparser.parse('title:"The Right Way" AND text:go');

alert(results['left']['field']);      // title
alert(results['left']['term']);       // The Right Way
alert(results['operator']);           // AND
alert(results['right']['field']);     // text
alert(results['right']['term']);      // go

A slightly more complicated example:

// return the expression tree 
var results = lucenequeryparser.parse('test AND (foo OR bar)');

alert(results['left']['term']);       // test
alert(results['operator']);           // AND

// the parantheses group becomes it's own nested node
var rightNode = results['right'];  

alert(rightNode['left']['term']);     // foo
alert(rightNode['operator']);         // OR
alert(rightNode['right']['term']);    // bar

Unit Tests

To run the unit tests, just open SpecRunner.html in any browser. Unit tests are built with Jasmine.

Grammar

The parser is auto-generated from a PEG implementation in Javascript called PEG.js.

To test the grammar without using the generated parser, or if you want to modify it, try out PEG.js online. This is a handy way to test an abritrary query and see what the results will be like or debug a problem with the parser for a given piece of data.

Community

If you'd like to help out with the project, or if you have a question, feel free to contact Troy Howard at [email protected].

Bug reports or feature requests should go in the bitbucket issue tracker. Please include relevant sample data (the query) and a good description of the challenges you're facing.

Look to the wiki for documentation and other resources.

lucene-query-parser's People

Contributors

mahnunchik avatar matthiasg avatar thoward 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

Watchers

 avatar  avatar

lucene-query-parser's Issues

white space after field:

I am trying to find out whether the lucene query string syntax allows whitespace between field name and term. lucene-query-parser does not allow whitespace right now. The docs don't explicitly forbid it just mention the field is followed by the term.

Example:

field: value 

Raises: expected "+", "-" or whitespace but "v" found. And requires:

field:value

Elasticsearches query_string parser does allow it and thus I would like to understand what the behavior should be or whether this parser should be updated.

Use this to search "documents" in memory?

I would love to be able to use this to parse a user given lucene query and apply it to an array of JSON objects in memory, and get back the items in the array that match the query ...

support dot notation (e.g. group.field:2)

The parser currently does not support subfields. ElasticSearch supports that for queries e.g. (which works using the LuceneQueryParser).

Is that something you would want to add ?

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.