我有一个带Umbraco.Tags类型字段的Umbraco.Tags。
使用“检查”搜索字段,如下所示:
var searchEngine = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
var searchCriteria = searchEngine.CreateSearchCriteria(BooleanOperation.Or);
var query = searchCriteria.Field("title", searchTerm)
.Or().Field("topicTags", searchTerm).Compile();
var results = searchEngine.Search(query);我知道这个值在topicTags内部,但结果是0.
有什么想法吗?
更新:没有找到结果的原因是因为Umbraco.Tags数据类型存储这样的数据: tag1、tag2、tag3没有空格,所以tag1不在索引中,我必须搜索"tag1,tag2,tag3“才能获得成功。
看起来,我可能不得不高调检查索引事件,并更改数据索引的方式。
这是一个内置的umbraco数据类型,当然有办法搜索它。
发布于 2014-11-11 09:52:03
是的,你的右边,我得到0的原因是标签是这样存储的: tag1,tag2,tag3。没有空格,所以tag1,tag2,tag3会导致成功,但tag1不会。
解决方案是连接到umbraco发布事件,并更改字段的索引方式。解决方案:
public class ExamineEvents : ApplicationStartupHandler
{
public ExamineEvents()
{
ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData +=
ExamineEvents_GatheringNodeData;
}
private void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
if (e.IndexType != IndexTypes.Content) return;
// Node picker values are stored as csv which will not be indexed properly
// We need to write the values back into the index without commas so they are indexed correctly
var fields = e.Fields;
var searchableFields = new Dictionary<string, string>();
foreach (var field in fields)
{
switch (field.Key)
{
case "topicTags":
var searchableFieldKey = "topicTagsIndexed";
var searchableFieldValue = field.Value.Replace(',', ' ');
if (!string.IsNullOrEmpty(searchableFieldValue))
{
searchableFields.Add(searchableFieldKey, searchableFieldValue);
}
break;
}
}
foreach (var fld in searchableFields)
{
e.Fields.Add(fld.Key, fld.Value);
}
}然后,在创建搜索查询时,可以在字段topicTagsIndexed中搜索
SearchCriteria.Field("pagetitle", searchTerm).Or().Field("topicTagsIndexed", searchTerm).Compile();希望这能帮到别人。
发布于 2014-11-10 23:58:05
所有这些都与标记值中的逗号有关。Lucene (检查)中的标准分析器将将其视为一个值。
不过,听起来您知道该怎么做--为了在索引中用空格替换逗号,需要使用检查索引器的GatheringNodeData事件-- Lucene将正确地对该属性进行索引。每当内容发布时,就会发生GatheringNodeData事件,但就在内容插入索引之前。
https://stackoverflow.com/questions/26847527
复制相似问题