Search Web Service does not return correct record count.
- Hi I am trying to simulate the advanced search box functionality using a web service. The number of hits I get from the web service are enormously huge and I am pretty sure they are incorrect because they are far more than what advanced search returns. This is what I am doing:
private const string keywordQueryTemplate = @"<?xml version='1.0' encoding='utf-8' ?>
<QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'>
<Query domain='QDomain'><Range><StartAt>{1}</StartAt> <Count>{0}</Count></Range>
<EnableStemming>false</EnableStemming>
<TrimDuplicates>true</TrimDuplicates>
<IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery>
<ImplicitAndBehavior>false</ImplicitAndBehavior>
<IncludeRelevanceResults>false</IncludeRelevanceResults>
<IncludeSpecialTermResults>false</IncludeSpecialTermResults>
<IncludeHighConfidenceResults>false</IncludeHighConfidenceResults>
<SupportedFormats>
<Format>urn:Microsoft.Search.Response.Document.Document</Format>
</SupportedFormats><Context>
<QueryText type='MSSQLFT'>" +"SELECT Title, Path, Description, Write, Rank, Size,isDocument FROM Scope() WHERE FREETEXT(DEFAULTPROPERTIES,'query_text_placeholder') and \"scope\"='Resumes' and IsDocument = 1 order by rank" +
@"</QueryText></Context>
</Query></QueryPacket>";
I provide three variables to this query:
1) StartAt
2) Count
3) Query word
I have a grid which displays the search results and I have two buttons "Next" and "Previous" to handle paging.
On click of "Next" or "Previous" I increment/decrement the StartAt parameter.
I get results by using the following statementresultDataset = searchService.QueryEx(queryString);
I believe I should get the total record count from resultDataset.Tables["RelevantResults"].ExtendedProperties["TotalRows"].
But the problem is that each time the value changes. I can understand if the values inreases/decrease by "Count" since I am increasing/decreasing the StartAt index. But that is not the case. Sometimes the record count is 38000 and sometimes its 11000.
The code is shown below.private void StartSearch(string count, string startAt)
{
DataSet resultDataset = new DataSet();
SearchService.QueryService searchService = new SearchService.QueryService();
searchService.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
string queryString = keywordQueryTemplate.Replace
("query_text_placeholder", txtQueryText.Text.Trim());
queryString = string.Format(queryString, count, startAt);
searchService.Url = WEBSERVICE_URL + "search.asmx";
resultDataset = searchService.QueryEx(queryString);
string labelCount = "Currently displaying {0} of {1} records: ";
string recCount = resultDataset.Tables["RelevantResults"].ExtendedProperties["TotalRows"].ToString();
if (Session["TotalRows"] == null)
Session["TotalRows"] = recCount;
if (Int32.Parse(recCount) < Int32.Parse(Session["endAt"].ToString()))
{
Session["endAt"] = recCount;
btnSearch.Enabled = false;
}
lblRecCount.Text = String.Format(labelCount, Session["endAt"].ToString(), Session["TotalRows"].ToString());
Page.Session["TableData"] = fillResultsGrid(resultDataset);
}
All Replies
- There is no telling if you actually executing the exact same query as the advanced search web part does. Keep in mind all result counts are estimated. You may have trouble getting these numbers to match up. Also, the accuracy of the result count gets better the closer you are to the end of the resultset using StartAt.
Corey Roth blog: www.dotnetmafia.com twitter: twitter.com/coreyroth


