Note that there are some explanatory texts on larger screens.

plurals
  1. POLucene.net multi field searches
    primarykey
    data
    text
    <p>In an attempt to get some more contextually relevant search results I've decided to have a play with lucene.net although I'm very new to it and I've found it not to be the most intuitive library I've come across. This isn't helped by the lack of relevant examples out there to help me figure it out.</p> <p>I'm using <a href="http://simplelucene.codeplex.com/">simple lucene</a> to build my index and that seems to be working perfectly:</p> <pre><code>Field f = null; Document document = new Document(); document.Add(new Field("id", dl.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); f = new Field("category", dl.CategoryName.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); f.SetBoost(5); document.Add(f); f = new Field("company_name", dl.CompanyName.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); f.SetBoost(2); document.Add(f); document.Add(new Field("description", dl.Description.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS)); document.Add(new Field("meta_keywords", dl.Meta_Keywords.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS)); document.Add(new Field("meta_description", dl.Meta_Description.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS)); //And a few more fields </code></pre> <p>Based on this index I first tried a query along these lines:</p> <pre><code>var whatParser = new MultiFieldQueryParser( global::Lucene.Net.Util.Version.LUCENE_29, new string[] { "company_name", "description", "meta_keywords", "meta_description", "category" }, analyzer); whatQuery = whatParser.Parse("search".ToLowerInvariant()); </code></pre> <p>This worked great up until the search term became more than 1 word. Next up was a phrase query.</p> <pre><code>whatQuery = new PhraseQuery(); whatQuery.Add(new Term("company_name", what)); whatQuery.Add(new Term("description", what)); whatQuery.Add(new Term("meta_keywords", what)); whatQuery.Add(new Term("meta_description", what)); whatQuery.Add(new Term("category", what)); </code></pre> <p>Which i then found threw the error: <code>All phrase terms must be in the same field</code></p> <p>So, where am I going wrong? Do you have any suggestions on how to fix it? I'm open to changing the search technology entirely if there are better suggestions out there.</p> <p>Some additional information which may be useful</p> <ul> <li>All results are sorted in the end via <code>new Sort(new SortField[] {new SortField("is_featured", SortField.STRING, true),SortField.FIELD_SCORE})</code></li> <li>There are some additional search criteria so each query is added to a Boolean query with occur set to SHOULD</li> </ul> <p>Thanks for your help.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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