如何使用Linq获取sitecore字段 [英] how to use Linq to get a sitecore field
问题描述
我有一个搜索,我想排除搜索中具有标题"字段名称的任何搜索结果.例如,假设我在搜索栏中输入联系人".我不希望出现联系我们"页面,但是如果有人想搜索联系我们"页面中包含单词的内容,那就可以了.我可以获取templateName和ID,但似乎无法获取字段...
I have a search that I'm wanting to exclude any search result that has the name of the "Title" field in the search. For example, say I type in "Contact" in the search bar. I don't want the Contact Us page to come up, but if someone wants to search something that has words in the Contact Us page, then its ok. I am able to get templateName and IDs but can't seem to get fields...
Item homeItem = Main.Utilities.SitecoreUtils.getHomeItem();
var query = PredicateBuilder.True<SearchResultItem>();
query = query.And(i => i.Paths.Contains(homeItem.ID));
query = query.And(i => i.Content.Contains(searchTerm));
query = query.And(i => i.TemplateName != "MenuFolder");
这是我所拥有的,但是我想向其中添加一些内容以排除标题"字段,甚至排除"SEO"字段.所以大概是这样的:
This is what I have, but I want to add something to it to exclude the "Title" field and maybe the "SEO" field. So probably something like:
query = query.And(i => i.Fields["Title"];
但是在这种情况下,它包括但不排除它.而且我做不到:
But in this case its including not excluding it. And I can't do:
query = query.And(i != i.Fields["Title"];
它不会接受这个答案.
推荐答案
尝试使用类似i => !i["Title"].Contains(searchTerm)
的代码:
Item homeItem = Main.Utilities.SitecoreUtils.getHomeItem();
var query = PredicateBuilder.True<SearchResultItem>();
query = query.And(i => i.Paths.Contains(homeItem.ID));
query = query.And(i => i.Content.Contains(searchTerm));
query = query.And(i => i.TemplateName != "MenuFolder");
query = query.And(i => !i["Title"].Contains(searchTerm));
这篇关于如何使用Linq获取sitecore字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!