Sitecore 7 Index treelist lucene

时间:2014-11-03 08:57:10

标签: lucene sitecore sitecore7

我有一个带有treelist属性的Sitecore项目引用其他项目(使用不同的模板)。 我的目标是使用ContentSearch api(lucene)在treelist属性中找到包含项目B的项目A.

我已将treelist属性添加到我的索引中:

  <indexConfigurations>
    <defaultLuceneIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
      <fieldMap             type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
        <fieldNames hint="raw:AddFieldByFieldName">
          <field patch:before="field[0]" fieldName="TreelistProperty" storageType="YES" indexType="UNTOKENIZED" vectorType="NO" boost="1f" type="System.String"
                 settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
            <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />
          </field>
        </fieldNames>
      </fieldMap>
    </defaultLuceneIndexConfiguration>
  </indexConfigurations>

我希望lucene将treelist属性存储为guids的串联。

假设这是正确的并填充了我的索引,我的查询如下所示:

master = Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_master_index");
using (var context = master.CreateSearchContext())
{
    var results = context.GetQueryable<SearchResultItem>()
                .Where(x => x["TreelistProperty"].Contains("{456-41414-my-guid-here-1516}"))
                .GetResults();
    var hits = results.Hits.ToArray();
}

这不会返回任何内容。它出了什么问题?

3 个答案:

答案 0 :(得分:4)

你应该正常化你的guid,如下:

var master = Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_master_index");
using (var context = master.CreateSearchContext())
{
    Sitecore.Data.ID myId = ID.Parse("{456-41414-my-guid-here-1516}");
    string normalizedID = Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(myId );
    var results = context.GetQueryable<SearchResultItem>()
                .Where(x => x["TreelistProperty"].Contains(normalizedID))
                .GetResults();
            var hits = results.Hits.ToArray();
}

答案 1 :(得分:0)

我认为您的索引配置中存在拼写错误,可以尝试

INDEXTYPE = “UN_TOKENIZED”

您还可以使用luke

调查lucene索引中的值

http://www.sitecore.net/en-gb/learn/blogs/technical-blogs/getting-to-know-sitecore/posts/2013/06/using-luke-to-understand-sitecore-7-search.aspx

答案 2 :(得分:0)

我认为guid值默认存储时没有大括号和短划线。尝试在比较之前转换为ToShortId()。