The Sitecore ContentSearch Linq API provides several methods that can be used to search against string fields in different ways:
From the doc site I have been able to get a vague sense of the purpose for each and I have successfully used some of these in the past, but I have not found a clear comparison anywhere. When should I use each of these methods? Is there a significant difference in performance between any of them? Is there any notable difference in how they behave with different search providers?
This answer is for Lucene, but as Solr is based un Lucene I'm expecting to have very similar result on it
Like: This one does a fuzzy search. It gets the top terms most similar to the term you introduced and then gives you the documents containing these terms. The similarity can be adjusted. It is based on the Damerau-Levenshtein (optimal string alignment) algorithm. This is is a heavy operation, but it safe to be executed. It's translated to: fieldname:value~0.5 (The number represent how similar the terms are, from 0 to 1)
Matches: It expects a regular expresion instead of a term to match documents. If you use "plain text" it performs like "equals".
MatchWildcard: It looks for terms containing the referenced text, then it creates a query for any of the terms found. I discourage this method as it usually triggers a "too many clauses" exception. Let's say it translate each word found in the whole index for that field into o field == word 1 or filed==word2, etc. By default Lucene only support 1024 clauses. It can be modified in the config file, but it will affect performance. By default, I recomend the like search to return more related result and with a safe execution than this one. The query is translated to field:*text*.
Contains: It performs a matchwildcard
StartsWith/EndsWith: It's like the matchwildcard but only at the beginning or end of the term: The query is translated to field:*value / field:value*As terms are index alphabetically based on each character from start to end, "starts with" performs much better as it can identify the terms easily within the index while "Ends with" forces Lucene to transverse the whole term set to identify those "matching terms".
Equals: This is the basic search and is term based. It will return only documents with the whole "word". The query is translated to: field:value