8

Relate a document

relatefile

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

id is the unique identifier of a file in your index, e.g. 12345678-9abc-def0-1234-56789abcdef0.

loginYour identification code.
passwordYour password.

You can test this function in the interface of your personal space.

Search

 q

 fq

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

 1 • 

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

A search of proximity lists the documents similar to a document of reference and terms in common.

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}

Look for the file fox.txt:

$ curl -s --fail --show-error -X GET "https://bezillion.com/api/v1/searchfile?login=abcdef&password=ABCDEF&fq=file:fox.txt"
{"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":1,"hl":false}]}}

Note the identifier of the file returned in the field id: 12345678-9abc-def0-1234-56789abcdef0.

fox.jpg

Index the file:

$ curl -s --fail --show-error -X POST "https://bezillion.com/api/v1/indexfile?login=abcdef&password=ABCDEF" -F "lang=eng" -F "psm=6" -F "file=@fox.jpg" -o -
{"status":"success","data":null}

Look for the file fox.jpg:

$ curl -s --fail --show-error -X GET "https://bezillion.com/api/v1/searchindex?login=abcdef&password=ABCDEF&fq=file:fox.jpg"
{"status":"success","data":{"count":1,"docs":[{"date":1669597200,"file":"fox.jpg","size":30917,"id":"75efc8d3-5f88-4902-81eb-1c33dfa7a385","lang":"en","from":"local","extra":"","stored":true,"score":1}]}}

Look for the files similar to the file fox.txt:

$ curl -s --fail --show-error -X GET "https://bezillion.com/api/v1/relatefile/12345678-9abc-def0-1234-56789abcdef0?login=abcdef&password=ABCDEF"
{"status":"success","data":{"count":1,"docs":[{"id":"75efc8d3-5f88-4902-81eb-1c33dfa7a385","lang":"en","from":"local","score":1.1002516}]}}

NOTE: If a search returns nothing, the field data is null:

{"status":"success","data":null}

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 relatefile.php with the following content:

  1. require_once 'sendhttp.php';

Loads the code of the sendget function.

  1. function relatefile($login, $password, $id) {

Defines the function relatefile. $login is your identification code. $password is your password. $id is the unique identifier of a file in your index.

  1.     $curl = 'https://local.bezillion.com/api/v1/relatefile/' . $id . '?' . 'login=' . urlencode($login) . '&' . 'password=' . urlencode($password);

Sets $curl to the URL of the relatefile action of the API with the identifier of the file, the identification code and the password of the user's account. $login and $password must be escaped.

  1.     $response=sendget($curl);

Sends the HTTP request with sendget. The arguments $id, login and password are already in $curl.

  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, relatefile returns false.

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

Decodes the data returned in JSON.

  1.     if ($r['status'] == 'success') {
  2.         return ($r['data']);
  3.     }

Returns the result of the search if the action has succeeded.

  1.     return false;
  2. }

Returns false in case of error.

EXAMPLE

Assuming you have saved the files sendhttp.php and relatefile.php in the current directory, run PHP in interactive mode, load the relatefile function and call it with as arguments your identification code and password, the id of the file fox.txt in your index:

$ php -a
php > require_once 'relatefile.php';
php > $r=relatefile('abcdef', 'ABCDEF', '12345678-9abc-def0-1234-56789abcdef0');
php > $print_r($r);
Array
(
    [count] => 1
    [docs] => Array
        (
            [0] => Array
                (
                    [file] => fox.jpg
                    [size] => 30917
                    [extra] => 
                    [id] => 75efc8d3-5f88-4902-81eb-1c33dfa7a385
                    [date] => 1669597200
                    [from] => local
                    [lang] => en
                    [score] => 1.1002516
                )
        )
)
php > quit

NOTE: If relatefile returns false, edit the code to display $response.

SEE ALSO

Call the service API, Index a document, Search for a document , Unindex a document

Comments

To add a comment, click here.