Created
September 25, 2014 02:55
-
-
Save sholfen/3b3938ecbf958978f3b7 to your computer and use it in GitHub Desktop.
Lucene.Net demo: IndexItems function
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
static void IndexItems(List<Product> list) | |
{ | |
Lucene.Net.Store.Directory directory = FSDirectory.Open(new DirectoryInfo(@"D:\Index")); | |
IndexWriter indexWriter = new IndexWriter( | |
directory, | |
new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), | |
true, | |
IndexWriter.MaxFieldLength.LIMITED); | |
foreach (Product product in list) | |
{ | |
Document doc = new Document(); | |
Field productName = new Field("ProductName", product.ProductName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO); | |
doc.Add(productName); | |
NumericField price = new NumericField("Price", Field.Store.YES, true); | |
price.SetIntValue(product.Price); | |
doc.Add(price); | |
indexWriter.AddDocument(doc); | |
} | |
indexWriter.Optimize(); | |
indexWriter.Commit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment