How to replace %20 with <space> using conditional skillset?

Haaris Jalal 0 Reputation points
2023-03-21T18:10:15.8733333+00:00

Hi,

I am trying to use a conditional skillset to remove part of a name and replace it with space. For Example, I would like to replace %20 with <space>. I was looking into the document related to conditional skill, link below, but cannot find any "contain" property.

https://learn.microsoft.com/en-us/azure/search/cognitive-search-skill-conditional

Could you please let me know how can I write the condition so that it states, if the name property contains '%20', replace it with " ".

Looking forward to your reply.

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
937 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 17,886 Reputation points
    2023-03-30T20:23:14.3533333+00:00

    Hi @Haaris Jalal

    Thanks for your patience. You can use the "indexOf" function in combination with the "replace" function to achieve your scenario. Here's an example condition you can use:

    if (ctx.name && ctx.name.indexOf('%20') !== -1) {
       ctx.name = ctx.name.replace('%20', ' ');
    }
    
    

    This condition first checks if the 'name' property exists and contains '%20' by using the "indexOf" function. If '%20' is found, it is replaced with a space using the "replace" function.

    You can include this code in a conditional skill definition to process the 'name' property of your input documents. Here's an example skill definition that uses this condition:

    {
      "name": "replace-space",
      "description": "Replace '%20' with space in name property",
      "context": "/document",
      "inputs": [
        {
          "name": "name",
          "source": "/document/name"
        }
      ],
      "outputs": [
        {
          "name": "name",
          "targetName": "name"
        }
      ],
      "condition": "if (ctx.name && ctx.name.indexOf('%20') !== -1) { ctx.name = ctx.name.replace('%20', ' '); }"
    }
    
    

    In this skill definition, the 'name' property of the input document is mapped to the 'name' input of the skill. The condition is used to replace '%20' with a space in the 'name' property, and the resulting value is mapped back to the 'name' property of the output document.

    Note that the condition uses JavaScript syntax and can be customized based on your specific requirements.

    Hope that helps

    -Grace

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.