Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是检查搜索忽略了某些关键字还是我的查询错误?_C#_Search_Umbraco_Lucene.net_Examine - Fatal编程技术网

C# 是检查搜索忽略了某些关键字还是我的查询错误?

C# 是检查搜索忽略了某些关键字还是我的查询错误?,c#,search,umbraco,lucene.net,examine,C#,Search,Umbraco,Lucene.net,Examine,我正在Umbraco中建立搜索,并通过关键字、国家代码或城市进行搜索,但我得到了一些错误的结果 例如,我搜索countryCode=IN和startCity=New Delhi 我传递了所需属性(必须属性)的列表: 显然忽略了值中的countryCode 如果仅按国家/地区搜索,则相同: List<string> matchProperties = new List<string> { countryCode = "IN" }; 这里我得到了错误的结果,因为搜索返回的

我正在Umbraco中建立搜索,并通过关键字、国家代码或城市进行搜索,但我得到了一些错误的结果

例如,我搜索
countryCode=IN
startCity=New Delhi

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

显然忽略了值中的
countryCode

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

List<string> matchProperties =  new List<string> { countryCode = "IN" };
这里我得到了错误的结果,因为搜索返回的是所有
product
节点,而不是
countryCode
中包含的节点

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

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" };
并返回所有节点,而不是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();
        });
    }
protected async async async Task SearchCriteriaResultAsync(Examine.Providers.BaseSearchProvider searcher、isearchcriteriasearchcriteria、string contentAliasToMatch、bool excludeHidden、Dictionary matchProperties、Dictionary matchOrProperties)
{
IBooleanOperation query=searchCriteria.NodeTypeAlias(contentAliasToMatch);
if(matchProperties!=null&&matchProperties.Any())
{
foreach(matchProperties中的变量项)
{
query=query.And()字段(item.Key、item.Value);
}
}
if(matchOrProperties!=null&&matchOrProperties.Any())
{
int计数器=0;
foreach(matchOrProperties中的var项)
{
query=query.Or()字段(item.Key、item.Value);
计数器++;
}
}
如果(不包括隐藏)
{
query=query.Not().字段(“umbracanavihide”、“1”);
}
return wait System.Threading.Tasks.Task.Run(()=>{
返回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。

您没有达到最小字符长度?当您的国家代码超过4个字符时会发生什么情况?@Peska它永远不会超过4个字符。它是ISO国家代码,总是2个字符。其他国家搜索得很好,只是“IN”不好。这就是为什么我认为它可能被排除在外的原因,因为它是英语中的一个常见介词。如果你使用的是StandardAnalyzer,它使用的是一个英语单词停止列表…'IN'在该列表中:-)您没有达到某个最小字符长度?当您的国家代码超过4个字符时会发生什么情况?@Peska它永远不会超过4个字符。它是ISO国家代码,总是2个字符。其他国家搜索得很好,只是“IN”不好。这就是为什么我认为它可能被排除在外的原因,因为它是英语中的一个常见介词。如果你使用的是StandardAnalyzer,它使用的是一个英语单词停止列表…'IN'在该列表中:-)
List<string> matchOrProperties =  new List<string> { keyword = "asdadasda" };
SearchIndexType: "content", LuceneQuery: {+(__NodeTypeAlias:product -umbracoNaviHide:1) +__IndexType:content}
    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>