Note that there are some explanatory texts on larger screens.

plurals
  1. POLucene.Net what am I doing wrong?
    primarykey
    data
    text
    <p>I'm very new to lucene.net. I wrote this simple console app in C# which indexes some fake data. I then wanted to be able to search the index for various terms using a booleanquery.</p> <p>I never get any results back. Here is the code. Any help would be greatly appreciated. Thanks.</p> <pre><code> static void Main(string[] args) { StandardAnalyzer analyzer = new StandardAnalyzer(); IndexWriter writer = new IndexWriter("Test", analyzer, true); Console.WriteLine("Creating index"); for (int i = 0; i &lt; 1500; i++) { Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document(); doc.Add(new Lucene.Net.Documents.Field("A", i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO)); doc.Add(new Lucene.Net.Documents.Field("B", "LALA" + i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO)); doc.Add(new Lucene.Net.Documents.Field("C", "DODO" + i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO)); doc.Add(new Lucene.Net.Documents.Field("D", i.ToString() + " MMMMM", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO)); writer.AddDocument(doc); } writer.Optimize(); writer.Close(); BooleanQuery query = new BooleanQuery(); query.Add(new WildcardQuery(new Term("B", "lala*")), Lucene.Net.Search.BooleanClause.Occur.MUST); query.Add(new WildcardQuery(new Term("C", "DoDo1*")), Lucene.Net.Search.BooleanClause.Occur.MUST); IndexSearcher searcher = new IndexSearcher("Test"); Hits hits = searcher.Search(query); if (hits.Length() &gt; 0) { for (int i = 0; i &lt; hits.Length(); i++) { Console.WriteLine("{0} - {1} - {2} - {3}", hits.Doc(i).GetField("A").StringValue(), hits.Doc(i).GetField("B").StringValue(), hits.Doc(i).GetField("C").StringValue(), hits.Doc(i).GetField("D").StringValue()); } } searcher.Close(); Console.WriteLine("Done"); Console.ReadLine(); } </code></pre> <p>I then got it to work by using MultiFieldQueryParser Like so:</p> <pre><code> static void Main(string[] args) { StandardAnalyzer analyzer = new StandardAnalyzer(); IndexWriter writer = new IndexWriter("Test", analyzer, true); Console.WriteLine("Creating index"); for (int i = 0; i &lt; 1500; i++) { Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document(); doc.Add(new Lucene.Net.Documents.Field("A", i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED)); doc.Add(new Lucene.Net.Documents.Field("B", "LALA" + i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED)); doc.Add(new Lucene.Net.Documents.Field("C", "DODO" + i.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED)); doc.Add(new Lucene.Net.Documents.Field("D", i.ToString() + " MMMMM", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED)); writer.AddDocument(doc); } writer.Optimize(); writer.Close(); BooleanQuery.SetMaxClauseCount(5000); Query query = MultiFieldQueryParser.Parse(new string[] { "LALA*", "DODO*" }, new string[] { "B", "C" }, analyzer); IndexSearcher searcher = new IndexSearcher("Test"); Hits hits = searcher.Search(query); if (hits.Length() &gt; 0) { for (int i = 0; i &lt; hits.Length(); i++) { Console.WriteLine("{0} - {1} - {2} - {3}", hits.Doc(i).GetField("A").StringValue(), hits.Doc(i).GetField("B").StringValue(), hits.Doc(i).GetField("C").StringValue(), hits.Doc(i).GetField("D").StringValue()); } } searcher.Close(); Console.WriteLine("Done"); Console.ReadLine(); } </code></pre> <p>This is possibly the best article I've found for any new lucene developers: <a href="http://www.ifdefined.com/blog/post/2009/02/Full-Text-Search-in-ASPNET-using-LuceneNET.aspx" rel="nofollow noreferrer">http://www.ifdefined.com/blog/post/2009/02/Full-Text-Search-in-ASPNET-using-LuceneNET.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload