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:
- Query Conditions - Advanced Query Text Match
- 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.
Here is the RegEx: Sample RegEx