Skip to main content
December 24, 2024
Question

Document Search With Partial Name

  • December 24, 2024
  • 2 replies
  • 0 views

Hello All,

I am trying to create a document search feature where the user is expected to search for documents only with document name as input. I have already tested "Content Tools - findDocumentByName()" function and realized that it only works when the full name of the file is provided as input. I want to have the partial name string search capability where the system can output list of documents with names containing the search string. Assuming the document metadata(e.g. doc id) is not stored in DB, is there any way to solve this?

2 replies

sasia0001
December 25, 2024

Try with the below steps

1) Get documents from the folder using the function fn!getdocumentsfromfolder

2) Save doc id and docname in local variable.

3) Apply contains filter in the local!finaloutput variable.

Below is the sample code

local!finaloutput: a!flatten(a!forEach(
items: local!folderdetails,
expression: a!forEach(
items: fn!getdocumentsfromfolder(fv!item.id, true()),
expression: {
folderid: document(fv!item, "folderId"),
documentid: document(fv!item, "id"),
docname:document(fv!item, "name")})))

mathieud0001
December 25, 2024

Content tools also has the findcontentbyattribute function which allows you to do a search with a wildcard

a!localVariables(
  local!documentNameToSearchFor: "documentName",
  findcontentbyattribute(
    searchAllContent: true,
    contentType: "document",
    attributeName: "name",
    searchCriteria: concat(local!documentNameToSearchFor, "*")
  )
)