首页 > 解决方案 > 检查搜索是否忽略了某些关键字或我的查询是错误的?

问题描述

我正在 Umbraco 中构建检查搜索,并且正在按关键字、国家代码或城市进行搜索,但其中一些结果我得到了错误的结果。

例如我搜索countryCode = INstartCity = New Delhi

我传递了所需属性的列表(必须属性):

List<string> matchProperties =  new List<string> { countryCode = "IN", startCity = "New Delhi" };

但是检查将查询构建为:

SearchIndexType: "content", LuceneQuery: {+(__NodeTypeAlias:product +startCity:"new delhi" -umbracoNaviHide:1) +__IndexType:content}

显然忽略了countryCode IN价值

如果我仅按国家/地区搜索,则相同:

List<string> matchProperties =  new List<string> { countryCode = "IN" };

我收到以下查询:

SearchIndexType: "content", LuceneQuery: {+(__NodeTypeAlias:product -umbracoNaviHide:1) +__IndexType:content}

在这里我得到了错误的结果,因为搜索返回所有product节点而不是包含 IN 的节点countryCode

如果我通过关键字查找(它使用Or属性,因此当任一字段包含关键字时应该返回产品)它包含在查询中:

SearchIndexType: "content", LuceneQuery: {+(__NodeTypeAlias:product heading:danakil tags:danakil description:danakil -umbracoNaviHide:1) +__IndexType:content}

但它再次返回所有错误的节点,因为肯定只有少数节点(最多 20 个)包含此特定单词(区分大小写或不区分大小写)。

但是,如果我使用虚假/非单词关键字进行搜索,例如。asdadasda

List<string> matchOrProperties =  new List<string> { keyword = "asdadasda" };

它也在查询中被忽略(与IN上面相同):

SearchIndexType: "content", LuceneQuery: {+(__NodeTypeAlias:product -umbracoNaviHide:1) +__IndexType:content}

并返回所有节点而不是 0 个节点。

这就是我构建查询的方式:

    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();
        });
    }

还有我的索引器和搜索器:

    <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>

检查是否忽略了某些关键字或我的查询是错误的?如果错了我应该如何解决?

如果这很重要,我会使用 umbraco 7.6。

标签: c#searchumbracolucene.netexamine

解决方案


推荐阅读