3

I have a requirement in which I want to get the search results programmatically. For this I am using KeyWordQuery to search programmatically. But here I am getting less results that default SharePoint search, it is omitting some records from the results.

Here is the code I am using

    SPSite site = SPContext.Current.Site;
    KeywordQuery objkeywordquery = new KeywordQuery(site);
    objkeywordquery.QueryText = strQuery;
    objkeywordquery.SelectProperties.Add("Title");
    objkeywordquery.SelectProperties.Add("Path");

    objkeywordquery.ResultsProvider = SearchProvider.Default;
    objkeywordquery.ResultTypes = ResultType.RelevantResults;
    objkeywordquery.RowLimit = 5000
    ResultTableCollection queryResults = objkeywordquery.Execute();
    ResultTable queryResultsTable = queryResults[ResultType.RelevantResults];

    DataTable queryDataTable = new DataTable();

    queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);

f I get 100 results in sharepoint search reults page, with the same querytext I get 96-97 results. Can someone help me with this

1

Try setting TrimDuplicates = false; http://msdn.microsoft.com/en-us/library/microsoft.office.server.search.query.query.trimduplicates.aspx

SPSite site = SPContext.Current.Site;
KeywordQuery objkeywordquery = new KeywordQuery(site);
objkeywordquery.QueryText = strQuery;
objkeywordquery.SelectProperties.Add("Title");
objkeywordquery.SelectProperties.Add("Path");

objkeywordquery.ResultsProvider = SearchProvider.Default;
objkeywordquery.ResultTypes = ResultType.RelevantResults;
objkeyworkquery.TrimDuplicates = false;
objkeywordquery.RowLimit = 5000
ResultTableCollection queryResults = objkeywordquery.Execute();
ResultTable queryResultsTable = queryResults[ResultType.RelevantResults];

DataTable queryDataTable = new DataTable();

queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.