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

Question

Question

Search and Sort using metadata

SDK
asked on May 27, 2020

Hi all.

Sorry for asking so many questions lately, but I'm doing things I've not seen before.

Usually I do an SDK search in a known folder for any files, sort by date (descending) and grab the top ID number. This usually gets me the latest document. :)

searchSettings.SetSortColumn(SystemColumn.CreationDate, Laserfiche.RepositoryAccess.SortDirection.Descending);  
SearchResultListing Results = lfSearch.GetResultListing(searchSettings);
instFileID = Results.GetDatumAsString(1, SystemColumn.Id);

However there is now a 'metadata?' field named "Status - Code" that may have a text value of "Primary" for one of the documents. If so, that is really the doc id I want. [no clue yet how to fetch/search these meta fields]

So..
How can I tweak my search to see if the word "Primary" in that field and use that ID, but if nothing is marked as Primary, just do what I'm already doing; grabbing the ID for the 'latest' document.

I've try to find this out on my own with no success.
Thank you for pondering this.

 

 

0 0

Answer

SELECTED ANSWER
replied on May 27, 2020

Add the field as a column, iterate through the results and return the first document with the field value set:

string fieldName = "Status - Code";

// Add the field column
searchSettings.AddColumn(new ColumnSpecifier(fieldName));

searchSettings.SetSortColumn(SystemColumn.CreationDate, Laserfiche.RepositoryAccess.SortDirection.Descending);  

using (SearchResultListing listing = lfSearch.GetResultListing(searchSettings))
{
	// Iterate over the results until the document with "status - code" is found
	for (int rowIndex = 0; rowIndex < listing.RowCount; rowIndex++)
	{
		EntryListingRow row = listing.GetRowData(rowIndex + 1);
		
		object statusCode = row[fieldName];
		if (statusCode != null && ((string)statusCode) == "Primary")
		{
			instFileID = listing.GetDatumAsString(rowIndex + 1, SystemColumn.Id);
			// .. This is the document you want
		}
	}
}

 

0 0
replied on May 27, 2020 Show version history

Thanks yet again Robert.

I learn by looking at samples, and couldn't find anything like this.

Going to implement this right away. Very exciting to get back on track.

I really enjoy playing with the SDK, and the people here in the forum are fantastic! 

---- Follow Up ----

Roberts sample worked great!

This line here, was the key; as I had know clue how to turn the field into a column so I could work with it.

searchSettings.AddColumn(new ColumnSpecifier(fieldName));

 

0 0

Replies

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

Sign in to reply to this post.