我能够生成构面并将结果绑定在转发器控件中的Linkbutton
中。现在,当用户在Sitecore 7中选择多个相同构面类型的值时,我在使用OR
运算符生成构面查询时遇到问题。
可以做些什么来解决它?
由于
答案 0 :(得分: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();
}
答案 1 :(得分:1)
这是一篇关于使用PredicateBuilder解决此问题的博客文章,其中包含一个特定的代码示例:
答案 2 :(得分:0)
作为一种快速方式,如果您可以使用SitecoreUISearchResultItem
作为查询结果类型,则可以使用Sitecore 7用于解析在内容编辑器搜索中输入的查询的相同方法:
Sitecore.Buckets.Util.UIFilterHelpers.ParseDatasourceString(string query)
如果这不符合您的要求,那么阅读反编译器(ILSpy,DotPeek,Reflector,Resharper等)的实现方式可以帮助您根据动态标准手动编写表达式。