1
votes

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?

2
This is only the case with computed index field, for a normal indexed field it works fineAman B
This is how I am adding the computed indexfield, it is a string value <fields hint="raw:AddComputedIndexField"> <field fieldName="area" storageType="no" indexType="TOKENIZED" >MyClass,MyAssembly</field> </fields>Aman B
Could you please add some code samples here?Ahmed Okour
Hi Ahmed, thank you for your reply. However I have solved it now.Aman B

2 Answers

1
votes

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.

1
votes

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