Skip to content

Commit 495c897

Browse files
Merge pull request SharePoint#5150 from andrewconnell/docfix-issue5146
Docfix update - update broken links
2 parents 60410d9 + bee18fd commit 495c897

File tree

1 file changed

+41
-120
lines changed

1 file changed

+41
-120
lines changed
Lines changed: 41 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,110 @@
11
---
22
title: Using the SharePoint search Query APIs
3-
ms.date: 09/25/2017
3+
ms.date: 01/16/2020
44
ms.prod: sharepoint
55
ms.assetid: ae9d73ed-1140-430b-9287-01dbbe8ae7d1
66
localization_priority: Priority
77
---
88

9+
# Using the SharePoint search Query APIs
910

11+
Learn about the query APIs available in SharePoint that enable you to add search functionality to custom solutions and applications.
1012

11-
# Using the SharePoint search Query APIs
12-
Learn about the query APIs available in SharePoint that enable you to add search functionality to custom solutions and applications.
1313
## SharePoint Query APIs
14-
<a name="bk_QueryAPIs"> </a>
1514

1615
Search in SharePoint provides several query APIs, giving you lots of ways to access search results, so that you can return search results in a variety of custom solution types.
17-
18-
19-
16+
2017
In addition to the server object model that was available in previous versions of SharePoint, Search in SharePoint also provides the following:
21-
22-
23-
2418

2519
- Client object model (CSOM)
26-
27-
2820
- JavaScript object model (JSOM)
29-
30-
3121
- Representational State Transfer (REST) service
32-
33-
22+
3423
Table 1 shows the APIs that you can use to program search queries and the path to the source file on the server.
35-
36-
37-
3824

3925
**Table 1. Search APIs**
4026

41-
4227
|**API name**|**Class library or schema and path**|
4328
|:-----|:-----|
4429
|.NET CSOM <br/> |Microsoft.SharePoint.Client.Search.dll <br/>%ProgramFiles%\\Common Files\\Microsoft Shared\\web server extensions\\15\\ISAPI <br/> |
4530
|Silverlight CSOM <br/> |Microsoft.SharePoint.Client.Search.Silverlight.dll <br/>%ProgramFiles%\\Common Files\\Microsoft Shared\\web server extensions\\15\\TEMPLATE\\LAYOUTS\\ClientBin <br/> |
4631
|JavaScript CSOM <br/> |SP.search.js <br/>%ProgramFiles%\\Common Files\\Microsoft Shared\\web server extensions\\15\\TEMPLATE\\LAYOUTS <br/> |
47-
|REST service endpoints <br/> |http://server/_api/search/query <br/>http://server/_api/search/suggest <br/> |
32+
|REST service endpoints <br/> |https://{site_url}/_api/search/query <br/>https://{site_url}/_api/search/suggest <br/> |
4833
|Server object model <br/> |Microsoft.Office.Server.Search.dll <br/>%ProgramFiles%\\Common Files\\Microsoft Shared\\web server extensions\\15\\ISAPI <br/> |
49-
34+
5035
As a best practice in SharePoint development, use client APIs when you can. Client APIs include the .NET, Silverlight, Phone, and JavaScript client object models, and the REST service. For more information about the APIs in SharePoint and when to use them, see [Choose the right API set in SharePoint](choose-the-right-api-set-in-sharepoint.md).
51-
52-
53-
5436

5537
### Query using the .NET client object model
56-
<a name="bk_QueryNETcsom"> </a>
5738

5839
Search in SharePoint includes a client object model that enables access to search results for online, on-premises, and mobile development. The Search in SharePoint CSOM is built on the SharePoint CSOM. Therefore, your client code first needs to access the SharePoint CSOM and then access the Search in SharePoint CSOM. For more information about the SharePoint CSOM and the [ClientContext](https://msdn.microsoft.com/library/Microsoft.SharePoint.Client.ClientContext.aspx) class, which is the entry point to the CSOM, see [SharePoint Complete Basic Operations Using SharePoint Client Library Code](https://docs.microsoft.com/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code).
59-
60-
61-
62-
For the .NET managed CSOM, get a **ClientContext** instance (located in the [Microsoft.SharePoint.Client](https://msdn.microsoft.com/library/Microsoft.SharePoint.Client.aspx) namespace in the Microsoft.SharePoint.Client.dll). Then use the object model in the **Microsoft.SharePoint.Client.Search.Query** namespace in the Microsoft.SharePoint.Client.Search.dll.
63-
64-
65-
66-
Here's a basic example.
67-
68-
69-
7040

41+
For the .NET managed CSOM, get a **ClientContext** instance (located in the [Microsoft.SharePoint.Client](https://msdn.microsoft.com/library/Microsoft.SharePoint.Client.aspx) namespace in the Microsoft.SharePoint.Client.dll). Then use the object model in the **Microsoft.SharePoint.Client.Search.Query** namespace in the Microsoft.SharePoint.Client.Search.dll.
7142

43+
Here's a basic example.
7244

7345
```cs
74-
7546
using (ClientContext clientContext = new ClientContext("http://<serverName>/sites/<siteCollectionPath>"))
7647
{
77-
KeywordQuery keywordQuery = new KeywordQuery(clientContext);
78-
keywordQuery.QueryText = "SharePoint";
79-
SearchExecutor searchExecutor = new SearchExecutor(clientContext);
80-
ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
81-
clientContext.ExecuteQuery();
48+
KeywordQuery keywordQuery = new KeywordQuery(clientContext);
49+
keywordQuery.QueryText = "SharePoint";
50+
SearchExecutor searchExecutor = new SearchExecutor(clientContext);
51+
ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
52+
clientContext.ExecuteQuery();
8253
}
8354
```
8455

85-
To download an example, see the following code sample posted by SharePoint MVP [Corey Roth](https://mvp.microsoft.com/mvp/Corey%20Roth-4029260): [SharePoint: Query Search with the Managed Client Object Model](https://code.msdn.microsoft.com/Query-Search-with-the-649f1bc1).
86-
87-
88-
56+
To download an example, see the following code sample posted by SharePoint MVP [Corey Roth](http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2012/09/10/how-to-query-search-with-the-sharepoint-2013-client-object-model.aspx): [SharePoint: Query Search with the Managed Client Object Model](https://github.com/microsoftarchive/msdn-code-gallery-community-s-z/tree/master/SharePoint%202013%20Query%20Search%20with%20the%20Managed%20Client%20Object%20Model).
8957

9058
### Query using the JavaScript client object model
91-
<a name="bk_QueryJSOM"> </a>
9259

9360
For the JavaScript CSOM, get a [ClientContext](https://msdn.microsoft.com/library/Microsoft.SharePoint.Client.ClientContext.aspx) instance, and then use the object model in the SP.Search.js file.
94-
95-
96-
97-
Here's a basic example.
98-
99-
100-
10161

62+
Here's a basic example.
10263

103-
104-
```
105-
64+
```cs
10665
var clientContext = new SP.ClientContext("<serverRelativeUrl>");
10766
var contextSite = clientContext.get_site();
108-
var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(clientContext);
109-
keywordQuery.set_queryText("SharePoint");
110-
var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(clientContext);
111-
var results = searchExecutor.executeQuery(keywordQuery);
67+
var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(clientContext);
68+
keywordQuery.set_queryText("SharePoint");
69+
var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(clientContext);
70+
var results = searchExecutor.executeQuery(keywordQuery);
11271
context.executeQueryAsync(onQuerySuccess, onQueryError);
11372
```
11473

115-
To download an example, see the following code sample posted by SharePoint MVP [Corey Roth](https://mvp.microsoft.com/mvp/Corey%20Roth-4029260): [SharePoint: Querying Search with the JavaScript Client Object Model](https://code.msdn.microsoft.com/SharePoint-2013-Querying-a629b53b).
116-
117-
118-
74+
To download an example, see the following code sample posted by SharePoint MVP [Corey Roth](http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2012/09/10/how-to-query-search-with-the-sharepoint-2013-client-object-model.aspx): [SharePoint: Query Search with the Managed Client Object Model](https://github.com/microsoftarchive/msdn-code-gallery-community-s-z/tree/master/SharePoint%202013%20Query%20Search%20with%20the%20Managed%20Client%20Object%20Model).
11975

12076
### Query using the REST service
121-
<a name="bk_QueryREST"> </a>
12277

12378
SharePoint includes a REST service that enables you to remotely execute queries against the SharePoint Search service from client applications by using any technology that supports REST web requests. The Search REST service exposes two endpoints, **query** and **suggest**, and will support both **GET** and **POST** operations. Results are returned in either XML or JavaScript Object Notation (JSON) format.
124-
125-
126-
127-
The following is the access point for the service: `http://server/_api/search/`. You can also specify the site in the URL, as follows: `http://server/site/_api/search/`. The search service returns results from the entire site collection, so the same results are returned for both ways to access the service.
128-
129-
130-
131-
See [SharePoint Search REST API overview](sharepoint-search-rest-api-overview.md) and [Retrieving query suggestions using the Search REST service](retrieving-query-suggestions-using-the-search-rest-service.md) for more information.
132-
133-
134-
79+
80+
The following is the access point for the service: `https://{site_url}/_api/search/`. You can also specify the site in the URL, as follows: `https://{site_url}/site/_api/search/`. The search service returns results from the entire site collection, so the same results are returned for both ways to access the service.
81+
82+
See [SharePoint Search REST API overview](sharepoint-search-rest-api-overview.md) and [Retrieving query suggestions using the Search REST service](retrieving-query-suggestions-using-the-search-rest-service.md) for more information.
13583

13684
### Query using the .NET server object model
137-
<a name="bk_QuerySOM"> </a>
138-
139-
Applications that use the server object model must run directly on a server that is running SharePoint. The search Query server object model resides in the [Microsoft.Office.Server.Search.Query](https://msdn.microsoft.com/library/Microsoft.Office.Server.Search.Query.aspx) namespace, which is located in Microsoft.Office.Server.Search.dll.
140-
141-
142-
143-
As in SharePoint Server 2010, you use the **KeywordQuery** class to define the query, and then called the [Execute()](https://msdn.microsoft.com/library/Microsoft.Office.Server.Search.Query.Query.Execute.aspx) method to submit the query. In SharePoint, the **Execute** method is obsolete, and while it will still work, you should use the [SearchExecutor](https://msdn.microsoft.com/library/Microsoft.Office.Server.Search.Query.SearchExecutor.aspx) class instead. To submit the query, call the [ExecuteQuery()](https://msdn.microsoft.com/library/Microsoft.Office.Server.Search.Query.SearchExecutor.ExecuteQuery.aspx) method, passing the instance of the **KeywordQuery** class in the call.
144-
145-
146-
147-
Here's a basic example.
148-
149-
150-
15185

86+
Applications that use the server object model must run directly on a server that is running SharePoint. The search Query server object model resides in the [Microsoft.Office.Server.Search.Query](/previous-versions/office/sharepoint-server/ms559899(v=office.15)) namespace, which is located in Microsoft.Office.Server.Search.dll.
15287

88+
As in SharePoint Server 2010, you use the **KeywordQuery** class to define the query, and then called the [Execute()](/previous-versions/office/sharepoint-server/ms562867(v=office.15)) method to submit the query. In SharePoint, the **Execute** method is obsolete, and while it will still work, you should use the [SearchExecutor](/previous-versions/office/sharepoint-server/jj277656(v=office.15)) class instead. To submit the query, call the [ExecuteQuery()](/previous-versions/office/sharepoint-server/jj517659(v=office.15)) method, passing the instance of the **KeywordQuery** class in the call.
15389

154-
```cs
90+
Here's a basic example.
15591

92+
```cs
15693
using (SPSite siteCollection = new SPSite("<serverRelativeUrl>"))
15794
{
158-
KeywordQuery keywordQuery = new KeywordQuery(siteCollection);
159-
keywordQuery.QueryText = "SharePoint";
160-
SearchExecutor searchExecutor = new SearchExecutor();
161-
ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
162-
resultTableCollection = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
163-
ResultTable resultTable = resultTableCollection.FirstOrDefault();
164-
DataTable dataTable = resultTable.Table;
95+
KeywordQuery keywordQuery = new KeywordQuery(siteCollection);
96+
keywordQuery.QueryText = "SharePoint";
97+
SearchExecutor searchExecutor = new SearchExecutor();
98+
ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
99+
resultTableCollection = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
100+
ResultTable resultTable = resultTableCollection.FirstOrDefault();
101+
DataTable dataTable = resultTable.Table;
165102
}
166103
```
167104

168-
To download an example, see the following code sample posted by SharePoint MVP [Corey Roth](https://mvp.microsoft.com/mvp/Corey%20Roth-4029260): [SharePoint: Query Search with the KeywordQuery Class](https://code.msdn.microsoft.com/Query-Search-with-the-372139b5).
169-
170-
171-
105+
To download an example, see the following code sample posted by SharePoint MVP [Corey Roth](http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2012/09/10/how-to-query-search-with-the-sharepoint-2013-client-object-model.aspx): [SharePoint: Query Search with the Managed Client Object Model](https://github.com/microsoftarchive/msdn-code-gallery-community-s-z/tree/master/SharePoint%202013%20Query%20Search%20with%20the%20Managed%20Client%20Object%20Model).
172106

173107
## See also
174-
<a name="bk_addresources"> </a>
175-
176-
177-
- [Building search queries in SharePoint](building-search-queries-in-sharepoint.md)
178-
179-
180-
- [SharePoint Search REST API overview](sharepoint-search-rest-api-overview.md)
181-
182-
183-
- [SharePoint: Using the search REST service from an app for SharePoint](https://code.msdn.microsoft.com/sharepoint/SharePoint-2013-Perform-a-1bf3e87d)
184-
185-
186-
187-
188-
189-
108+
109+
- [Building search queries in SharePoint](building-search-queries-in-sharepoint.md)
110+
- [SharePoint Search REST API overview](sharepoint-search-rest-api-overview.md)

0 commit comments

Comments
 (0)