2

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?

4
  • Are you making sure to lowercase the GUID value you query with? If I remember it correctly; all GUIDs go into your index as lowercase. Nov 3, 2014 at 9:24
  • Yes tried that as well. Nov 3, 2014 at 9:49
  • So I tried this yesterday. Map the field has IndexField("name of field in lucene") public IEnumerable<ID> Values {get;set;}. Then follow Aman's approach. Works great.
    – Gabbar
    Nov 3, 2014 at 19:43
  • Here is something that you can refer to. May solve your problem - sitecorecontextitem.wordpress.com/2013/12/06/…
    – Gabbar
    Nov 3, 2014 at 19:45

3 Answers 3

4

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

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.