Wildcard Search for People (or any other scope)

I recently downloaded the DotMafia's version of WildCard Search from CodePlex ( http://www.codeplex.com/WildcardSearch). It works well overall, however, I have a custom scope and the wildcard search does not take any scopes into account. Therefore my results when using a "*" returns everything in crawled content. I have a solution. If you want to use the wildcard search only within certain scopes, you can modify the code to do so; essentially you modify the full text query.

Open the web part code (WildCardSearhResults.cs) and locate the GetFullTextQuery method. Within that method search for the following code:

// append the from clause
fullTextQuery.Append(" FROM Scope() WHERE ");

To add scopes to a full text query the syntax is WHERE "scope" = '{scope name}' (both the double quotes around scope and the single quotes around the scope name are required). Therefore you can modify the code to only use the People scope, for example, using the following:

// append the from clause
fullTextQuery.Append(" FROM Scope() WHERE \"scope\" = 'People' AND " );

The AND is needed to append the other items the code generates. Recompile and re-deploy and it should work (I actually needed to Retract and Remove the solution from Central Admin). If you need various wilcard web parts to co-exist, you will probably need to change the names of everything in the original solution and create a "new" web part for the scope you are interjecting into the code.

1 comments:

Steve Mann said...

I have an even better solution that makes the scope generic. It will use the Scope entry from the tool pane (under Miscellaneous).

Here is the updated code:

// append the from clause
if (base.Scope != null)
{
fullTextQuery.Append(" FROM Scope() WHERE \"scope\" = '" + base.Scope + "' AND ");
}
else
{
fullTextQuery.Append(" FROM Scope() WHERE ");
}