Amir Salah
Amir Salah

Reputation: 31

TotalResults count changed when page index changed FullTextQuery in sharepoint search

I create custom search for SharePoint search. if i search it wit page size 10 and page index (0 or 1 or 2) total result count will be 55 when actual result 40, else if page size 10 and page index 4 total result count will be 50 and no rows returned else if page size 10 and page index 3 total result count will be 40, else if page size 100 and page index 0 total result count will be 40.

My Code:

private static DataTable ExecuteSearchQuery(SPWeb web, int pageNumber, int pageSize, ref long totalRecords)
    {
        FullTextSqlQuery query = new FullTextSqlQuery(web.Site);
        query.StartRow = pageSize * (pageNumber - 1);
        query.RowLimit = pageSize;
        query.TrimDuplicates = true;
        query.ResultTypes = ResultType.RelevantResults;
        query.QueryText = @"SELECT ID, Title, Modified ,URL  FROM Scope() WHERE (CONTAINS(Url, '/lists/Comments') AND FREETEXT(Title,'*any*'))";
        ResultTableCollection results = query.Execute();
        DataTable searchResults = results[ResultType.RelevantResults].Table;
        totalRecords = query.QueryInfo.TotalResults;
        return searchResults;
    }

Upvotes: 1

Views: 2092

Answers (1)

asilioni
asilioni

Reputation: 1

the problem is caused by the paging web part. If you modify it to show all the pages, the statistic total results number will be always the same. For example, from the paging web part properties, change the number of pages before and after current page to 1000, then you will see that your problem will not exist anymore!! This is a bit ugly if you have many pages!!!

Check out this: http://kamilmka.wordpress.com/2012/04/14/customize-sharepoint-search-results-paging/

Upvotes: 0

Related Questions