Click here to Skip to main content
15,906,333 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi there.

I am building a Sharepoint custom search webpart using C# and ASP.net with .Net 3.5.

I am using the KeywordQuery search types so that the user can use the wildcard (*) function and we display the results using a custom results screen.

After sharepoint has returned it's results, we do some additional filtering based on some other criterias that arent accessible/usable through sharepoint.

All of this works great

My problem comes in when the user searches for a blank string. I get the error:
"Your query is malformed. Please rephrase your query.", which makes complete sense as Sharepoint doesn't understand what to search for.
But unfortunately, because of the other filtering that we are doing, we sometimes need the users to be able to search on a blank/empty string.

If anyone has any idea on how to do this, it would be much Appreciated.

Regards
Francois


UPDATE on behalf of OP (moved from answer):
This was my code:

C#
SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site));

            KeywordQuery query = new KeywordQuery(proxy);

query.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default;

            query.QueryText = TextBox1.Text;
            query.ResultTypes = ResultType.RelevantResults;
            query.EnablePhonetic = true;
            query.TrimDuplicates = false;
            query.RowLimit = 1000;
            query.KeywordInclusion = KeywordInclusion.AllKeywords;

            query.SelectProperties.Add("Field1");
            query.SelectProperties.Add("Field2");
            query.SelectProperties.Add("Field3");

            
            ResultTableCollection searchResults = query.Execute();


But all I did was when the user enters an epty string i forced the query string to the following:

"Isdocument:1"

Which then returns all my documents.
Posted
Updated 30-Jul-12 7:53am
v2
Comments
Where is the code ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900