|
| 1 | +======================================== |
| 2 | +Lucene Query Parser for Javascript |
| 3 | +======================================== |
| 4 | + |
| 5 | +This is an implementation of the Lucene Query Parser developed using PEG.js. |
| 6 | + |
| 7 | +Example |
| 8 | +======================================== |
| 9 | + |
| 10 | +A quick example of how to use it:: |
| 11 | + |
| 12 | + // return the expression tree |
| 13 | + var results = lucenequeryparser.parse('title:"The Right Way" AND text:go'); |
| 14 | + |
| 15 | + alert(results['left']['field']); // title |
| 16 | + alert(results['left']['term']); // The Right Way |
| 17 | + alert(results['operator']); // AND |
| 18 | + alert(results['right']['field']); // text |
| 19 | + alert(results['right']['term']); // go |
| 20 | + |
| 21 | + |
| 22 | +A slightly more complicated example:: |
| 23 | + |
| 24 | + // return the expression tree |
| 25 | + var results = lucenequeryparser.parse('test AND (foo OR bar)'); |
| 26 | + |
| 27 | + alert(results['left']['term']); // test |
| 28 | + alert(results['operator']); // AND |
| 29 | + |
| 30 | + // the parantheses group becomes it's own nested node |
| 31 | + var rightNode = results['right']; |
| 32 | + |
| 33 | + alert(rightNode['left']['term']); // foo |
| 34 | + alert(rightNode['operator']); // OR |
| 35 | + alert(rightNode['right']['term']); // bar |
| 36 | + |
| 37 | + |
| 38 | +Unit Tests |
| 39 | +======================================== |
| 40 | + |
| 41 | +To run the unit tests, just open SpecRunner.html in any browser. Unit tests are built with |
| 42 | +`Jasmine <http://pivotal.github.com/jasmine/>`_. |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +Grammar |
| 47 | +======================================== |
| 48 | + |
| 49 | +The parser is auto-generated from a PEG implementation in Javascript called |
| 50 | +`PEG.js <http://pegjs.majda.cz/>`_. |
| 51 | + |
| 52 | + |
| 53 | +To test the grammar without using the generated parser, or if you want to modify it, try out `PEG.js |
| 54 | +online <http://pegjs.majda.cz/online>`_. This is a handy way to test an abritrary query and see |
| 55 | +what the results will be like or debug a problem with the parser for a given piece of data. |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +Community |
| 60 | +======================================== |
| 61 | + |
| 62 | +If you'd like to help out with the project, or if you have a question, feel free to contact |
| 63 | + |
| 64 | + |
| 65 | +Bug reports or feature requests should go in the bitbucket issue tracker. Please include relevant |
| 66 | +sample data (the query) and a good description of the challenges you're facing. |
| 67 | + |
| 68 | +Look to the wiki for documentation and other resources. |
0 commit comments