【问题标题】:Multiple Searchterm in umbraco Examine Searchumbraco 检查搜索中的多个搜索词
【发布时间】:2013-12-09 06:26:15
【问题描述】:

我正在尝试在 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,manufacturer).Compile(); contentResults = contentSearcher.Search(query).ToList(); }

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

我们如何分割这个关键字并完成搜索? 提前感谢您的帮助....

【问题讨论】:

    标签: umbraco examine


    【解决方案1】:

    您正在使用 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/examining-examine.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-01
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多