Welcome to my blog, stay tunned :
Home

Search

Search Engine not working fine in your App?

Hi,

I know that might sound stupid and it really is but I spent recently a few hours trying to figure out why the Search Engine wasn't working fine when queried from my App.
It turned-out that I forgot to ask the permission to use it. So, I was missing this line in my AppManifest.xml:





While this is very stupid, this little distraction made me realize that the system isn't behaving as expected. Indeed, one could expect that the App Model throws an exception such as "Attempt to perform an unauthorized operation" but it doesn't. It's actually even querying the Search Engine successfully but simply, no results are returned.
It is behaving as if it was applying some kind of security trimming but it's not because the App had full control over the site collection...Morality, just don't forget this line and you should avoid some headaches :).

Happy Coding!



Double quotes & single quotes when using the Search REST API of SharePoint 2013 combined with KQL from JavaScript

Hi,

Update 04/2013 download my demo App at http://sptoolbasket2013.codeplex.com/
I've been facing a quite strange issue when using the new search REST API of SharePoint 2013 and you might be facing the same kind of issue so as it took me a while to figure out the problem, I thought it was a good idea to share both the problem and the fix.
Double quotes
First, the problem! When trying to pass double-quotes into the querytext parameter. If you do not use the KQL syntax, you don't have any problem. So, if I transmit this:






/_api/search/query?querytext='test%22'


it's working fine.
If you're using the KQL to say for instance that you want to retrieve only items whose title equals "test". You can do it this way:

/_api/search/query?querytext='Title="test"'


Usually, you'll make sure to encode the full querytext parameter. However, with the KQL syntax, you can use parenthesis and if you repeat the same query than before with parenthesis:


/_api/search/query?querytext='(Title="test")' 
=> encoded value is :/_api/search/query?querytext='%28Title%3D%22item%201%22%29'


it will also work fine. Usually you'll use parenthesis if you want to apply priorities among multiple search criteria, however this is not a must since the above query works also fine but...strangely enough, if you add a double quote in the value, despites of the fact that this is encoded:


/_api/search/query?querytext='(Title="test " double quote")' 
=> encoded value is :::/_api/search/query?querytext='%28Title%3D%22test%20%22%20double%20quote%22%29'


You see that the value test " was encoded to test%20%22 so the double quote is escaped, at least from a web point of view, you will still receive the following error from the service:


Status:500Error:{"error":{"code":"-1, Microsoft.Office.Server.Search.REST.SearchServiceException","message":{"lang":"en-US","value":"We didn't understand your search terms. Make sure they're using proper syntax."}}}


and the reason of that are the parenthesis...If you get rid of them, you won't have that message anymore. So, make sure to use the parenthesis only if you need them...even with multiple search criteria. So, I don't know exactly why the parenthesis have this effect but for sure, they seem to have a weird impact.
Actually, the double quote character is meaningfull for the KQL engine so I think that encoding doesn't change anything and the character is still interpretated somehow by the KQL engine. I tried many different ways of escaping it with %22, \", \x22 in Javascript...and none of them is working.
If I have an item that has this value with " quotes and I try to search using the encoded form, I'll have no error without parenthesis but it won't return any result no matter how I'm encoding the ", I'll have the error described earlier with the parenthesis and it will just work fine with the right results if I replace " by nothing.
Single Quote
Here it's even worste, whatever you're trying to do, the server will crash with an error whether you're working with KQL or even with a basic search term...and the reason of this is because the ' character is enclosing the value of the querytext parameter and that's most probably why it goes mad. So, again, if I just remove the ' character from the search value, it's finding results correctly even when you make an exact match. So if you search for Title="test single quote", items whose the title is test ' single quote are returned...
So, not sure that removing both ' and " from the search terms is the right workaround but it seems to work and you'll probably avoid some headaches.
Note that these problems are only encountered when working with GET and _api/search/query, you won't run into them when using _api/search/postquery because there, you can just use JSON.stringify of the entire request and pass it as the data parameter and that will work like a charm.

Happy Coding!








SharePoint 2010 - Overcome the 10000 default search results limit

Hi,

I don't know if you ever noticed but by default since SharePoint 2010, search results are limited to 10000 results per query maximum.

I never noticed that before but for a project, we (me & another fellow SharePoint developer Jeroen Van Bastelaere) had to cache all the user profiles with a few properties in memory and make use of that cache for later use.

Unexpected People Search results - the right way to fix it!

Hi,

When performing search queries scoped to the People scope, you can sometimes end-up with no results although you know there are user profiles containing the keyword you typed.

This can be due to the following reasons:

1) You search on custom Profile Properties

When creating a custom profile property, if you want to be able to perform a search query on that property without being forced to create a corresponding Managed Property, you can just edit the ContentsHidden built-in managed property and add a mapping to your own custom profile property: