Locally I successfully enabled full text search on a field in the sitecore_web_index by implementing the following logic in my Sitecore solution:

1) Added this xml to a patch configuration file:

    <defaultCloudIndexConfiguration type="Sitecore.ContentSearch.Azure.CloudIndexConfiguration, Sitecore.ContentSearch.Azure">
      <fieldMap type="Sitecore.ContentSearch.Azure.FieldMaps.CloudFieldMap, Sitecore.ContentSearch.Azure">
        <fieldNames hint="raw:AddFieldByFieldName">
          <field fieldName="subtitle" cloudFieldName="subtitle_2" searchable="YES" retrievable="YES" facetable="YES" filterable="YES" sortable="YES" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.Azure.CloudSearchFieldConfiguration, Sitecore.ContentSearch.Azure" />

2) Added the index field name in the custom SearchResultItem model:

public class CustomSearchResultItem : SearchResultItem
    public virtual string Subtitle { get; set; }

3) I ensured this field was used in the search predicate:

searchQuery = searchQuery.Or(q => q.Subtitle.Contains(searchTerm));

However the above logic has just failed in the UAT environment where Azure Search is the provider.

I'm about to look through the logs for clues but is there a better/easier way of enabling full text search for a single field? Or does anyone know why the above may have failed?

  • Don't undo moderator edits, please. We're here to assist. sitecore.meta.stackexchange.com/questions/172/…
    – Mark Cassidy
    Nov 19 '19 at 13:30
  • what version of Sitecore?
    – Chris Auer
    Nov 19 '19 at 13:32
  • @MarkCassidy - the answer below which is really useful is an Azure Search vs SOLR answer - if the title doesn't include Azure Search it just comes across as a general Content Search question Nov 19 '19 at 13:41
  • @ChrisAuer It's for Sitecore version 8.2 Nov 19 '19 at 13:42

I've had similar issues to this in the past. Contains() seems to Work in a strange way in Azure Search vs Solr. If I recall it does a regex match on each word. The documentation here is a little confusing: https://doc.sitecore.com/developers/90/platform-administration-and-architecture/en/support-reference-for-azure-search.html

What I've seen work is a like fairly well is creating a 'phrased search query' so that the query is treated as a single string and then using the Like() operator instead like so:

var phrasedSearchTerm = $@"""{searchTerm.Trim()}""";
searchQuery = searchQuery.Or(q => q.Subtitle.Like(phrasedSearchTerm));

An alternative you can also try is the MatchWildcard() operator like so:

searchQuery = searchQuery.Or(q => q.Subtitle.MatchWildcard($"*{searchTerm.Trim()}*"));

One other thing I would consider doing (depending on what validation you have in place in your search) is creating an extension method to strip out certain special characters as these can confuse your search. e.g something like:

public static string EscapeCharacters(this string input, string charactersToEscape = @" ,(,),&,-,+,*")
    foreach (var character in charactersToEscape.Split(',').ToList())
        input = input.Replace(character, $@"\{character}");
    return input;

Lastly when testing this look in the latest 'search.log.[data].txt' log files to see what Query is actually being generated by Sitecore and sent off to Azure Search, the logs will look something like:

ManagedPoolThread #9 10:47:10 INFO AzureSearch Query [query here]

You can test the search yourself in the Azure Portal too and see what you get back.

There is more info on issues with Azure search queries here: Azure search matching wildcard instead of equals


Our final fix for this was around the way we retrieved data from the index.

We simply used the predicate:

searchQuery = searchQuery.Or(q => q.Subtitle == searchTerm);

Instead of:

searchQuery = searchQuery.Or(q => q.Subtitle.Contains(searchTerm));

With Azure the '==' operator in a predicate doesn't behave how you might think it would (or at least it didn't for us).

If the field is indexed as type 'Edm.String' then the '==' will find all instances of the search term within the subtitle fields as well as variations of that search term.

For example if the searchTerm is "investment" all subtitles that contain "investments", "investment" and "invest" are returned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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