Sitecore 8.1 | Do not search custom Lucene stopwords

Viewed 206

I'm implementing a full text search solution for my website using Lucene. The goal is to search in the content of all sitecore items that have any of the words searched.

I was able to do this using search with predicate:

var predicate = PredicateBuilder.True<SearchResultItem>();
var searchTerms = search.Split(' ');

predicate = predicate.Or(item => item.Content.Contains(search)).Boost(3);

foreach (var word in searchTerms)
{
 predicate = predicate.Or(item => item.Content.Contains(word)).Boost(1);
}

var allItems = Context.GetQueryable<SearchResultItem>().Where(predicate);

However, when I search with some specific words I have a error "The Lucene query that was generated contains too many clauses".

To solve this error I created a stopwords file stopwords.txt with these words, put it on [FULL_PATH_TO_SITECORE_ROOT_FOLDER]\Data\indexes\ and change the Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config file to:

<param desc="defaultAnalyzer" type="Sitecore.ContentSearch.LuceneProvider.Analyzers.DefaultPerFieldAnalyzer, Sitecore.ContentSearch.LuceneProvider">
  <param desc="defaultAnalyzer" type="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net">
    <param hint="version">Lucene_30</param>
      <param desc="stopWords" type="System.IO.FileInfo, mscorlib">
      <param hint="fileName">[FULL_PATH_TO_SITECORE_ROOT_FOLDER]\Data\indexes\stopwords.txt</param>
      </param>
  </param>
</param>

I stopped having "The Lucene query that was generated contains too many clauses" error, but from my understanding, when I set a stopword in stopword.txt file, lucene should not search for that word in the content of items.

This means that when I searching for "holiday in London", should return the same results as "holiday London".

However, this does not happen. When I search for "holiday in London" are returned much more results, included items where there are no "London" neither "holiday" word, but exist the word "in".

Can someone help me figure out what escaped me here?

Thanks in advance.

0 Answers
Related