I'm having some fun with Solr and here is my current issue.
I've applied some stop words using the stopwords.txt
file and rebuilt my indexes. Everything looks fine here, I can see that those stop words are no longer indexed:
All that being said Query Time is my issue.
Firstly, here is my text_general
field type config on managed-schema
:
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100" multiValued="false">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
<filter class="solr.SynonymFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
Since the StopFilterFactory
is there on both Index and Query time I'm wondering why queries with stop words are keeping those words during execution.
Let's say I'm quering Designed for you
.
Since for
is a stopword my query should really be Designed you
.
Here is the code handling the query:
var keywordsFilter = PredicateBuilder.True<UnifiedSearchResultItemWithLocalDatasource>();
foreach (var keyword in keywords)
{
var keywordFilter = PredicateBuilder.False<UnifiedSearchResultItemWithLocalDatasource>();
keywordFilter = keywordFilter.Or(item => item.UnifiedTitle.Like(keyword, 0.8f).Boost(8f))
.Or(item => item.UnifiedTitle.StartsWith(keyword).Boost(8f))
.Or(item => item.UnifiedSiteSection.Like(keyword, 0.8f).Boost(4f))
.Or(item => item.UnifiedSiteSection.StartsWith(keyword).Boost(4f))
.Or(item => item.UnifiedDescription.Like(keyword, 0.8f).Boost(2f))
.Or(item => item.UnifiedDescription.StartsWith(keyword).Boost(2f));
keywordsFilter = keywordsFilter.And(keywordFilter);
}
And here is the Search log with the generated Solr query:
16776 17:32:29 INFO Solr Query - ?q=((-unifiedtitle_t:("") unifiedtitle_t:[* TO ]) AND ((((unifiedtitle_t:(designed~0.8))^8 OR (unifiedtitle_t:(designed))^8 OR (unifiedsitesection_t:(designed~0.8))^4 OR (unifiedsitesection_t:(designed*))^4 OR (unifieddescription_t:(designed~0.8))^2 OR (unifieddescription_t:(designed*))^2) AND ((unifiedtitle_t:(for~0.8))^8 OR (unifiedtitle_t:(for*))^8 OR (unifiedsitesection_t:(for~0.8))^4 OR (unifiedsitesection_t:(for*))^4 OR (unifieddescription_t:(for~0.8))^2 OR (unifieddescription_t:(for*))^2)) AND ((unifiedtitle_t:(you~0.8))^8 OR (unifiedtitle_t:(you*))^8 OR (unifiedsitesection_t:(you~0.8))^4 OR (unifiedsitesection_t:(you*))^4 OR (unifieddescription_t:(you~0.8))^2 OR (unifieddescription_t:(you*))^2)))&start=0&rows=10&fl=*,score&fq=((_latestversion:(True) AND has_presentation_b:(True)) AND _language:(en))&fq=_indexname:(index_master_index)&facet=true&facet.field=computedarticlecategoryname_s&f.computedarticlecategoryname_s.facet.mincount=0&facet.field=computedresidencetypename_s&f.computedresidencetypename_s.facet.mincount=0&wt=xml
As you guys can see the stopped keyword is still there.
And since the indexing is doing its work properly, I don't have any for
term indexed. The result is that the above query is always returning 0 results
.
What am I doing wrong guys? Thanks in advance.