Skip to content

Commit

Permalink
wrote some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftkey committed Jul 18, 2015
1 parent cb41c58 commit d1bd50c
Showing 1 changed file with 84 additions and 15 deletions.
99 changes: 84 additions & 15 deletions docs/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,73 @@ on the GitHub or GitHub Enterprise server:
- code
- users

I won't go into the full details here as the [developer documentation](https://developer.github.com/)
covers all the options far better than I could.

## Search Issues

You can search for issues containing a given phrase across many repositories:
You can search for issues containing a given phrase across many
repositories:

```csharp
// a search
var request = new SearchIssuesRequest("linux");
// searching without specifying a term
var request = new SearchIssuesRequest();

// you should focus your search to a specific repo
request.Repos.Add("aspnet/dnx");

// it is highly recommended to search in specific repositories
// or use a series of repositories
request.Repos = new Collection<string> {
"aspnet/dnx",
"aspnet/dnvm"
};
```

// other parameters available for tweaking the output
request.SortField = IssueSearchSort.Created;
request.Order = SortDirection.Descending;
There's many other options available here to tweak
your search criteria:

```csharp
// if you're searching for a specific term, you can
// focus your search on specific criteria
request.In = new[] {
IssueInQualifier.Title,
IssueInQualifier.Body
};

// you can restrict your search to issues or pull requests
request.Type = IssueTypeQualifier.Issue;

// you can filter on when the issue was created or updated
var aWeekAgo = DateTime.Now.Subtract(TimeSpan.FromDays(7));
request.Created = new DateRange(aWeekAgo, SearchQualifierOperator.GreaterThan)

// you can search for issues created by, assigned to
// or mentioning a specific user
request.Author = "davidfowl";
request.Assignee = "damianedwards";
request.Mentions = "shiftkey";
request.Commenter = "haacked";

// rather than setting all these, you can use this to find
// all the above for a specific user with this one-liner
request.Involves = "davidfowl";

// by default this will search on open issues, set this if
// you want to get all issues
request.State = ItemState.All;
// or to just search closed issues
request.State = ItemState.Closed;
```

By default, search will return the first page of results and use
a page size of 100 results.
And there's other options available for how the results are returned:

```csharp
request.Page = 2;
request.SortField = IssueSearchSort.Created;
request.Order = SortDirection.Descending;

// 100 results per page as default
request.PerPage = 30;
```

// execute this when you want to fetch multiple pages
request.Page = 2;
```

Once you've set the right parameters, execute the request:

Expand All @@ -47,11 +84,43 @@ var repos = await client.Search.SearchIssues(request);

Console.WriteLine("Query has {0} matches.", repos.TotalCount);
Console.WriteLine("Response has {0} items.", repos.Items.Count);
Assert.NotEmpty();
```

## Search Pull Requests

Another scenario to consider is how to search broadly:

```csharp
var threeMonthsAgoIsh = DateTime.Now.Subtract(TimeSpan.FromDays(90));

// search for a specific term
var request = new SearchIssuesRequest("linux")
{
// only search pull requests
Type = IssueTypeQualifier.PR,

// search across open and closed PRs
State = ItemState.All,

// search repositories which contain code
// matching a given language
Language = Language.CSharp,

// focus on pull requests updated recently
Updated = new DateRange(threeMonthsAgoIsh, SearchQualifierOperator.GreaterThan)
};
```



## Search Repositories

**TODO**

## Search Code

**TODO**

## Search Users

**TODO**

0 comments on commit d1bd50c

Please sign in to comment.