0

I try to search for a string like: 1001ˌtestcompanyˌtestcity with the SharePoint Online search query:

var url = encodeURI("/_api/search/query?querytext='" + this.searchstring + "'&selectproperties='ListID,Path,FileType,SiteName,Title,isDocument,SitePath,SPSoteUrl,SPWebUrl,WebUrl'");

Note that I use ˌ which is not equal to the normal ,.

I only want the search to return results that contain the exact string but I get any Document that Includes 1001, testcompany and testcity.

I already tried to put the string into (), [] or {} and also tried to put a \ in front of every special character but I always ended with the result described above or with no results.

How do I have to modify my string to get the results I want?

1 Answer 1

0

Try disabling stemming in your query by adding &enablestemming=false (see documentation).

Per default, SharePoint search will split your search terms based on whitespace characters etc. and will also try to search for word stems of those terms. Disabling that functionality for your query might yield better results for you.

In additional, you should encode your search string by using encodeURIComponent to take account for characters that are invalid for a URL.

var url = "/_api/search/query" + 
    "?querytext='" + encodeURIComponent(this.searchstring) + "'" + 
    "&selectproperties='ListID,Path,FileType,SiteName,Title,isDocument,SitePath,SPSoteUrl,SPWebUrl,WebUrl'" + 
    "&enablestemming=false";

Update:

You could also try enclosing the search term with an additional double quotation mark, which is encoded as %22 in URL components.

Encoding the search part of the URL like I proposed is typically the correct way to handle characters that are not allowed in URLs. Looking at your example of 1001ˌtestcompanyˌtestcity, the ˌ (secondary stress) gets encoded to %CB%8C, i.e. into two characters. You could try the following example with the additional quotation mark, but in the worst case, the ˌ was "normalized away" by the indexing component when the item was crawled by SharePoint.

var url = "/_api/search/query" + 
    "?querytext='%22" + encodeURIComponent(this.searchstring) + "%22'" + 
    "&selectproperties='ListID,Path,FileType,SiteName,Title,isDocument,SitePath,SPSoteUrl,SPWebUrl,WebUrl'" + 
    "&enablestemming=false";

To analyze the value that is actually stored in the search index, you could retrieve that specific item with a Path:<urlofitem> query as search query and analyze the property value (using browser or something like the Search Query Tool).

2
  • I tryed adding the "&enablestemming=false" but it didn't change the result. I also added the encodeURIComponent. After adding it I get zero results.
    – ElBiasto
    Commented Nov 20, 2019 at 15:45
  • 1
    Added an update to my answer. You will most likely have to dig deeper by analyzing how the value of the item is stored in the search index @ElBiasto
    – Anon
    Commented Nov 21, 2019 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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