是的,你的权利,我得到 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();
希望这对其他人有帮助。