Created
December 6, 2010 19:48
-
-
Save robbywalker/730811 to your computer and use it in GitHub Desktop.
Example usage of the Lucene Interval Fields project.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add some documents. | |
Document doc = new Document(); | |
doc.add(new Field("name", "George Washington", Field.Store.YES, Field.Index.NO)); | |
doc.add(new NumericIntervalField("term", true, 1789, 1793)); | |
doc.add(new NumericIntervalField("term", true, 1793, 1797)); | |
indexWriter.addDocument(doc); | |
doc = new Document(); | |
doc.add(new Field("name", "John Adams", Field.Store.YES, Field.Index.NO)); | |
doc.add(new NumericIntervalField("term", true, 1797, 1801)); | |
indexWriter.addDocument(doc); | |
doc = new Document(); | |
doc.add(new Field("name", "Thomas Jefferson", Field.Store.YES, Field.Index.NO)); | |
doc.add(new NumericIntervalField("term", true, 1801, 1805)); | |
doc.add(new NumericIntervalField("term", true, 1805, 1809)); | |
indexWriter.addDocument(doc); | |
// ... | |
// List all presidents in office in the 1700s. | |
searcher.search(new NumericIntervalIntersectionQuery("term", 1700, 1799), collector) | |
// Who was president in 1804? | |
searcher.search(new InNumericIntervalQuery("term", 1804), collector) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment