Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepping searching code doc #955

Merged
merged 2 commits into from
Nov 3, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion docs/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,61 @@ var request = new SearchRepositoriesRequest("mvc client side framework")

## Search Code

**TODO**
To search for code using Octokit you need to create a `SearchCodeRequest` and populate it with the search criteria.

```csharp
// Initialize a new instance of the SearchCodeRequest class with a search term
var request = new SearchCodeRequest("auth");

// Or we can restrict the search to a specific repo
var request = new SearchCodeRequest("auth", "dhh", "rails");

var result = await githubClient.Search.SearchCode(request);
```

Now we can further filter our search.

```csharp
var request = new SearchCodeRequest("auth")
{
// maybe we want to restrict the search to the file only
In = new[] { CodeInQualifier.File },

// or we can search the file and the path too
In = new[] { CodeInQualifier.File, CodeInQualifier.Path },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer code that would compile. This one will fail to compile because there is duplication of In

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I think we should keep this second line around instead of both

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// how about we find a file based on a certain language
Language = Language.JavaScript,

// do we want to search forks too?
Forks = true,

// find files that are above 1000 bytes
Size = Range.GreaterThan(1000),

// we may want to restrict the search to the path of a file
Path = "app/assets",

// we may want to restrict the file based on file extension
Extension = "json",

// restrict search to a specific file name
FileName = "app.json",

// search within a users or orgs repo
User = "dhh"
};
```

We can also sort our results by indexed or leave as null for best match.

```csharp
var request = new SearchCodeRequest("dhh")
{
// sort by last indexed
SortField = CodeSearchSort.Indexed
}
```

## Search Users

Expand Down