25

Search for a document

searchindex

GET https://bezillion.com/api/v1/searchindex?login=&password=

loginYour identification code.
passwordYour password.
qquery
fqfilter query
pagesizenumber of results per page
pagenumber 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.

Search

 q

 fq

 2 • 

2022-11-28 02:00 45 en fox.txt

The quick brown fox
jumps over
the lazy dog.

2022-11-28 02:00 30,9k en fox.jpg

The quick brown fox
jumps over
the lazy dog.

The quick brown fox
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}

sushi.png

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:

  1. require_once 'sendhttp.php';

Loads the code of the sendget function.

  1. 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.

  1.     $curl = 'https://bezillion.com/api/v1/searchindex';

Sets $curl to the URL of the searchindex action of the API.

  1.     $args = array(
  2.         'login'     => $login,
  3.         'password'  => $password,
  4.         'q'         => $q,
  5.         'fq'        => $fq,
  6.         'pagesize'  => $pagesize,
  7.         'page'      => $page,
  8.     );

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.

  1.     $response=sendget($curl, $args);

Sends the HTTP request with sendget.

  1.     if (!$response or $response[0] != 200) {
  2.         return false;
  3.     }

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.

  1.     $r=json_decode($response[2], true);

Decodes the data returned in JSON.

  1.     return $r['data'];
  2. }

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.