Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Umbraco-使用“检查”搜索Umbraco.Tags_Umbraco_Lucene.net_Umbraco7_Umbraco6_Umbraco Blog - Fatal编程技术网

Umbraco-使用“检查”搜索Umbraco.Tags

Umbraco-使用“检查”搜索Umbraco.Tags,umbraco,lucene.net,umbraco7,umbraco6,umbraco-blog,Umbraco,Lucene.net,Umbraco7,Umbraco6,Umbraco Blog,我有一个umbraco doctype,其字段类型为umbraco.Tags 使用“检查”以如下方式搜索字段: var searchEngine = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"]; var searchCriteria = searchEngine.CreateSearchCriteria(BooleanOperation.Or); var

我有一个umbraco doctype,其字段类型为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数据类型,当然有办法搜索它。

所有这些都与标记值中的逗号有关。Lucene(检验)中的标准分析仪将其视为一个值

听起来你知道该怎么做-你需要使用检查索引器的GatheringNodeData事件,以便在索引中创建一个字段,其中逗号被替换为空格-然后Lucene将正确索引该属性。
每当内容发布时,但就在内容插入索引之前,GatheringNodeData事件就会发生,这与标记值中的逗号有关。Lucene(检验)中的标准分析仪将其视为一个值

听起来你知道该怎么做-你需要使用检查索引器的GatheringNodeData事件,以便在索引中创建一个字段,其中逗号被替换为空格-然后Lucene将正确索引该属性。
每当内容发布时,但就在内容插入索引之前,就会发生GatheringNodeData事件。是的,您的权利是,我得到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);
    }
}

希望这对其他人有所帮助。

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