【发布时间】:2014-10-22 15:22:52
【问题描述】:
我正在尝试排除存储项目 ID 的字段为空的搜索结果。例如,此字段称为“类型”。我无法使用 LINQ 做到这一点。这是我的代码示例。
public class SearchItem : SearchResultItem
{
[IndexField("type")]
public string Type{ get; set; }
}
public class Search
{
public static IEnumberable<Item> GetItems()
{
List<Item> items = new List<Item>();
var index = ContentSearchManager.GetIndex(new SitecoreIndexableItem(Sitecore.Context.Item));
using (var context = index.CreateSearchContext())
{
var indexItems = context.GetQueryable<SearchResultItem>()
.Where(x => !string.IsNullOrEmpty(x.Type))
.OrderByDescending(x => x.ReleaseDate);
foreach(var indexItem in indexItems)
{
var tempItem = indexItem.GetItem();
items.Add(tempItem);
}
}
return items;
}
}
空字符串比较不起作用,并且项目集合包含类型字段具有空字符串的项目。我正在使用 Lucene 的开箱即用设置。
另外,如果您发现有问题,请在我的代码中戳洞。这是我第一次使用 Sitecore 7 Search。
【问题讨论】:
-
我对此不是 100% 的,但我认为在 Lucene 中不可能像使用 SQL 那样进行否定匹配。通过使用 IsNullOrEmpty,您是说您需要识别索引中的空值/空值,但这些值一开始就不会添加到索引中,因此没有什么可以匹配的。底线,我不认为你可以检查缺席
标签: c# lucene sitecore sitecore7 sitecore7.2