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
.
login | Your identification code. |
---|---|
password | Your password. |
You can test this function in the interface of your personal space.
A search of proximity lists the documents similar to a document of reference and terms in common.
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
.
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:
- require_once 'sendhttp.php';
Loads the code of the sendget
function.
- 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.
- $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.
- $response=sendget($curl);
Sends the HTTP request with sendget
.
The arguments $id
, login
and password
are already in $curl
.
- 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, relatefile
returns false.
- $r=json_decode($response[2], true);
Decodes the data returned in JSON.
- if ($r['status'] == 'success') {
- return ($r['data']);
- }
Returns the result of the search if the action has succeeded.
- return false;
- }
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.