locked
Getting record count from SharePoint search service (FAST search) RRS feed

  • Question

  • Hi,

    I'm using FAST serach for SharePoint 2010 and using the search service (search.asmx) to retrieve data from an external data source that is connected through BCS.

    Is there a way to retrieve the total record count for a search without retrieving all the result set?

     

    Thanks,

     

    • Moved by hsalviMicrosoft employee Saturday, August 28, 2010 5:03 PM moving to Fast Forum (From:SharePoint 2010 - General Questions and Answers)
    Tuesday, August 24, 2010 6:27 PM

Answers

  • Hi,

    You should be able to achieve what you want by specifying in the Query Packet 0 as the number of documents you want to receive back.

    The following code shows how this could be accomplished:

    QueryServiceSoap.QueryServiceSoapClient client = new QueryServiceSoap.QueryServiceSoapClient();
    
       client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
       client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
    
       string queryXML = @"<QueryPacket xmlns='urn:Microsoft.Search.Query'>
             <Query>
              <SupportedFormats>
               <Format revision='1'>urn:microsoft.Search.Response.Document:Document</Format>
              </SupportedFormats>
              <Context>
               <QueryText language='en' type='FQL'>Microsoft</QueryText>
              </Context>
              <ResultProvider>FASTSearch</ResultProvider>
              <Range><Count>0</Count></Range>
             </Query>
            </QueryPacket>";
    
       System.Data.DataSet dataset = client.QueryEx(queryXML);
    
       string totalRows = dataset.Tables["relevantresults"].ExtendedProperties["TotalRows"].ToString();
    
    


    The parameter that tells FAST not to return any documents is <Range><Count>0</Count></Range> Once you execute the query through QueryEx, the total number of documents that match your query will be in the ExtendedProperty "TotalRows" for the "relevantresults" Data Table.

    The Query XML schema is explained in this MSDN article: http://msdn.microsoft.com/en-us/library/ms563775.aspx

    --Leo
    • Edited by leonardocsouza Tuesday, August 31, 2010 6:57 AM correcting html tags
    • Proposed as answer by leonardocsouza Tuesday, August 31, 2010 7:24 AM
    • Marked as answer by Exploring Win8 Wednesday, September 15, 2010 2:22 PM
    Tuesday, August 31, 2010 6:56 AM

All replies

  • Hi,

    You should be able to achieve what you want by specifying in the Query Packet 0 as the number of documents you want to receive back.

    The following code shows how this could be accomplished:

    QueryServiceSoap.QueryServiceSoapClient client = new QueryServiceSoap.QueryServiceSoapClient();
    
       client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
       client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
    
       string queryXML = @"<QueryPacket xmlns='urn:Microsoft.Search.Query'>
             <Query>
              <SupportedFormats>
               <Format revision='1'>urn:microsoft.Search.Response.Document:Document</Format>
              </SupportedFormats>
              <Context>
               <QueryText language='en' type='FQL'>Microsoft</QueryText>
              </Context>
              <ResultProvider>FASTSearch</ResultProvider>
              <Range><Count>0</Count></Range>
             </Query>
            </QueryPacket>";
    
       System.Data.DataSet dataset = client.QueryEx(queryXML);
    
       string totalRows = dataset.Tables["relevantresults"].ExtendedProperties["TotalRows"].ToString();
    
    


    The parameter that tells FAST not to return any documents is <Range><Count>0</Count></Range> Once you execute the query through QueryEx, the total number of documents that match your query will be in the ExtendedProperty "TotalRows" for the "relevantresults" Data Table.

    The Query XML schema is explained in this MSDN article: http://msdn.microsoft.com/en-us/library/ms563775.aspx

    --Leo
    • Edited by leonardocsouza Tuesday, August 31, 2010 6:57 AM correcting html tags
    • Proposed as answer by leonardocsouza Tuesday, August 31, 2010 7:24 AM
    • Marked as answer by Exploring Win8 Wednesday, September 15, 2010 2:22 PM
    Tuesday, August 31, 2010 6:56 AM
  • Thanks Leo.

    With count 0 it doesn't return any result. however trying with 1 worked well.

    Wednesday, September 15, 2010 2:23 PM
  • Glad to know! I'll add this to my notes here. :)

    Cheers,
    Leo

    Thursday, September 16, 2010 3:48 AM