# search

This module provides a function for searching for issues in YouTrack.

## search

```JAVASCRIPT
static search(folder, query, user)
```

Returns issues that match a search query.

> **Note:**
> If the query does not specify a sort order, YouTrack returns the matching issues in random order.

For supported query operators and attributes, see [Search and Command Attributes](https://www.jetbrains.com.cn/en-us/help/youtrack/cloud/?Search-and-Command-Attributes).

Parameters

| Name | Type | Description |
| --- | --- | --- |
| folder |  [WatchFolder](v1-WatchFolder.html)  |    The project, tag, or saved search to set as the search context.     If omitted, the search includes all issues. This is equivalent to selecting Everything as the search context in the user interface.                       |
| query |  string, Object  |    A YouTrack search query.     When this parameter is an object, you can search by extension properties.                       |
| user |  [User](v1-User.html)  |    The user on whose behalf the query is executed.     The results exclude issues that this user does not have permission to view.     If omitted, the query is executed on behalf of the current user.                       |

Return Value

| Type | Description |
| --- | --- |
|  [Set](v1-Set.html).<[Issue](v1-Issue.html)>  |  The issues that match the query.                 |

## Working with Results

The function returns a [Set](v1-Set.html) of [Issue](v1-Issue.html) objects. Use [Set](v1-Set.html) methods to select or process the results:

* [first()](v1-Set.html#first) returns the first issue or `null` when the set is empty.

* [find()](v1-Set.html#find) returns the first issue that matches a predicate.

* [forEach()](v1-Set.html#forEach) processes every matching issue.

## Examples

Text query:

```JAVASCRIPT
const search = require('@jetbrains/youtrack-scripting-api/search');

const issues = search.search(
  ctx.issue.project,
  'for: me State: {In Progress}',
  ctx.currentUser
);
```

Extension properties:

```JAVASCRIPT
const search = require('@jetbrains/youtrack-scripting-api/search');

const query = {
  query: 'project: APP',
  extensionPropertiesQuery: {
    service: 'billing',
    region: 'eu'
  }
};

const issues = search.search(null, query, ctx.currentUser);
```

First result:

```JAVASCRIPT
const search = require('@jetbrains/youtrack-scripting-api/search');

const firstIssue = search.search(
  ctx.issue.project,
  'State: {In Progress}',
  ctx.currentUser
).first();

if (firstIssue) {
  // Process the first matching issue.
}
```

## See also

[Set](v1-Set.html) [Issue](v1-Issue.html) [WatchFolder](v1-WatchFolder.html)

