From 3f6297ae5aa2be28189b4eada5fdbf1bfbe5fb06 Mon Sep 17 00:00:00 2001 From: Haroon Date: Sat, 31 Oct 2015 22:08:49 +0000 Subject: [PATCH 1/2] Prepping searching code doc --- docs/search.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/docs/search.md b/docs/search.md index 6b6cd22a12..00686b75e6 100644 --- a/docs/search.md +++ b/docs/search.md @@ -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 }, + + // 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 From 538b33bba10bb7f2d1a0fa2d4d11cb1b9b50f9b8 Mon Sep 17 00:00:00 2001 From: Haroon Date: Tue, 3 Nov 2015 21:11:45 +0000 Subject: [PATCH 2/2] :lipstick: --- docs/search.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/search.md b/docs/search.md index 00686b75e6..a3536579ef 100644 --- a/docs/search.md +++ b/docs/search.md @@ -201,10 +201,7 @@ 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 + // we can restrict search to the file, path or search both In = new[] { CodeInQualifier.File, CodeInQualifier.Path }, // how about we find a file based on a certain language