0

First time using Lucene so I apologise in advance if some terminology is incorrect.

I am modifying a Lucene query and am not getting the results expected. A search term is used to build a boolean query, and I need to add an extra field to search. This field, called tags is already part of the index (confirmed with Luke for Lucene) but hasn't been included in the search.

Currently the boolean query looks like this:

if (!String.IsNullOrEmpty(settings.SearchTerm))
  {
    booleanQuery.Add(KeywordQuery(settings.SearchTerm, analyzer), Occur.Must);
  }


 private Query KeywordQuery(string searchTerm, StandardAnalyzer analyzer)
   {
     var parser = new MultiFieldQueryParser(Version.LUCENE_29, new[] 
       { 
         LuceneMedia.IndexFields._Title, 
         LuceneMedia.IndexFields.Description
       }, analyzer);
     string sTerm = LuceneUtilities.AddSearchWildCard(searchTerm);
     Query query = LuceneUtilities.ParseQuery(sTerm, parser);

     return query;
   }

(indexFields are constants that refer to the field names)

I thought it would be a case of extending the array of tags like so:

 new[] 
            { 
                LuceneMedia.IndexFields._Title, 
                LuceneMedia.IndexFields.Description, 
                LuceneMedia.IndexFields.Tags 
            }, 

but this bought back no results when searching for a tag I know exists, but results for a title I know exists. so I thought maybe I should change OCCURS.MUST to OCCURS.SHOULD but a tag search brought back all results.

What have I done wrong?

4

1 回答 1

0

这是搜索多个字段的正确方法,不幸的是我没有重新索引!

于 2013-09-13T15:37:21.093 回答