3

我能够生成构面并将结果绑定Linkbutton在转发器控件中。OR现在,当用户在 Sitecore 7 中选择超过 1 个相同构面类型的值时,我在使用运算符生成构面查询时遇到了问题。

可以做些什么来解决它?

谢谢

4

3 回答 3

1

要在 Sitecore 中实现 Facet 搜索,请使用 PredicateBuilder 类构建过滤查询,然后将过滤查询添加到基本查询。代码如下:

        List<PeopleFields> objPeoplefields = new List<PeopleFields>();
        IQueryable<PeopleFields> Query = null;
        var predicatePractice = Sitecore.ContentSearch.Utilities.PredicateBuilder.False<PeopleFields>();
        var predicateOffice = Sitecore.ContentSearch.Utilities.PredicateBuilder.False<PeopleFields>();

        using (var context = ContentSearchManager.GetIndex(SITECORE_WEB_INDEX).CreateSearchContext())
        {
            //Base query
            Query = context.GetQueryable<PeopleFields>().Where(i => i.FirstName.StartsWith(txtFirstName.Text)).Where(i => i.LastName.StartsWith(txtLastName.Text));
            foreach (string strselecteFacet in lstPracticefacetSelected)
            {
                //filter query
                predicatePractice = predicatePractice.Or(x => x.Practice.Like(strselecteFacet));
            }

            foreach (string strselecteFacet in lstOfficefacetSelected)
            {
                //Filter query
                predicateOffice = predicateOffice.Or(x => x.Office.Like(strselecteFacet));
            }

            //Joining the filter query alongwith base query
            if (lstPracticefacetSelected.Count > 0 && lstOfficefacetSelected.Count > 0)
                Query = Query.Filter(predicatePractice).Filter(predicateOffice);
            else if (lstPracticefacetSelected.Count > 0 && lstOfficefacetSelected.Count == 0)
                Query = Query.Filter(predicatePractice);
            else if (lstPracticefacetSelected.Count == 0 && lstOfficefacetSelected.Count > 0)
                Query = Query.Filter(predicateOffice);

            objPeoplefields = Query.ToList();
        }
于 2013-06-18T07:43:31.903 回答
1

这是一篇关于使用 PredicateBuilder 和特定代码示例解决此问题的博客文章:

http://www.nttdatasitecore.com/en/Blog/2013/November/Building-Facet-Queries-with-PredicateBuilder.aspx

于 2013-11-06T20:59:51.283 回答
0

作为一种快速方法,如果您可以使用SitecoreUISearchResultItem作为查询结果类型,您可以使用 Sitecore 7 用来解析在内容编辑器搜索中输入的查询的相同方法:

Sitecore.Buckets.Util.UIFilterHelpers.ParseDatasourceString(string query)

如果这不符合您的要求,阅读如何使用反编译器(ILSpy、DotPeek、Reflector、Resharper 等)实现它可能会帮助您根据动态标准手动编写表达式。

于 2013-06-13T05:21:17.527 回答