Code Monkey home page Code Monkey logo

php-doofinder's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-doofinder's Issues

Let the client library exceptions be easily classified

Currently, the php exception that is thrown when the query limit is reached is:

throw new DoofinderException("Requests Limit Reached");

if an user wants to know what to do when the request limit is reached, she has to parse the exception message . It would be easier if:

  • there's a specific exception for that case or
  • the generic exception has some code

implement "wait" option for deleteType operation

  • in the constructor specify a "maximum waiting time" or the like

  • in the dleteType method, add a boolean argument to indicate the method to wait untill the search engine is no longer busy indexing anything.

Division by zero error

Hey Folks,

We have a frequent error when using your search client.

What we are doing:

$searchParams = [
    'hashid'    => $this->engine,
    'indices'   => [$this->index],
    'query'     => $searchKeyword,
    'rpp'       => 100
];
$dfClient->search($searchParams);

The searchKeyword is a sanitized user input.

The error in Search/Client, Line 177:
$this->_lastPage = ceil($total / $rpp); // Division by zero error

It looks like your client does not want to handle zero results when querying your API.
Furthermore, I'm confused why your documentation said we can give a rpp, but it's immediately overwritten here.

Any ideas how to handle that? :)
Here's a link to our issue in sentry.io:
Isses's link

Best,
Bent

Make all client exceptions extends from a DoofinderException

Right now all exceptions from the Utils::handleErrors method returns exceptions that extends \Exception; would it be possible to ensure that all those exceptions extends a generic exception, say DoofinderException ?

That would allow us to ensure that we properly catch everything that may fail when we call the API though the SDK.

Deprecated function breaks functionality with guzzlehttp/psr7:2.0

The Management API uses deprecated functions, which can break functionallity, since "guzzlehttp/guzzle": "~7.3" requires "guzzlehttp/psr7": "^1.7 || ^2.0":

$httpBody = \GuzzleHttp\Psr7\build_query($formParams);

https://github.com/guzzle/psr7/blob/1.7.0/src/functions.php#L318

  • @deprecated build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead.

$httpBody = \GuzzleHttp\json_encode($httpBody);

https://github.com/guzzle/guzzle/blob/7.3.0/src/functions.php#L164

  • @deprecated json_encode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonEncode instead.

( ! ) Fatal error: Uncaught Error: Call to undefined function GuzzleHttp\Psr7\build_query() in /application/plugins/doofinder/vendor/doofinder/doofinder/src/Management/PhpClient/Api/SearchEnginesApi.php on line 1651
( ! ) Error: Call to undefined function GuzzleHttp\Psr7\build_query() in /application/plugins/doofinder/vendor/doofinder/doofinder/src/Management/PhpClient/Api/SearchEnginesApi.php on line 1651
Call Stack
#TimeMemoryFunctionLocation
513.062811057240Doofinder\Management\ManagementClient->getSearchEngine( $hashid = 'xxx' ).../SearchengineController.php:54
613.062811057240DoofinderManagement\Api\SearchEnginesApi->searchEngineShow( $hashid = 'xxx' ).../ManagementClient.php:141
713.062811057240DoofinderManagement\Api\SearchEnginesApi->searchEngineShowWithHttpInfo( $hashid = 'xxx' ).../SearchEnginesApi.php:1401
813.062811057240DoofinderManagement\Api\SearchEnginesApi->searchEngineShowRequest( $hashid = 'xxx' ).../SearchEnginesApi.php:1419

managementApiCall -> /logs: empty response not decoded

If there is no log entry the logs() funktion returns a tring: "[]"

https://github.com/doofinder/php-doofinder/blob/master/src/Management/SearchEngine.php#L302:

  public function logs() {
    $result = $this->client->managementApiCall("GET", "{$this->hashid}/logs");
    return $result['response'];
  }

from https://github.com/doofinder/php-doofinder/blob/master/src/Management/Client.php#L97:

$contentResponse = "[]";
$decoded = ($decoded = json_decode($contentResponse,true)) ? $decoded : $contentResponse;
var_dump($decoded);

$contentResponse = '[{"date":"2019-04-25T08:08:11.694963Z","level":"INFO","msg":"All \"product\" feeds were processed successfully. Items: 68 (87 Kb)"}]';
$decoded = ($decoded = json_decode($contentResponse, true)) ? $decoded : $contentResponse;
var_dump($decoded);

Result:

string(2) "[]"  // sould be array(0)

array(1) {
  [0]=>
  array(3) {
    ["date"]=>
    string(27) "2019-04-25T08:08:11.694963Z"
    ["level"]=>
    string(4) "INFO"
    ["msg"]=>
    string(66) "All "product" feeds were processed successfully. Items: 68 (87 Kb)"
  }
}

Better results from multiple indices with one request

I have an engine with 2 indices: product and category

I need to get fixed number of products and categories, in my case 32 products and 32 categories.

Although, the current Doofinder API supports search in multiple indices, it returns variable amount of prods/cats. For example it returns 30 products and 2 categories.

Right now I have to make 2 search requests: one for products, and one for categories which is redundant and slows down the whole process.

Sort fields

There is no sort method while the API has it. What would be te best way to add sort option?

make sure http_build_query uses "&" as parameter separator

$res = http_build_query(array("pepe"=>"kiko", "culo"=>"pis")); // "?pepe=kiko&culo=pis"

but it turns out that the separator character can be changed. some servers have set that to "&" (only God knows why),
it also can be explicitly forced. That's the way to go.

Error Class Exception : The second parameter cannot be a string.

Hello,

There is a small typo in the code, during a RequestException.
HttpClient.php : line 41.

if (($response = curl_exec($s)) === false) { $error = curl_error($s); curl_close($s); throw new RequestException('curl_error', $error); }
=>
if (($response = curl_exec($s)) === false) { $error = curl_error($s); curl_close($s); throw new RequestException($error); }

image

Thank you

Sorting not working as expected???

README.md says this works:

dfParam_sort = array(
  array('price' => 'desc'),
  array('title', 'asc')
);

But I'm doing this:

$query = $searchClient->query(
  'vin',
  null,
  array(
    'rpp' => 100,
    'transformer' => 'onlyid',
    'sort' => array(
      array('best_price', 'desc'),
    ),
  )
);

And I'm getting:

Fatal error: Uncaught Doofinder\Api\Search\Error: 400

If I execute this instead:

$query = $searchClient->query(
  'vin',
  null,
  array(
    'rpp' => 100,
    'transformer' => 'onlyid',
    'sort' => array(
      array('best_price' =>'desc'),
    ),
  )
);

everything works as expected.

Retrieve all products from a query

Hello everyone,

I wanted to know if it's possible to have all products from a query ?
Because if I take the results from $client->query(), I only have the number of products per page.

many thanks.

EDIT: use getProperty method :)

; missing in example

In your example there is a missing ; at the end of
define('API_KEY', 'eu1-384fdag73c7ff0a59g589xf9f4083bxb9727f9c3')

Wrong response when you delete a datatype and re-create it

During the catalogsearch_fulltext reindex following API calls are performed:

DELETE https://eu1-api.doofinder.com/v1/{hashid}/types/{datatype}
POST https://eu1-api.doofinder.com/v1/{hashid}/types

The second request fails with an unhandled error "Bad request", it should be some named error which can be catched, not a "Bad request", like: "IndexingInProgress" or "ThrottledResponse".

Preconditions:

  • sample data must be installed and indexed

(1) Error parsing bulk response with errors

When you do a updateBulkItem operation with a missing item, the response contains an error but the library parse as good result:

This is the response returned by api server:

{"errors":true,"results":[{"error":"document_missing_exception","id":"1","result":"[product_test][4f140023c50e00001a9020235ff7b4ab@product_test@c4ca4238a0b923820dcc509a6f75849b]: document missing"}]}

And this the error returned by the php library:

PHP Fatal error:  Uncaught InvalidArgumentException: Invalid value for 'result', must be one of 'created', 'updated', 'deleted' in /home/antonio/Projects/php-doofinder/src/Management/PhpClient/Model/BulkResultResults.php:304
Stack trace:
#0 /home/antonio/Projects/php-doofinder/src/Management/PhpClient/ObjectSerializer.php(313): DoofinderManagement\Model\BulkResultResults->setResult()
#1 /home/antonio/Projects/php-doofinder/src/Management/PhpClient/ObjectSerializer.php(246): DoofinderManagement\ObjectSerializer::deserialize()
#2 /home/antonio/Projects/php-doofinder/src/Management/PhpClient/ObjectSerializer.php(313): DoofinderManagement\ObjectSerializer::deserialize()
#3 /home/antonio/Projects/php-doofinder/src/Management/PhpClient/Api/ItemsApi.php(4728): DoofinderManagement\ObjectSerializer::deserialize()
#4 /home/antonio/Projects/php-doofinder/src/Management/PhpClient/Api/ItemsApi.php(4667): DoofinderManagement\Api\ItemsApi->itemsTempBulkUpdateWithHttpInfo()
#5 /home/antonio/Projects/php-doofinder/src/Management/ManagementClient.php(709): DoofinderManagement\Api\ItemsApi->itemsTempBulkUpdate()
#6 /home/antonio/Projects/php-doofinder/test.php(35): Doofinder\Management\ManagementClient->updateTempBulk()
#7 {main}
  thrown in /home/antonio/Projects/php-doofinder/src/Management/PhpClient/Model/BulkResultResults.php on line 304

Implement facet sort indicator

Hy doofinder Team,

is it possible to get the facet sort indicator, when using the Search API?

For example like this:

"facets": {
    "size": {
      "sort": 1,    //_<=_sort_indicator
      "total": {
        "value": 41
      },
      "terms": {
        "sum_other_doc_count": 0,
        "doc_count_error_upper_bound": 0,
        "buckets": [
          ...
        ]
      },
      "doc_count": 76
    },
    "price": {
      "sort": 4,
      "range": {
        "buckets": [
          {
            "stats": {
              "sum": 10068.670000076294,
              "min": 10.0,
              "max": 765.0,
              "count": 76,
              "avg": 132.48250000100387
            },
            "key": "0.0-*",
            "from": 0.0,
            "doc_count": 76
          }
        ]
      },
      "doc_count": 76
    },
    "plattform": {
      "sort": 7,
      "total": {
        "value": 0
      },
      "terms": {
        "sum_other_doc_count": 0,
        "doc_count_error_upper_bound": 0,
        "buckets": []
      },
      "doc_count": 76
    },
    "material": {
      "sort": 6,
      "total": {
        "value": 0
      },
      "terms": {
        "sum_other_doc_count": 0,
        "doc_count_error_upper_bound": 0,
        "buckets": []
      },
      "doc_count": 76
    },
    "genre": {
      "sort": 8,
      "total": {
        "value": 0
      },
      "terms": {
        "sum_other_doc_count": 0,
        "doc_count_error_upper_bound": 0,
        "buckets": []
      },
      "doc_count": 76
    },
    "g:availability_label": {
      "sort": 3,
      "total": {
        "value": 76
      },
      "terms": {
        "sum_other_doc_count": 0,
        "doc_count_error_upper_bound": 0,
        "buckets": [
         ...
        ]
      },
      "doc_count": 76
    },
    "color": {
      "sort": 2,
      "total": {
        "value": 26
      },
      "terms": {
        "sum_other_doc_count": 8,
        "doc_count_error_upper_bound": 0,
        "buckets": [
          ...
        ]
      },
      "doc_count": 76
    },
    "categories": {
      "sort": 0,
      "total": {
        "value": 77
      },
      "terms": {
        "sum_other_doc_count": 6,
        "doc_count_error_upper_bound": 0,
        "buckets": [
         ...
        ]
      },
      "doc_count": 76
    },
    "brand": {
      "sort": 5,
      "total": {
        "value": 74
      },
      "terms": {
        "sum_other_doc_count": 19,
        "doc_count_error_upper_bound": 0,
        "buckets": [
         ...
        ]
      },
      "doc_count": 76
    }
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.