Sitecore 8.1:从 Lucene 切换到 SOLR - 从 SearchContext 得不到任何结果

Sitecore 8.1: Switching from Lucene to SOLR - Getting no results from SearchContext

我已在 Sitecore 8.1 中切换到 SOLR 搜索,一切正常(索引正常重建)。但是,当我使用 SearchContext 搜索项目时,我根据 item.Path.Contains("") 进行过滤时没有得到任何结果,尽管它使用 Lucene。如果我删除 item.Path.Contains(""),我会得到结果。那么,为什么它不起作用? 这是使用的代码:

        List<NewsSearchResultItem> results = new List<NewsSearchResultItem>();
        var index = ContentSearchManager.GetIndex("sitecore_web_index");

        using (IProviderSearchContext context = index.CreateSearchContext())
        {
            var tempResults = context.GetQueryable<NewsSearchResultItem>()
                   .Where(item => item.Path.Contains("/sitecore/content/News"))
                   .Take(10);

            results = tempResults.ToList();
        }

        return results.Select(s => new NewsViewModel(s.GetItem())).ToList();

默认情况下,带有 Sitecore 的 Solr 将文本字段存储为小写字段。

更改 Where 子句以使用 path/toLower():

var pathToLower = "/sitecore/content/news";
... .Where(item => item.Path.Contains(pathToLower))

另外请记住添加过滤器以仅使用您当前的语言 - Solr 中可能有一些针对 Sitecore 项目的文档,尽管它们没有特定语言的任何版本。

这可能是Marek所说的小写问题,不过你也可以尝试用Paths 属性代替Path,如下:

var tempResults = context.GetQueryable<NewsSearchResultItem>()
                   .Where(item => item.Paths.Contains(Sitecore.Data.ID.Parse("News Item ID (GUID)")))
                   .Take(10);