Omicron Llama

Coding all day, every day.

SharePoint Search API Gotchas

I’ve been working with the SharePoint Search API lately to aggregate data across site collections, and came across a couple of gotchas that I’d thought I’d share.

CONTAINS keyword & searching for a phrase with a space

Let’s say you want to extract results that only exist in “Shared Documents”. You will need to construct your clause like this:

The point to note here is that inside the normal single quotes, you have to put your search phrase inside double quotes. When doing this in C#, you must remember to escape the double quotes with a backslash like how I’ve done.

Metadata Properties – DO A FULL CRAWL!

Another point was that I wanted to pull in columns which weren’t available in the SCOPE() – I was getting the following error trying to do the Query:

Property doesn’t exist or is used in a manner inconsistent with schema settings.

What I had to do was to go into the Shared Service Provider then Search administration and manually add in the Managed Properties, and map them to crawled fields. Luckily this is quite straightforward to do, just ensure that the fields you are mapping actually have the “Include values for this property in the search index” checkbox checked, otherwise the values will never be crawled. You can see if you have the right crawled property in the Edit window as it will show you examples of where the property is used – These will only show where the field actually has a value.

The main thing to remember here is when editing these mappings you must perform a FULL CRAWL of the database, an incremental crawl just won’t cut it.

Leave a Reply

Your email address will not be published. Required fields are marked *