You are viewing limited content. For full access, please sign in.

Question

Question

RA Search.GetHitCount always returns 0

asked on September 22, 2017

I'm finally in the process of updating an integration to the .Net SDK, version 10.2. I've attempted to use Search.GetHitCount method a couple of times, but it keeps returning zero. I incorporated sample code from the SDK to check that the search completes before moving forward. If I remove the raFolSearch.GetHitCount > 0 line, the code proceeds without any issues.

raFolSearch = New Search(raLFSession)
raFolSearch.Command = "{LF:Name=""LFFolder"",TYPE=""F""}"
Dim longOp As LongOperation = raFolSearch.BeginRun(True)
While Not longOp.IsCompleted
     Thread.Sleep(1000)
     raFolSearch.UpdateStatus()
End While

If raFolSearch.GetHitCount > 0 Then.......

Am I using the method incorrectly?

0 0

Replies

replied on June 8, 2022

Hi There,

Old question but deserves a response for those looking. I have never gotten any result other than 0 so stop trying to use it.  Instead for a "hit count" I use: 

 

mySearch.Run();
SearchStatistics SS = mySearch.GetSummaryStats();

Console.WriteLine("Entries Found: " + SS.DocumentCount);

 

Wiley

1 0
replied on August 5, 2024 Show version history

Old topic but I wasted a lot of time with the same issue, and finally I found out that, using RepositoryAccess, Search.GetHitCount only gives a result if using FullTextSearch, it doesn't work with complex search syntaxes.

 

Here you have the code, if it helps someone:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim cloudTicketSettings As New CloudTicketRequestSettings()
        Dim cloudTicket As CloudTicket
        Dim cloudSession As Session

        cloudTicketSettings.AccountId = "123456"
        cloudTicketSettings.UserName = "user"
        cloudTicketSettings.Password = "password"

        cloudTicketSettings.CustomEndpoint = New Uri("https://acs.laserfiche.ca/ACS/")

        cloudTicket = cloudTicket.GetTicket(cloudTicketSettings)

        Dim repositoryHost As String = "r-000111xxxxx.laserfiche.ca"

        cloudSession = Session.Create(repositoryHost, cloudTicket)

        Dim searchstring As String
        
        searchstring = 165008                               'Full text search
        searchstring = "{LF:Name=""165008"", Type=""D""}"   'Complex search

        Dim StudentSearch As New Search(cloudSession, searchstring)
        StudentSearch.BeginRun(True)

        Dim ss As SearchStatistics = StudentSearch.GetSummaryStats     'This always work
        Dim ResultCountSS As String = ss.DocumentCount

        Dim ResultCount As Integer = StudentSearch.GetHitCount        'This only works with full text search

        StudentSearch.Close()
        cloudSession.Close()
        End
    End Sub

 

Good luck!

IPdeA

0 0
replied on August 5, 2024 Show version history

The recommended method to check whether the search has results is to retrieve the listing results and use the length of the listing:

using (Search search = new Search(session, "{LF:Name=\"doc name\", Type=\"D\"}"))
{
    search.Run();
    while (search.Status != SearchStatus.Done)
    {
        search.UpdateStatus();
        System.Threading.Thread.Sleep(5);
    }

    SearchListingSettings setting = new SearchListingSettings();
    setting.SortColumn = new ColumnSpecifier(SystemColumn.Id);
    setting.AddColumn(SystemColumn.Id);

    using (SearchResultListing listing = search.GetResultListing(setting))
    {
        if (listing.RowCount > 0)
        {
            // Search has results
        }
    }
}

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.