Search for a document
searchindex
GET https://bezillion.com/api/v1/searchindex?login=&password=
login | Your identification code. |
---|---|
password | Your password. |
q | query |
fq | filter query |
pagesize | number of results per page |
page | number of the page of results |
q
- query, *:*
by default.
fq
- query filter.
pagesize
- number of results to return per page between 10
and 100
, 10
by default.
page
- number of the page of results to return, 1
by default.
You can test this function in the interface of your personal space.
jumps over
the lazy dog.
Index the file:
$ curl -s --fail --show-error -X POST "https://bezillion.com/api/v1/indexfile?login=abcdef&password=ABCDEF" -F "file=@fox.txt" -o -
{"status":"success","data":null}
Search for the term fox:
$ curl -s --fail --show-error -X GET "https://bezillion.com/api/v1/searchindex?login=abcdef&password=ABCDEF&q=fox"
{"status":"success","data":{"count":1,"docs":[{"date":1669597200,"file":"fox.txt","size":45,"id":"12345678-9abc-def0-1234-56789abcdef0","lang":"en","from":"local","extra":"","stored":true,"score":0.45427877,"hl":["The quick brown fox\njumps over\nthe lazy dog.\n\n"]}]}}
NOTE: If a search returns nothing, the field data
is null
:
{"status":"success","data":null}
Index the file:
$ curl -s --fail --show-error -X POST "https://bezillion.com/api/v1/indexfile?login=abcdef&password=ABCDEF" -F "lang=eng+jpn+spa" -F "psm=6" -F "file=@sushi.png" -o -
Search for the term pollo:
$ curl -s --fail --show-error -X GET "https://bezillion.com/api/v1/searchindex?login=abcdef&password=ABCDEF&q=pollo"
{"status":"success","data":{"count":1,"docs":[{"date":1669597200,"file":"sushi.png","size":14394,"id":"12345678-9abc-def0-1234-56789abcdef0","lang":"en","from":"local","extra":"","stored":true,"score":0.5125473,"hl":["I eat \u3059\u3057 y Pollo\n\n"]}]}}
Search for the term polo:
$ curl -s --fail --show-error -X GET "https://bezillion.com/api/v1/searchindex?login=abcdef&password=ABCDEF&q=polo"
{"status":"fail","data":{"count":0,"suggest":["pollo"]}}
Search for the file sushi.*:
$ curl -s --fail --show-error -X GET "https://bezillion.com/api/v1/searchindex?login=abcdef&password=ABCDEF&fq=file:sushi.*"
{"status":"success","data":{"count":1,"docs":[{"date":1669597200,"file":"sushi.png","size":14394,"id":"12345678-9abc-def0-1234-56789abcdef0","lang":"en","from":"local","extra":"","stored":true,"score":1,"hl":false}]}}
Download the code of the sendget
function from the iZend library.
Copy the file in the space of your application.
NOTE: See the page Call the service API for a description of the sendget
function.
Add the file searchindex.php with the following content:
- require_once 'sendhttp.php';
Loads the code of the sendget
function.
- function searchindex($login, $password, $q=false, $fq=false, $pagesize=10, $page=1) {
Defines the function searchindex
.
$login
is your identification code. $password
is your password.
- $curl = 'https://bezillion.com/api/v1/searchindex';
Sets $curl
to the URL of the searchindex action of the API.
- $args = array(
- 'login' => $login,
- 'password' => $password,
- 'q' => $q,
- 'fq' => $fq,
- 'pagesize' => $pagesize,
- 'page' => $page,
- );
Prepares the list of arguments of the GET: the identification code and the password of the user's account, the query parameter, the filter query parameter, the page size and the page number.
- $response=sendget($curl, $args);
Sends the HTTP request with sendget
.
- if (!$response or $response[0] != 200) {
- return false;
- }
If $response
is false
, the server is unreachable.
If $response[0]
doesn't contain the HTTP return code 200 Ok, an execution error has occurred.
In case of error, searchindex
returns false.
- $r=json_decode($response[2], true);
Decodes the data returned in JSON.
- return $r['data'];
- }
Returns the result of the search if the action has succeeded.
EXAMPLE
Assuming you have saved the files sendhttp.php and searchindex.php in the current directory, run PHP in interactive mode, load the searchindex
function and call it with as arguments your identification code and password, a term to search in your index:
$ php -a
php > require_once 'searchindex.php';
php > $r=searchindex('abcdef', 'ABCDEF', 'pollo' );
php > $print_r($r);
Array
(
[count] => 1
[docs] => Array
(
[0] => Array
(
[file] => sushi.png
[size] => 14394
[extra] =>
[id] => 12345678-9abc-def0-1234-56789abcdef0
[date] => 1669597200
[from] => local
[lang] => en
[score] => 0.8451465
[stored] => 1
[hl] => Array
(
[0] => I eat すし y Pollo
)
)
)
)
php > $r=searchindex('abcdef', 'ABCDEF', 'polo' );
php > $print_r($r);
Array
(
[count] => 0
[suggest] => Array
(
[0] => pollo
)
)
php > $r=searchindex('abcdef', 'ABCDEF', false, 'file:sushi.*');
php > $print_r($r);
Array
(
[count] => 1
[docs] => Array
(
[0] => Array
(
[file] => sushi.png
[size] => 14394
[extra] =>
[id] => 12345678-9abc-def0-1234-56789abcdef0
[date] => 1669597200
[from] => local
[lang] => en
[score] => 1
[stored] => 1
[hl] =>
)
)
)
php > $r=searchindex('abcdef', 'ABCDEF', 'pollo', false, 2);
php > $print_r($r);
php >
php > quit
SEE ALSO
Call the service API, Index a document, Relate a document , Unindex a document
Comments
To add a comment, click here.