One early pain that organizations run into with SharePoint Search is the inability to perform wildcard queries (using a * to find keywords). I have identified three approaches to solve this problem.
- Use a third party tools like Ontolica, BA Insight, or FAST. These tools provide wildcard search along with additional capability like improved results pages, faceted search and more.
- I have seen customers write their own search API on top of SharePoint to get this necessary functionality. This is a good approach, but it requires you to also rewrite the results page.
- Use the Wildcard Search webpart by Corey Roth. This is a drop-in replacement for the CoreResultsWebPart. I will discuss the third approach in depth.
The webpart is easy to install. The only infrastructure requirement is that you install the .NET Framework v3.5. This is required because the web part uses LINQ to XML to parse the SelectColumns property. You can drop this on the search results page to compare it to the OOB experience. When you do this you will probably notice some subtle differences between the results. The wildcard results will probably be more numerous, however, we have lost something in the process. Some search functionality is based on keyword search including
- SearchSummaryWebPart – Provides the "Did you mean…" functionality.
- Best Bets
- Keyword Highlighting
- Federated Search – Works but treats your search term as a keyword ignoring the wildcard.
- Faceted Search
Well, do we drop this functionality to get Wildcard search? I propose a third option, we get both. Now, I’m not going to write my own implementation of the above features. We should try to detect if the wildcard query is being used, and if it isn’t then we drop back to our original keyword search. This is quite easy to do.
- Find the following code in WildCardSearchResultsWebPart.cs (line 95 for v3)
// read what the user searched for
string keywordQuery = (string)keywordQueryProperty.GetValue(searchResultsHiddenObject, null);
- Add the following code underneath
//If we're not doing the fulltext then fall back to keyword
if (!(keywordQuery.Contains('*') || AlwaysUseWildcard))
- Compile and deploy
As you can see from the additional code, if the web part is configured to always use Wildcard, this block will never fall back to keyword search. I feel this is a nice way to maintain the OOB function of Search, but provide users additional power when they need it.