user1613512
user1613512

Reputation: 3640

Sitecore 7 Index treelist lucene

I have Sitecore items with a treelist property referring to other items (with different a template). My goal is to find item A that contains item B in the treelist property using the ContentSearch api (lucene).

I've added the treelist property to my index:

  <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>

I would expect that lucene stores the treelist property as a concatenation of guids.

Assuming this is correct and my index is populated my query looks like this:

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();
}

This returns nothing. Where did it go wrong?

Upvotes: 2

Views: 740

Answers (3)

Varun Nehra
Varun Nehra

Reputation: 379

I think the guid values are stored without the braces and dashes by default. Try converting to ToShortId() before the comparison.

Upvotes: 0

Aman B
Aman B

Reputation: 2398

I think there is a typo in your index configuration, can you try

indexType="UN_TOKENIZED"

You can also investigate what values are in your lucene indexes using luke

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

Upvotes: 0

Ahmed Okour
Ahmed Okour

Reputation: 2422

You should normalize your guid, like this:

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();
}

Upvotes: 4

Related Questions