3

I want to create a query rule and define a keyword.When a user uses that keyword in their query, no matter where it is, I want the query to find that keyword.

I know how to create a query rule that will pick up on the keyword if it is the very first word or last word in the query, but I want my keyword to be found when it is ANYWHERE in the query (if possible)!!!!!!!!!!

  • This one goes out to all my sharepoint gurus!!!!!!!!!!!!! Do we have an answer on this? And if there is no way to solve this issue, can I get an explanation as to why (i.e. why are is it that sharepoint will not recognize a term that is in the middle of two terms)? – osozoso Mar 29 '17 at 20:59
  • Let me know if this works for you! – Matthew McDermott Feb 13 '18 at 4:09
3
+50

I was able to solve this in SharePoint 2013 Enterprise with a Query Rule using Advanced Query Text Match. If my chosen keyword is Ruby create the following rule:

  1. Query Conditions - Advanced Query Text Match
  2. Query matches this regex: (.*?)(?i:\bruby\b)(.*?) (Note: if you want the keyword anywhere in any string omit the \b word boundary operator like this: (.*?)(?i:ruby)(.*?))

I am NOT a RegEx expert (not even close) so there are probably 100 different ways to write this. My understanding is this matches the case insensitive phrase "ruby" anywhere in the query with zero or more words before or after the keyword. The thing I learned is that since "Entire query matches exactly" is the default, your RegEx has to successfully match all combinations of the query. I tested this with the following combinations.

  • ruby
  • Ruby
  • RUBY
  • this is ruby
  • ruby is this
  • I love Ruby so very much
  • ruby charter project
  • charter ruby project
  • charter project ruby
  • ruby video charter project powerful
  • video ruby charter project powerful
  • video charter ruby project powerful
  • video charter project ruby powerful
  • video charter project powerful ruby

It did not hit:

  • charterruby project
  • charter rubyproject
  • charterrubyproject

For extra credit, just in case you wanted the option for multiple keywords I tested (.*?)(?i:\bruby\b|\bwilla\b)(.*?) and this matches on either "Ruby" or "Willa". Continue piping additional terms as needed.

For extra extra credit, just in case you wanted to capture the keyword you could use (.*?)(?<phrase>(?i:\bruby\b|\bwilla\b))(.*?) which SharePoint will recognize as a Capture Group and populate the variable {phrase} with the term (in this case "ruby" or "willa") for use in a Result Block. The Query Variables UI will change to indicate the presence of the capture group. Capture Group in Query Variable

Here is the RegEx: Sample RegEx

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.