multiple keyword wildcard search

Nov 12, 2009 at 6:23 PM

Thank you for this useful web part.

Your wildcard search works fine for one keyword expression, but not for a multiple keywords.

Here is the part of your code (inside GetFullTextQuery function) that I have changed: 

	// append an asterisk if alwaysUseWildcard is on
	if ((AlwaysUseWildcard) && (!keywordQuery.EndsWith("*")))
		keywordQuery += "*";
			
	// append the wildcard query
	fullTextQuery.AppendFormat("CONTAINS ('\"{0}\"')", keywordQuery);

... by the following to make the multiple keyword search work fine.

            //split the keyword query into words (separated by spaces)
            //each word (with optional addition of *) is then put in the CONTAINS expression with AND operator
            string containsExpression = "";
            string theWordWithWC;
            bool firstWord = true;
            string[] lesMots = keywordQuery.Split(' ');
            foreach (string theWord in lesMots)
            {
		// append an asterisk if alwaysUseWildcard is on
                if ((AlwaysUseWildcard) && (!theWord.EndsWith("*")))
                    theWordWithWC = String.Format("{0}*", theWord);
                else
                    theWordWithWC = theWord;
    			
                if (!firstWord)
                    containsExpression += " AND ";

                containsExpression += String.Format("\"{0}\"", theWordWithWC);
                firstWord=false;
            }

		// append the wildcard query
            fullTextQuery.AppendFormat("CONTAINS ('{0}')", containsExpression);

In summary, I have replace the single expression inside the CONTAINS operator by on containing the AND operator between each keyword.

But like your version, it does not work in Advanced search page.

Feel free to use this code as you wish.

Hope it helps.

Charles

Jan 18, 2010 at 7:59 AM

Hi Charles. Do you have a wsp package with the above revised cs file compiled into the DLL? I don't have the necessary tools to recompile the DLL and do it myself.

 

Many Thanks,

Tim