Thursday, July 18, 2013

Limiting search results by exact time in SharePoint 2013–and how to do FQL

[Update 2020-01-27]
KQL in SharePoint Online and SharePoint 2019 now support time portion as well. For SP2016 and SP2013 you still need to use FQL to accomplish this.

[Original post]
Often you might find the need to limit search results between two dates, or even more exact, between two exact time intervals. The issue is that property queries written in KQL will disregard the time portion of your query, limiting to full day results only (See this old post for an explanation).

FAST Search for SharePoint allowed queries with the time portion in Sharepoint 2010 by using FQL, and fortunately you can do this in 2013 and Office 365 as well.

Doing FQL in 2013 in theory involves setting a parameter either on your REST queries or on the KeywordQuery object telling it your query is written in FQL and not KQL. The reality is a bit more complex involving a custom result source, and to tell you the truth. I have yet to be able to get FQL to work using REST this way.

How then? you might ask. Use use the RefinementFilters property instead! This property actually uses FQL which is what we need and is our “Get out of jail free card”. And all though KQL has more of the FQL operators in 2013, FQL still has some tricks up it's sleeve. Worth taking a look at for sure.

To limit on dates you will use the FQL range operator. The default behavior is to use “greater than” and “equal and less than” if not specified in the query.

The granularity of date/time queries are down to 7 decimals, as long as the crawler has been able to set this level of granularity during indexing.

Wednesday, July 17, 2013

How to copy files between sites using JavaScript REST in Office365 / SharePoint 2013

I’m currently playing with a POC for an App, and wanted to try to do the App as a SharePoint hosted one, only using JavaScript and REST.

The starting point was to call _vti_bin/ExcelRest.asmx on the host web from my app web, but this end-point does neither support CORS nor JSONP, so it can’t be used directly. My next thought was; Ok, let’s copy the file from the host web over to my app web, then call ExcelRest locally. Easier said than done!

While the final solution seems easy enough, the research, trial and error have taken me about 3 days. I’m now sharing this with you so you can spend your valuable time increasing the international GDP instead.

Note: If you want to copy files between two libraries on the same level, then you can use the copyTo method. http://server/site/_api/web/folders/GetByUrl('/site/srclib')/Files/getbyurl('madcow.xlsx')/copyTo(strNewUrl = '/site/targetlib/madcow.xlsx,bOverWrite = true)


Copy a file from a document library in one site to a document library in a different site using JavaScript and REST.

Friday, July 12, 2013

Enabling multi-select refiners in SharePoint 2013/Office365

I recently received a question about how to do multi-select refiners in SharePoint 2013 as comment on my post Limiting Search Results in SharePoint.

Fortunately this is very easy, which is was not in SharePoint 2010.

  1. On your search page, edit the Refinement web part
  2. Click the “Choose Refiners” button
  3. Select your refiner, eg. FileType
  4. Chose the “Multi-value Refinement Item” display template
  5. Click OK and Save the web part changes


Your Result type refiner will now look like the image below where you can check off each value you want to refine on.


You should note that when using this template it will in the case of file types show the extension and not the application names which is does with the “Refinement Item” display template. But that’s fixable if you edit your display templates :) and left as an option for you.

Wednesday, July 10, 2013

Working with refiners in CSOM–SharePoint 2013

Topics covered in this post:
  • CSOM Search Queries
  • Working with refiners in your queries
  • ModifiedBy and EditorOWSUSER managed properties
I’m playing around using CSOM search in an App these days and find that I am using a lot more time than usual writing my code. The reason is two-fold. One: no IntelliSense, and two: not that much documentation and samples out there.

Also the quirks of setting properties in JSOM takes some learning as you have to know if the property is a collection or not. Writing C"# code, spotting collections is much more intuitive.
I’ll be using Microsoft.SharePoint.Client.Search.Query.KeywordQuery for my samples.