Result search query for managed properties

Copper Contributor
Hi all,

I have build an search query for a search site with an refinement webpart.

Here is my query:

path:https://xxx.sharepoint.com/ {?Title:{searchboxquery}*} OR {?RefinableString1:{searchboxquery}*} OR {?RefinableString2:{searchboxquery}*} OR {?RefinableString3:{searchboxquery}*} ContentType:xxx

The problem is, i can't use a word for the title and a managed property. With the query I can now use multi words for the Title but u cant use two words together, 1 for the Title and one for the managed property.

So the question, is it possible to build an query so I can use multiple words for the title and managed properties.
12 Replies

@Mackdewack take a look at the articles by @Mikael Svenson on his blog https://www.techmikael.com/2019/ there are many tips and tricks which may provide you the answer.

@Mackdewack first off you might end up with loose OR's in that statement when searchboxquery is empty. What you are looking for is adding () around the variable as I blogged about at https://www.techmikael.com/2019/08/search-nugget-grouping-property.html

 

Also, adding a *, will only wildcard enable the last term you input. An remember that adding * to a term, will remove it from getting rank points. Only individual terms are ranked, so relevance might drop when using wildcards.

Thnx for the response! So you think it's possible to combine the managed properties? Tomorrow I can try the new query.
Yes, but you need to read up on KQL syntax a bit and how to best use the {?...} syntax :)

@Mikael Svenson i'm almost there, i hope :smile:

This is my input query: 

 

 

ContentType:xxx (Title:{searchboxquery}) OR (RefinableString1:{searchboxquery})

 

 

With the query i can search on titles and on the refinablestring1. When i start with the refinablestring after my results i can add extra words for the the title.  

 

 

ContentType:xxx (Title:Microsoft 777) OR (RefinableString31:Microsoft 777) -ContentClass=urn:content-class:SPSPeople

 

 

Refinablestring = Microsoft
Title 777

 

When i use Microsoft 777 i see my result but when i use 777 Microsoft i got no results, doenst make any sense to me. Is there an explanation for? 

You need to read better.

(RefinableString1:{searchboxquery}) should be RefinableString1:({searchboxquery})

Uhhh if i try it with the (), i can't combine the words together. Without the () i can combine it but i have to start with the string and then the title.

 

ContentType:xxx (Title:Microsoft 777) OR RefinableString31:Microsoft 777 -ContentClass=urn:content-class:SPSPeople
I think I understand now. You want to split the terms into being queried by different properties. Not doable without adding code to pick up and modify. If this is classic, it's doable/hackable, but in general no. And how do you know which terms should go where?

@Mikael Svenson Thanks for your time, here is a little more context. I have a site collection with around 10K documentsets. Every documentset have serval tags, these are text/choice/lookup column. 

 

With the query i would like that we can search for the refinablestring. For example i had a lookup column with serval suppliers like Google, Microsoft, etc. There is also an product choice column so i would like that we can search for Microsoft hardware. 

I doubt if this is possible with OOTB search features. What is your experience? Maybe i have to look to an SPFX webpart?

@Mackdewack remember that data isn columns are searchable by default, without using property queries. You can do OR queries as well if you want.

 

ContentType:xxx Title:ANY({searchboxquery}) OR RefinableString1:ANY({searchboxquery})

 If you searched for "test microsoft" you will get matches where title or refineablestring1 has one of these terms.

 

I have no idea what your end users will be querying, so hard to figure out the best solution.

@Mikael Svenson 

Are you sure, you can use ANY after the : ? If i look to my output query i got no results:

ContentType:xxx Title:ANY(microsoft) OR RefinableString1:ANY(microsoft) -ContentClass=urn:content-class:SPSPeople

About the end users. They need to search inside the side collection. The documents have serveral metadata tags so they would like to search for the metadata tags. The problems is, i can't now only search for the words in the title and one word from the metadata.  

 

I would love to use 2 of 3 words from the different metadata columsn so that i will find my results and here is the problem. I don't get my query right... At this moment, this is my best query now, i can use serveral words for the title + one word from a metadata column. When i use two words from two differents words i dont get any results. 

ContentType:xxx (Title:{searchboxquery}) OR (RefinableString1:{searchboxquery}) OR (RefinableString2:{searchboxquery}) OR (RefinableString3:{searchboxquery}) 



I will dig in your site and will try it! 

Sorry.. title:(ANY({searchboxquery}))
And you want () after the :. If not the first term in a multi term query is tied to the property, the subsequent ones are freetext.

And what if the query is:

-foo bar

Then you need () around it for it to parse correct. Making sure the KQL makes sense after you substitute the variable is not easy.