Friday, September 26, 2014

How To: Query the Office Graph using CSOM

I’m in the process of adding GQL support to the SharePoint 2013 Search Query Tool together with Barry Waldbaum (Microsoft), and while writing the POST support I found it easier to test it using CSOM.

image

Below is sample code with inline comments if you want to go the CSOM route instead of using REST to query the Office graph. The key is to use the Properties property of the KeywordQuery object.

The benefit of using CSOM over REST in my opinion is that you can pass in more than one query per call, and thus optimize network traffic and wire chatter.

Friday, September 19, 2014

How to remove certain items from a list/library in SharePoint, and keep all other items

The scenario is as follows. You have indexed a SharePoint farm and one of your business owners tells you that in his library he keeps multiple copies of a file, where the latest is marked as ApprovalStatus=1 with a custom column. And only those files should be surfaced in the search results.

So, how do you craft search a query? At first you might write something like:

ApprovalStatus=1

This will exclude all items which don’t have that value as well, so not a good idea.

Next you know the list has a custom list definition so you try something like:

ApprovalStatus=1 AND ContentClass=STS_ListItem_10300

Now you’re excluding all other content except that list. Even worse, but still explicit to what you want. The solution is to add an OR clause to include all the other stuff you want, which is everything.

((ApprovalStatus=1 AND ContentClass=STS_ListItem_10300) OR (ContentClass<>STS_ListItem_10300))

And we have arrived at the final query. It will include anything not from the 10300 list definition + items from the 10300 definition which is approved.

Conclusion

When you want to exclude certain content, it’s much easier to generate a rule saying what you want to include. In this case one part specifying the exact rule for what to show for a particular library, and one part saying everything else except that library.

Other possible solutions

  • Content enrichment web service which excludes content from that library and which is not approved
  • Don’t keep multiple files, but use SP versioning
  • Move non-approved documents to a library which is not being indexed

Thursday, September 11, 2014

Sending in arbitrary extra query parameters to your SharePoint Search Center

I touched on this subject previously in my post Appending query terms in SharePoint 2013/O365 without adding them to the search box, but I did not have a solution at that time. Now I have.
Topics covered
  • Extend Search.ClientControls.js to support arbitrary FQL statements
  • Add appended search queries to your page without them showing in the search box
As mentioned in Limiting search results by exact time in SharePoint 2013–and how to do FQL you can pass extra query information beside the search text itself by using the refinement filter parameter of a query. This parameter takes FQL by default which is very handy at times. So, the refinement filter property is not just for adding refiners, but can be used to add any FQL statement of your choice, that being an extra query term or XRANK statement.

Let that sink in and think about the possibilities. The good guys at FAST actually handed over the master key to search, probably without knowing it!

image

Monday, September 8, 2014

S15E09: Query Rules – Trigger happy circumstances (context)

Want the book? Go get it!

This is episode nine in the series “SharePoint Search Queries Explained - The Series”. See the intro post for links to all episodes.

image
This is one of my favorite areas of search, but also one of the harder ones to get right. The overall concept is as follows:

For a specific group of users you change the search experience based on that group.

In the sample image above I show a promoted result for new employees who happen to like StarWars. It’s a very simple concept, but a really powerful one, and it’s up to you to decide what your query rule should do with your result – promoted results, change sort order, change what is displayed etc..

Thursday, September 4, 2014

Debug crawled properties and creating a refiner for Content Source without modifying the existing ContentSource managed property

imageThat was a really long post title, but it explains what this post is about, so just look past the dryness of it.

The first part of the post explains how you can see what crawled properties are available for an item, and the second part is how you can use one of the RefinableStringXX managed properties as a refiner for content source. (Content sources is what you set up in your Search Service Application which points at what sources you want to index)

Say you have set up multiple content sources in SharePoint. One for SharePoint, a couple for file servers and maybe a web crawl or three of some web sites. Let’s assume all these sources have a mental footprint in the mind of your information works, and as such you want to show a refiner on the search page based on these content sources.

Out of the box SharePoint 2013 have a managed property named ContentSource which stores the name of the content source, but this property is not refinable, only queryable.
image

Monday, September 1, 2014

Importing Search Configurations on the SSA

imageYou might have noticed the settings for site collections have options to export and import search configuration files, which is very nice indeed. The Search Service Application however, does not have these options. What is available is the use of CSOM to export the SSA configuration via the SearchConfigurationPortability class. If you try to import a configuration file to the SSA you will simply get a nice error, explained at the documentation page for SearchConfigurationPortability with this interesting quote: ….however, you cannot import customized search configuration settings to a Search service application (SSA).

 Note: This does not apply to SharePoint Online where you can import/export search configuration from the UI for your tenant.

So, you have export, but no import!