Wednesday, December 4, 2013

SharePoint 2013 Search REST API



SharePoint 2013 includes a Search REST service to add search functionality to your client and mobile applications by using any technology that supports REST web requests. You can use the Search REST service to submit Keyword Query Language (KQL) or FAST Query Language (FQL) queries in your apps for SharePoint, remote client applications, mobile applications, and other applications.

The Search REST service supports both HTTP POST and HTTP GET requests.

GET requests

Construct the URI for query GET requests to the Search REST service as follows:

/_api/search/query

For GET requests, you specify the query parameters in the URL. You can construct the GET request URL in two ways:
  • http://server/_api/search/query?query_parameter=value&query_parameter=value
  • http://server/_api/search/query(query_parameter=value&query_parameter=)
POST requests

You construct the URI for query POST requests to the Search REST service as follows:

/_api/search/postquery

For POST requests, you pass the query parameters in the request in JavaScript Object Notation (JSON) format.

The HTTP POST version of the Search REST service supports all parameters supported by the HTTP GET version. However, some of the parameters have different data types, as described in Table 1.

Table 1. Query parameters with different data types for POST requests

Parameter
Data type
string[]
string[]
​string[]

Use POST requests in the following scenarios:
  • When you'll exceed the URL length restriction with a GET request.
  • When you can't specify the query parameters in a simple URL. For example, if you have to pass parameter values that contain a complex type array, or comma-separated strings, you have more flexibility when constructing the POST request.
  • When you use the ReorderingRules parameter because it is supported only with POST requests.

Location of REST service
http://SERVER/site/_api/search
 
query
http://SERVER/site/_api/search/query
Supports HTTP Get and is used to retrieve search results.
postquery
http://SERVER/site/_api/search/postquery
Supports HTTP POST and is used to retrieve search results. This method can be used to overcome URI length restrictions when using the HTTP GET based method "query".
suggest
http://SERVER/site/_api/search/suggest
Supports HTTP GET and is used to retrieve query suggestions.
Query Parameters
Name
Description
Type
Default
querytext
The text of the search query.
String
Empty
http://SERVER/site/_api/search/query?querytext='Search_Value'
querytemplate
The query template text.
String
Empty
 
enableinterleaving
Specifies if the result sets which are generated by executing query rule actions to add result block should be mixed with the result set for the original query.
bool
True
http://SERVER/site/_api/search/query?querytext='Search_Value'&enableinterleaving=false
sourceid
Specifies the unique identifier of the Result Source to use for executing the search query.
String
Empty
http://SERVER/site/_api/search/query?querytext='Search_Value'&sourceid=‘GUID'
rankingmodelid
The GUID of the Rank Model to be used for this search query.
String
Empty
 
startrow
A zero-based index of the first search result to be returned.
Integer [ >= 0]
0
http://SERVER/site/_api/search/query?querytext='Search_Value'&startrow=11
rowlimit
The maximum number of search results to be returned, starting at the index specified in  startrow.
Integer [ >= 0]
10
http://SERVER/site/_api/search/query?querytext='Search_Value'&startrow=11&rowlimit=3
rowsperpage
The number of results to return per page.
Integer [ >= 0]
0
 
selectproperties
Specifies the list of managed properties to return for each search result item. For a managed property to be returned; the Retrievable flag must be set to "true" in the Search Schema.
String
Empty
http://SERVER/site/_api/search/query?querytext='Search_Value'&selectproperties='Path,Url,Title,Author'
culture
Specifies the identifier of the language culture of the search query. If present, the value must be a valid LCID of a culture name. A list of LCIDs is available at this location.
Integer
-1
http://SERVER/site/_api/search/query?querytext='Search_Value'&culture=1044
refiners
Specifies a list of refiners to return as a comma-separated list of strings.
String
Empty
http://SERVER/site/_api/search/query?querytext='Search_Value'&refiners='companies,contentclass,ContentType,FileExtension,FileType'
refinementfilters
The list of refinement tokens for drilldown into search results. Refinement tokens are returned as part of the RefinementResults table for the search query.
String
Empty
http://SERVER/site/_api/search/query?querytext='sharepoint'&refiners='filetype'&refinementfilters='filetype:equals("pptx")'
hiddenconstraints
Specifies additional query Search_Value that will be appended to the query.
String
Empty
http://SERVER/site/_api/search/query?querytext='Search_Value'&hiddenconstraints='word'
sortlist
Specifies the list of properties to sort the search results by.
String
Empty
http://SERVER/site/_api/search/query?querytext='Search_Value'&sortlist='rank:ascending'
enablestemming
Specifies whether stemming is enabled for the query.
bool
True
http://SERVER/site/_api/search/query?querytext='Search_Value'&enablestemming=false
trimduplicates
Specifies whether duplicate items should be removed from search results. This property can also
 be used to collapse hits in the result set.
bool
True
http://SERVER/site/_api/search/query?querytext='Search_Value'&trimduplicates=false
trimduplicatesincludeid
Specifies the value associated with a collapse group, typically used when a user clicks the duplicates link of an item with duplicates.
long
0L
http://SERVER/site/_api/search/query?querytext='Search_Value'&trimduplicates=true&trimduplicatesincludeid=47
timeout
Specifies the amount of time, in milliseconds, before the query request times out.
Integer
30000
http://SERVER/site/_api/search/query?querytext='Search_Value'&timeout=50000
enablenicknames
Specifies whether the exact Search_Value in the search query are used to find matches, or if nicknames
 are used as well.
bool
False
http://SERVER/site/_api/search/query?querytext='Search_Value'&enablenicknames=true
enablephonetic
Specifies whether the phonetic forms of the query Search_Value are used to find matches.
bool
False
http://SERVER/site/_api/search/query?querytext='Search_Value'&enablephonetic=true
enablefql
Specifies whether the query string is according to the FAST Query Language (FQL) syntax.
Bool
False
http://SERVER/site/_api/search/query?querytext='Search_Value'&enablefql=true
hithighlightedproperties
Specifies the list of properties to include in the HitHighlightedProperties for each result item.
String
Empty
http://SERVER/site/_api/search/query?querytext='Search_Value'&hithighlightedproperties='Title,Author'
bypassresulttypes
Specifies if the search result item type should be returned for the query results.
bool
False
 
processbestbets
Specifies if the search promoted results should be returned, if available, as a result set.
bool
True
 
clienttype
Name of a client which issued query.
String
Empty
 
personalizationdata
Gets or sets the unique identifier (GUID) for the current user who submitted the search query.
String
Empty
 
resultsurl
Specifies the URL for the page where the search results are going to be displayed.
String
Empty
 
querytag
Any custom tags to be used to identify the query. Multiple tags are separated by semicolons.
String
Empty
 
enablequeryrules
Specifies if Query Rules are turned on for this query.
bool
True
http://SERVER/site/_api/search/query?querytext='Search_Value'&enablequeryrules=false
enablesorting
Indicates whether results should be sorted.
bool
True
http://SERVER/site/_api/search/query?querytext='Search_Value'&enablesorting=false

Share:

10 comments: