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

Question

Question

Searching the repository to find documents with a particular tag set

asked on April 11, 2014

 

Good Morning All,

 

I'm working on evolution three of my project. Issue: I'm trying to search the repository and find every instance where a tag labeled "Document Closed and Ready for Export" has been set. This is triggered when a checkbox is checked on the main form. For testing purposes I'm not implementing that phase, merely telling the app to search everything

 

My code is as follows, and does work, except for the tag locating. I'm trying to use the .NET RA and such rather than the old LFSO. I used a reference found in the LF SDK 9 help files, but I think once again, I'm not using the new procedures properly.

 

I've ID'ed the code I'm working with  using the rem statement ' *********************************TAG CODE ***********************************************

 

The code for the search is as follows.

 

My question is, what is the proper setup for finding the checked tag?

 

Regards,

Brian

 

 

Try
     ToolStripStatusLabel1.Text = "Beginning data export of Laserfiche files. This may take some time. Please be patient."

     ' Setting up the connection to the Repository
     Dim serverName As String = CMBLaserficheServerName.Text, repositoryName As String = CMBRepositoryName.Text
     Dim userName As String = CMBLaserficheRepositoryUserLogin.Text, userPassword As String = CMBLaserficheRepositoryUserPassword.Text
     Dim mySession As New Session
     Dim startDate As String = DateandTimeStart.Value
     Dim endDate As String = DateandTimeEnd.Value
     Dim listing As New List(Of String)

' *********************************TAG CODE ***********************************************
    Dim GetInfo(Tags.Equals(Tag("Document Closed and Ready for Export")))

'***********************************TAG CODE***********************************************

  ' Log into the Repository
     mySession.LogIn(userName, userPassword, New RepositoryRegistration(serverName, repositoryName))
     ' Instantiate the search objects...
      Dim searchParameters As String = "{LF:Name=""*"", Type=""DB""} & {LF:Created>=""" & startDate & """, Created<=""" & endDate & """} "
       Dim lfSearch As Search = New Search(mySession, searchParameters)
       Dim settings As SearchListingSettings = New SearchListingSettings
       Dim searchResults As SearchResultListing
        ' What columns do you want the search to retrieve...
      settings.AddColumn(SystemColumn.Name)
      settings.AddColumn(SystemColumn.CreationDate)
      settings.AddColumn(SystemColumn.EntryType)
      settings.AddColumn(SystemColumn.Path)
      settings.AddColumn(SystemColumn.Tags)
      ' Run the search...
      ToolStripStatusLabel1.Text = "Searching the repository for entries that match the search criteria."
      lfSearch.Run()
      ' Get the results...
       searchResults = lfSearch.GetResultListing(settings)
       ' If there are any results then step through them...

            If searchResults.RowCount > 0 Then
                ' In this case I am just adding the document name and the creation date to the list...
                For i As Integer = 1 To searchResults.RowCount
                    ' Write text to the listbox output
                    ListBox1.Items.Add(searchResults.GetDatumAsString(i, SystemColumn.Path) _
                    & " " & searchResults.GetDatumAsString(i, SystemColumn.Name) _
                    & " " & searchResults.GetDatumAsString(i, SystemColumn.EntryType) _
                    & " " & searchResults.GetDatumAsString(i, SystemColumn.CreationDate) _
                    & " " & searchResults.GetDatumAsString(i, SystemColumn.Tags))
                    ' Prep for getting or creating file to write text to the output log
                    Dim outputFile As StreamWriter
                    ' Create file on server
                    File.Create(CMBOutputLogFileLocation.Text).Dispose()
                    outputFile = File.CreateText(CMBOutputLogFileLocation.Text)
                    ' Write the items in the listbox into a file chosen by the user
                    ToolStripStatusLabel1.Text = "Writing document entry list to output file"
                    outputFile.WriteLine("Document gathering starting." & DateAndTime.Today & DateAndTime.TimeOfDay)
                    Dim ii As Integer = 0
                    While ii < ListBox1.Items.Count
                        outputFile.Write(ListBox1.Items(ii).ToString)
                        outputFile.WriteLine(1)

' *********************************TAG CODE ***********************************************

                Console.WriteLine(GetInfo)

' *********************************TAG CODE ***********************************************

                        ii += 1
                    End While
                    outputFile.WriteLine("Document gathering complete." & DateAndTime.Today & DateAndTime.TimeOfDay)
                    outputFile.Close()
                Next
            End If

            'Cleanup...
            listing = Nothing
            lfSearch = Nothing
            settings = Nothing
            searchResults = Nothing
            mySession.Close()
            mySession = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

 

0 0

Answer

SELECTED ANSWER
replied on April 11, 2014

Your code looks rather complicated, and I don't actually see where you are doing the tag search. Advanced Search Syntax supports searching directly for your tag by name using {LF:Tags="TagName"}. Here is some example code for retrieving DocumentInfos for all documents with a specific tag:

Dim myTag As String = "MyTagName"

Dim searchParameters As String = "{LF:Tags=""" & myTag & """}"

' You seem to be also looking for creation dates within a range
' I'll assume that you have these formatted correctly

Dim startDate As String = DateandTimeStart.Value
Dim endDate As String = DateandTimeEnd.Value

searchParameters = searchParameters & " & {LF:Created>=""" & _
    startDate & """, Created<=""" & endDate & """}"

' Assuming you have a logged in Session, s

Dim lfSearch As Search = New Search(s, searchParameters)
Dim settings As SearchListingSettings = New SearchListingSettings()
settings.AddColumn(SystemColumn.Id)
' Add other columns that you want here

lfSearch.Run()

Dim searchResults As SearchResultListing = _
    lfSearch.GetResultListing(settings)

For Each item As EntryListingRow In searchResults
    Dim docId As Integer = item(SystemColumn.Id)

    Console.WriteLine(docId)

    ' DocumentInfos must be disposed of after use. The Using
    ' block handles this for us.
    Using info As DocumentInfo = New DocumentInfo(docId, s)
        ' Do whatever you need to with the document
    End Using
Next

This worked on one test search, but it may not be bug free. It should give you a general idea of how to search for tags, though. Do remember to dispose of any DocumentInfos that you create, as well as your Session.

1 0

Replies

replied on April 11, 2014

Have you considered adding the tag to the search query?  This is the syntax.

0 0
replied on April 11, 2014

Mathew,

 

I did actually try using the tag search but it did not return anything  and so I was trying a different snippet thinking I might have misunderstood the RA variant.

 

Nice comment though, and your comment shows that I was thinking along the proper lines. I suppose I should have stopped and posted at that time.

 

Regards,

Brian

0 0
replied on April 11, 2014

Have you checked that the user running the search has permissions to see the documents that you were searching for? If these tags are security tags, you'll have to make sure that the user has that tag assigned.

0 0
replied on April 11, 2014

Hi Mathew,

 

Yes sir. The account is the default admin account and it has "god mode" rights to everything. (verified). The whole program functions and pulled information perfectly until I started tinkering with the tag idea.. As I explained to Cliff I transitioned from a VB6 environment to VS 2010 and now 2013. big difference, and still learning, but man is it fun!

 

The tags are just tags, no security. They basically are used to show a condition has been filled and it is safe to proceed to the next step.

 

Regards,

Brian

0 0
replied on April 21, 2014

Mathew's suggestion worked like a charm.

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

Sign in to reply to this post.