1 | <?php |
||
15 | class Search extends Api |
||
16 | { |
||
17 | use DiffbotAware; |
||
18 | |||
19 | /** @var string API URL to which to send the request */ |
||
20 | protected $apiUrl = 'https://api.diffbot.com/v3/search'; |
||
21 | |||
22 | /** @var string */ |
||
23 | protected $col = null; |
||
24 | |||
25 | /** @var string Search query to execute */ |
||
26 | protected $query = ''; |
||
27 | |||
28 | /** @var SearchInfo */ |
||
29 | protected $info; |
||
30 | |||
31 | const SEARCH_ALL = 'all'; |
||
32 | |||
33 | /** |
||
34 | * Search query. |
||
35 | * @see https://www.diffbot.com/dev/docs/search/#query |
||
36 | * @param string string $q |
||
37 | */ |
||
38 | 14 | public function __construct($q) |
|
42 | |||
43 | /** |
||
44 | * Name of the collection (Crawlbot or Bulk API job name) to search. |
||
45 | * By default the search will operate on all of your token's collections. |
||
46 | * |
||
47 | * @param null|string $col |
||
48 | * @return $this |
||
49 | */ |
||
50 | 5 | public function setCol($col = null) |
|
60 | |||
61 | /** |
||
62 | * Number of results to return. Default is 20. To return all results in |
||
63 | * the search, pass num=all. |
||
64 | * @param int $num |
||
65 | * @return $this |
||
66 | */ |
||
67 | 5 | public function setNum($num = 20) |
|
78 | |||
79 | /** |
||
80 | * Ordinal position of first result to return. (First position is 0.) |
||
81 | * Default is 0. |
||
82 | * @param int $start |
||
83 | * @return $this |
||
84 | */ |
||
85 | 5 | public function setStart($start = 0) |
|
96 | |||
97 | /** |
||
98 | * Builds out the URL string that gets requested once `call()` is called |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | 11 | public function buildUrl() |
|
120 | |||
121 | /** |
||
122 | * If you pass in `true`, you get back a SearchInfo object related to the |
||
123 | * last call. Keep in mind that passing in true before calling a default |
||
124 | * call() will implicitly call the call(), and then get the SearchInfo. |
||
125 | * |
||
126 | * So: |
||
127 | * |
||
128 | * $searchApi->call() // gets entities |
||
129 | * $searchApi->call(true) // gets SearchInfo about the executed query |
||
130 | * |
||
131 | * @todo: remove error avoidance when issue 12 is fixed: https://github.com/Swader/diffbot-php-client/issues/12 |
||
132 | * @param bool $info |
||
133 | * @return EntityIterator|SearchInfo |
||
134 | */ |
||
135 | 2 | public function call($info = false) |
|
158 | } |