Showing posts with label Search. Show all posts
Showing posts with label Search. Show all posts

Monday, 4 February 2013

Your Search Cannot Be Completed Because This Site Is Not Assigned To An Indexer

I had this very annoying error when trying to search my SharePoint Server 2010 single server development machine through code (using the KeywordQuery and FullTextSqlQuery classes).
The search crawler was running and searching from the SharePoint UI returned the expected results.

What you need to do is to...
  • Start the "SharePoint Foundation Search"service.
  • then go to the select "Manage Content Database Settings" page and select the server running the SahrePoint foundation search service at the drop down menu

Central Administration -> Application Management -> Manage services on server


Central Administration -> Application Management -> Manage Content Database -> (click on database name)



This was not intuitive to me as I was running SharePoint Server Enterpise. And the "SharePoint Server Search" service was already running. Also it strikes me as odd as you do not have the FullTextSqlQuery in SharePoint foundation - you need to have the Enterprise version.

Wednesday, 9 May 2012

SPQuery on a User field

Filtering on a user field in a SPQuery can be a bit tricky.

The following query would look at the displayname in the userfield on the list (not very practical):


<Where>
  <Eq><FieldRef Name="UserId" /><Value Type="User" >contoso\sp</Value></Eq>
</Where>


The userfield is actually a string like this "42#;contoso\sp"
You would then believe, that it was easy to filter on the loginname. However... If the displayname of the user is set, the string value og the userfield would then be "42;#Sune Popp".
The consistent thing is the user id. This id is unique within the site collection.

So... A better way (imho) is to query on the user lookup id. Your caml should then look like this:


<Where>
  <Eq><FieldRef Name="UserId" LookupId="TRUE"/><Value Type="User" >42</Value></Eq>
</Where>


Hint! As the user id is only unique within the site collection, you should use EnsureUser on the loginname, if your solution is spread across more site collections.