Quick Tip – Automatically Add Wildcard To Conditional SharePoint Search Queries

by | Microsoft 365, SharePoint, Teams

Powered by LUCK™

One of the hardest things to do is to train users on how to query SharePoint search effectively.  The hardest thing is probably trying to get users to use metadata instead of folders, but that is a battle for another day.  Today I needed a way to give users a helping hand when using search to automatically include a wildcard * in the query.  Small steps add up to great adoption! 

I’ll also throw in a few examples of using regex expressions to match your search results.

The Use Case

In the case of my client that was having this issue, there are SharePoint sites that have a name that is 3 letters then 6 numbers (a date) like EMC180406.  Users wanted to be able to just search EMC and quickly find the SharePoint site.  The default results include mostly documents and not the sites, when there are many subsites like EMC170905, EMC160218, etc. 

Of course we could just tell users “just add * to your search query”, but can we help and do that automatically for them?  Yep and without editing any web parts!

Configure A Search Query Rule

We will achieve this using a search query rule, either at the search service/site collection/subsite level.  I won’t give you the complete step-by-step for creating a query rule, but I will highlight the important parts to make this work.

For bonus points, I’ll show you some fancy regex.

  1. Start creating your query rule
  2. Set the query keyword match or whatever condition suits you (i.e. when someone searches “EMC”).  In our specific case, we need to use pattern matching to say when the query is 3 capital letters.  If you want to do something similar, choose “Advanced Query Text Match”.  But your criteria could be whatever you like.
  3. For the pattern, this uses a regex expression.  To match for 3 capital letters enter the following:
    1. ([A-Z]{3})
  4. NOTE: If you wanted to use case in-sensitive (upper or lower case), you would use this expression:
    1. ([A-Za-z]{3})
  5. Down below under Actions, click “Change ranked results by changing the query”
  6. In the Query text box:
    1. it will say by default:
      1. {searchTerms}. 
    2. Just change that to be:
      1. {searchTerms}*
  7. Click Ok, then Save

That’s all we had to do.  What we’re saying is what when search detects a user searches for EMC or ABC or whatever, change the search query to be EMC* or ABC*. 

If you want extra credit, I’ll throw in a regex to match a regex to march the 3 letters and the 6 numbers.  This was useful when we wanted to raise the sites higher in results vs the documents.  The expression is:

([A-Za-z]{3}[0-9]{6})

This matches for 3 letters (case in-sensitive), and 6 numbers.  Happy Searching!  If you need help to configure and customize your search in Search, we’re here to help!

Search Posts

Categories

Recent Posts

Resources
Interested in how we can improve your customer and employee engagement?
Contact us for a free assessment ►

Powered by LUCK™