我有一个功能,它搜索Sitecore内容项目中的一些文章,并给我的价值。到目前为止,我已经建立了我的索引,并在我的IndexViewer中显示。但是函数的返回值为0.我查找了这个链接:http://sitecoregadgets.blogspot.com/2009/11/working-with-lucene-search-index-in_25.html了解更多信息。Lucene搜索不起作用
protected IEnumerable<Item> ShowHomePageNews(int numOfArticles, string stringofCountries)
{
List<Item> items = new List<Item>();
Sitecore.Search.Index indx = SearchManager.GetIndex("newsArticles");
using (IndexSearchContext searchContext = indx.CreateSearchContext())
{
var db = Sitecore.Context.Database;
CombinedQuery query = new CombinedQuery();
QueryBase catQuery = new FieldQuery("countries", stringofCountries); //FieldName, FieldValue.
SearchHits results = searchContext.Search(catQuery); //Searching the content items by fields.
SearchResultCollection result = results.FetchResults(0, numOfArticles);
foreach (SearchResult i in result)
{
items = result
.Where(r => !r.Title.StartsWith("*"))
.Select(r => db.GetItem(new Sitecore.Data.ItemUri(r.Url).ToDataUri()))
.ToList();
//Lucene.Net.Documents.Field url = i.Document.GetField("_url");
//Sitecore.Data.ItemUri itemUri = new Sitecore.Data.ItemUri(url.StringValue());
//Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem(itemUri.ToDataUri());
//items.Add(item);
}
}
return items;
}
在这里的结果是0.我在这里做什么wrond?
这是快照我所看到的在我的IndexViewer:
编辑:
我传递一个 “NZ” 在 'catQuery' 和我得到结果回来了。因为在我的索引查看器中,我看到了Field Name = _name,其中包含NZ。我得到了这部分。但是,我希望我的每个领域都能被索引。我在IndexViewer中只看到3个字段:_url,_group & _name。
您可以在“国家”字段中指定值的格式/内容以及stringofCountries参数的格式/内容吗? – techphoria414
整个方法是否返回0结果或'results.FetchResults(...)'? –
您还可以在索引查看器中添加几行数据示例吗? –