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).