1

I am using Lucene search with Sitecore 7.2 and using predicate builder to search for data. I have included a computed field in the index which is a string. When I search on that field using .Contains(mystring), it fails when there is 'and' present in mystring. If there is no 'and' in the mystring it works.

Can you please suggest me anything?

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
Aman B
  • 2,276
  • 1
  • 18
  • 26

2 Answers2

1

Lucene by default, when the field and query is processed, will strip out what are called "stop words" such as and and the etc.

If you dont want this behaviour you can add an entry into the fieldMap section of your configuration to tell Sitecore how to process the field ...

<fieldNames hint="raw:AddFieldByFieldName">
   <field fieldName="YOURFIELDNAME" storageType="YES" indexType="UN_TOKENIZED" 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>  

.. this example tells Sitecore, for that field, to not tokenize and also to put everything into lowercase. You can change to different analyzers to get the results you want.

You can try setting the indexType to TOKENIZED but still using the LowerCaseKeywordAnalyzer as another combination. UN_TOKENIZED will mean that your string will be processed as a single token which may not be what you want.

Stephen Pope
  • 3,551
  • 1
  • 17
  • 21
  • Hi Stephen, Thank you for your reply. Is it the same behaviour for computed indexes? I am using something like this MyClass,MyAssembly – Aman B Jul 03 '14 at 11:02
  • I tried your suggestion, unfortunately no luck. One thing I would like to mention is this happens when I use predicate builder, following code works perfectly fine: context.GetQueryable().Where(p => p.area == myString ); – Aman B Jul 03 '14 at 11:43
  • I have solved it, taking a hint from @Stephen Pope 's reply In order to make your computed field untokenized you have to add it both raw:AddFieldByFieldName and AddComputedIndexField. See link below http://www.sitecore.net/Community/Technical-Blogs/Martina-Welander-Sitecore-Blog/Posts/2013/09/Sitecore-7-Search-Tips-Computed-Fields.aspx – Aman B Jul 03 '14 at 15:57
  • Apologies, this behaviour is changed in the upcoming v7.5 so you only have to define it in one place (the fieldMap). Sorry for the confusion Aman! – Stephen Pope Jul 04 '14 at 13:30
  • plus1 for largely answering the question! – geedubb Feb 03 '15 at 13:50
1

I have solved it, taking a hint from @Stephen Pope 's reply. In order to make your computed field untokenized you have to add it to both raw:AddFieldByFieldName and AddComputedIndexField.

See link below http://www.sitecore.net/Community/Technical-Blogs/Martina-Welander-Sitecore-Blog/Posts/2013/09/Sitecore-7-Search-Tips-Computed-Fields.aspx

Aman B
  • 2,276
  • 1
  • 18
  • 26