Skip to content

Instantly share code, notes, and snippets.

@sholfen
Created September 25, 2014 02:55
Show Gist options
  • Save sholfen/3b3938ecbf958978f3b7 to your computer and use it in GitHub Desktop.
Save sholfen/3b3938ecbf958978f3b7 to your computer and use it in GitHub Desktop.
Lucene.Net demo: IndexItems function
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