Skip to content

Commit 32acac4

Browse files
committed
adding code_with_match (#1024)
1 parent de92500 commit 32acac4

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

doc/search.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ $repos = $client->api('search')->repositories('github language:php');
1313
Returns a list of repositories found by such criteria.
1414

1515
### Search code
16-
16+
1717
```php
1818
$files = $client->api('search')->code('@todo language:php');
1919
```
2020

2121
Returns a list of files found by such criteria (containing "@todo" and language==php).
2222

23+
```php
24+
$files = $client->api('search')->code_with_match('@todo language:php');
25+
```
26+
27+
Same as code, with additional data to highlight the matching fragments (see [Text match metadata](https://docs.github.com/en/rest/reference/search#text-match-metadata)).
28+
2329
### Search issues
2430

2531
```php

lib/Github/Api/Search.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ public function code($q, $sort = 'updated', $order = 'desc')
6161
return $this->get('/search/code', ['q' => $q, 'sort' => $sort, 'order' => $order]);
6262
}
6363

64+
/**
65+
* Search code by filter (q), but will return additional data to highlight
66+
* the matched results.
67+
*
68+
* @link https://docs.github.com/en/rest/reference/search#text-match-metadata
69+
*
70+
* @param string $q the filter
71+
* @param string $sort the sort field
72+
* @param string $order asc/desc
73+
*
74+
* @return array list of code found
75+
*/
76+
public function code_with_match($q, $sort = 'updated', $order = 'desc')
77+
{
78+
$this->acceptHeaderValue = 'application/vnd.github.v3.text-match+json';
79+
return $this->code($q, $sort, $order);
80+
}
81+
6482
/**
6583
* Search users by filter (q).
6684
*

0 commit comments

Comments
 (0)