0

我正在尝试在 umbraco 检查中设置搜索。我有两个搜索字段,材料和制造商。当我尝试使用一种材料和一种制造商进行搜索时,它会给出正确的结果。但是当尝试搜索多种材料或制造商时它没有给出结果。这是我的代码

 const string materialSearchFields = "material";
    const string manufacturerSearchFields = "manufacturer";

if (!string.IsNullOrEmpty(Request.QueryString["material"])) { material = Helper.StripTags(Request.QueryString["material"]); } if (!string.IsNullOrEmpty(Request.QueryString["manufacturer"])) { 制造商 = Helper.StripTags(Request.QueryString["manufacturer"]); } if (!string.IsNullOrEmpty(Request.QueryString["material"]) || !string.IsNullOrEmpty(Request.QueryString["manufacturer"])) { var query = userFieldSearchCriteria.Field(materialSearchFields, material).And() .Field(manufacturerSearchFields, 制造商).Compile(); contentResults = contentSearcher.Search(query).ToList(); }

这里我在查询字符串中的搜索关键字是 material=iron,steel

我们如何拆分这个关键字并完成搜索?在此先感谢您的帮助....

4

1 回答 1

0

您正在使用 AND 运算符,在您的情况下,我认为您正在寻找 GROUPEDOR 吗?

我只是在一个旧项目中工作并从那里抓住了这个片段(我已经根据您的需要进行了调整)。我认为它会帮助你:

public IEnumerable<DynamicNode> SearchUmbraco(string[] keywords, string currentCulture)
        {
            // In this case I had some  diferent cultures, so this sets the BaseSearchProvider to the given culture parameter. You might not need this, use your default one.
            BaseSearchProvider searcher = SetBaseSearchProvider(currentCulture);

            var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
            var groupedQuery = searchCriteria.GroupedOr(new[] {"manufacturer", "material"}, keywords).Compile();

            var searchResults = searcher.Search(groupedQuery);

            // ... return IEnumerable of dynamic nodes (in this snipet case)

        }

当我调用此方法时,我只是拆分(等)助手中的关键字并将它们传递给字符串数组。

只需在 umbraco 博客上查看此信息:http: //umbraco.com/follow-us/blog-archive/2011/9/16/examineing-examine.aspx

于 2013-12-09T10:21:17.727 回答