Dev Time: Reading term values for fields from a Lucene Index
Reading term values for fields from a Lucene Index Sometimes when using Lucene you might want to retrieve all term values for a given field. Think of categories that you want to display as search links or in a filtering dropdown box. Indexing might look something like this: IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, new StandardAnalyzer(Version.LUCENE_36)); IndexWriter writer = new IndexWriter(directory, config); Document doc = new Document(); doc.add(new Field("Category", "Category1", Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.add(new Field("Category", "Category2", Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.add(new Field("Author", "Florian Hopf", Field.Store.NO, Field.Index.NOT_ANALYZED)); writer.addDocument(doc); doc.add(new Field("Category", "Category3", Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.add(new Field("Category", "Category2", Field.Store.NO, Field.Index.NOT_ANALYZED)); doc.add(new Field("Author", "Theo Tester", Field.Store.NO, Field.Read full article from Dev Time: Reading term values for fields from a Lucene Index
No comments:
Post a Comment