Document Search With Partial Name

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?

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    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")})))

  • 0
    Certified Lead Developer

    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, "*")
      )
    )