I am building Examine search in Umbraco and am searching by either keyword or country code or city but I am getting wrong results for some of them.
For example I search for countryCode = IN and startCity = New Delhi
I pass a list of required properties (MUST properties):
List<string> matchProperties = new List<string> { countryCode = "IN", startCity = "New Delhi" };
But the Examine builds the query as:
SearchIndexType: "content", LuceneQuery: {+(__NodeTypeAlias:product +startCity:"new delhi" -umbracoNaviHide:1) +__IndexType:content}
evidently ignoring countryCode IN value
Same if I search only by country:
List<string> matchProperties = new List<string> { countryCode = "IN" };
I receive the following query:
SearchIndexType: "content", LuceneQuery: {+(__NodeTypeAlias:product -umbracoNaviHide:1) +__IndexType:content}
Here I am getting wrong results, because the search returns all product nodes instead of the ones containing IN countryCode.
If I look up by a keyword (it uses Or properties so should return products when either of fields contain the keyword) it's included in the query:
SearchIndexType: "content", LuceneQuery: {+(__NodeTypeAlias:product heading:danakil tags:danakil description:danakil -umbracoNaviHide:1) +__IndexType:content}
but it again returns all nodes which is wrong because FOR SURE only a few nodes (up to 20) contain this specific word (case sensitive or not).
But if I search by a fake/ non-word keyword eg. asdadasda:
List<string> matchOrProperties = new List<string> { keyword = "asdadasda" };
it also gets ignored in the query (same like IN above):
SearchIndexType: "content", LuceneQuery: {+(__NodeTypeAlias:product -umbracoNaviHide:1) +__IndexType:content}
and returns all nodes instead of 0 nodes.
This is how I am building my query:
protected async Task<List<SearchResult>> SearchCriteriaResultAsync(Examine.Providers.BaseSearchProvider searcher, ISearchCriteria searchCriteria, string contentAliasToMatch, bool excludeHidden, Dictionary<string, string> matchProperties, Dictionary<string, string> matchOrProperties)
{
IBooleanOperation query = searchCriteria.NodeTypeAlias(contentAliasToMatch);
if (matchProperties != null && matchProperties.Any())
{
foreach (var item in matchProperties)
{
query = query.And().Field(item.Key, item.Value);
}
}
if (matchOrProperties != null && matchOrProperties.Any())
{
int counter = 0;
foreach (var item in matchOrProperties)
{
query = query.Or().Field(item.Key, item.Value);
counter++;
}
}
if(excludeHidden)
{
query = query.Not().Field("umbracoNaviHide", "1");
}
return await System.Threading.Tasks.Task.Run(() => {
return searcher.Search(query.Compile()).ToList();
});
}
And my indexer and searcher:
<add name="PublishedProductsIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
supportUnpublished="false"
supportProtected="true"
interval="10"
analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
<add name="PublishedProductsSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
<IndexSet SetName="PublishedProductsIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/PublishedProducts/" IndexParentId="1049">
<IndexAttributeFields>
<add Name="id" />
<add Name="nodeName" />
<add Name="updateDate" />
<add Name="writerName" />
<add Name="path" />
<add Name="email" />
<add Name="nodeTypeAlias" />
<add Name="parentID" />
</IndexAttributeFields>
<IncludeNodeTypes>
<add Name="product"/>
</IncludeNodeTypes>
</IndexSet>
Is Examine ignoring certain keywords or my query is wrong? If wrong how should I fix it?
I ma using umbraco 7.6 if this matters.