I used this code to perform a search of a Lucene.Net index. Lucene.Net.Store..Directory directory = Lucene.Net.Store.FSDirectory .Open(new DirectoryInfo(textBoxSearchIndex.Text)); Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.Standard .StandardAnalyzer(LuceneUtil.Version.LUCENE_29); Lucene.Net.Search.Searcher searcher = new Lucene.Net.Search .IndexSearcher(LuceneIndex.IndexReader .Open(directory, true)); Lucene.Net.Search.Query query = new Lucene.Net.QueryParsers .QueryParser(LuceneUtil.Version.LUCENE_29, “contents”, analyzer) .Parse(textBoxSearch.Text); Lucene.Net.Search.Hits hits = […]
Read More →Tags: Lucene.Net
Lucene.NET returns results only when using numeric values
I used this code to create a Lucene.Net 2.9.2 index. System.IO.DirectoryInfo indexFileLocation = new System.IO.DirectoryInfo(textBox1.Text); Lucene.Net.Store.Directory directory = Lucene.Net.Store.FSDirectory.Open(indexFileLocation); Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net .Analysis .Standard .StandardAnalyzer(LuceneUtil.Version.LUCENE_29); IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); foreach (IList item in dataToIndex) { Document doc = new Document(); doc.Add(new Field(“ID”, item[0].ToString(), Field.Store.YES, Field.Index.NO)); …. string contents = […]
Read More →Lucene.Net search with star (*) wildcard as first character
Using the star (*) as the first character of a Lucene.Net search is not supported by default. It will return null results if it is not turned on. To turn on the support for leading wild card characters you must set the SetAllowLeadingWildcard property to true. Then you will be able to use wildcard search […]
Read More →Getting started with Lucene.Net 2.9.2 using C#
I recently started a project working with Lucene.Net. I am amazed at how simple it was to create and search indexes. I downloaded the source by pointing my TortoiseSVN (subversion) here (https://svn.apache.org/repos/asf/lucene/lucene.net/tags/Lucene.Net_2_9_2/) and performing an Import. Once I downloaded it I opened the Lucene.Net.sln solution file in Visual Studio 2010 and compiled it targeting .Net […]
Read More →How to create and search a Lucene.Net index in 4 simple steps using C#, Step 3
Perform the search. In this step we will use the query which was created using the query parser to perform the search on the index we created in step 1. The Searcher class needs to be told where the index we want to search is. We will create a directory class to hold this information […]
Read More →How to create and search a Lucene.Net index in 4 simple steps using C#, Step 2
Build the Query. There are numerous ways you can build your query. I counted 17 different Query classes in the Lucene.Net source code. Here is a list of some of the query classes and when to use them. Query Class Description TermQuery Searches for a specific term RangeQuery Searches within a specific range, ex: date […]
Read More →How to create and search a Lucene.Net index in 4 simple steps using C#, Step 1
As mentioned in a previous blog, using Lucene.Net to create and search an index was quick and easy. Here I will show you in these 4 steps how to do it. Create an index Build the query Perform the search Display the results Before we get started I wanted to mention that Lucene.Net was originally […]
Read More →How to create and search a Lucene.Net index in 4 simple steps using C#, Step 4
Display the results. To view the results we need to loop through the ScoreDoc array we created in Part3. We do this by iterating through it within a for loop. for (int i = 0; i < hits.Length; i++) { int docId = hits[i].doc; float score = hits[i].score; Lucene.Net.Documents.Document doc = searcher.Doc(docId); string result = […]
Read More →