meilisearch / meilisearch-php

PHP wrapper for the Meilisearch API

Home Page:https://meilisearch.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why doesn't it find anything?

Div-Man opened this issue · comments

$sql= "SELECT * FROM products";

$result = $dbh->query($sql);
$data = $result->fetchAll(PDO::FETCH_OBJ);

$index = $client->index('cena');
$index->updateFilterableAttributes(['price']);

$client->index('cena')->addDocuments($data);
 
$res = $client->index('cena')->search('', [
  'filter' => 'price = 2'
]);


echo '<pre>';
print_r($res);
echo '</pre>';

$data

Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [title] => text
            [img_path] => Pepperoni_585x585.webp
            [description] => text
            [section_number] => 
            [total] => 
            [diameter] => 35
            [weight] => 519
            [volume] => 
            [price] => 1
            [category_id] => 2
        )

    [1] => stdClass Object
        (
            [id] => 2
            [title] => text
            [img_path] => Madeira_set20230207_585x585.webp
            [description] => text
            [section_number] => 4
            [total] => 32
            [diameter] => 
            [weight] => 1114
            [volume] => 
            [price] => 2
            [category_id] => 1
        )

    [2] => stdClass Object
        (
            [id] => 3
            [title] => text
            [img_path] => Vetchina_i_syr_585x585.webp
            [description] => text
            [section_number] => 
            [total] => 
            [diameter] => 35
            [weight] => 605
            [volume] => 
            [price] => 1
            [category_id] => 2
        )

    [3] => stdClass Object
        (
            [id] => 4
            [title] => text
            [img_path] => Kartofel_fri_585x585.webp
            [description] => text
            [section_number] => 
            [total] => 
            [diameter] => 
            [weight] => 100
            [volume] => 
            [price] => 2
            [category_id] => 3
        )

    [4] => stdClass Object
        (
            [id] => 5
            [title] => text
            [img_path] => Liogkii_salat_585x585.webp
            [description] => text
            [section_number] => 
            [total] => 
            [diameter] => 
            [weight] => 166
            [volume] => 
            [price] => 2
            [category_id] => 3
        )

    [5] => stdClass Object
        (
            [id] => 6
            [title] => text
            [img_path] => Tropicheskii_salat_585x585.webp
            [description] => text
            [section_number] => 
            [total] => 
            [diameter] => 
            [weight] => 215
            [volume] => 
            [price] => 2
            [category_id] => 3
        )

    [6] => stdClass Object
        (
            [id] => 7
            [title] => text
            [img_path] => ZHako_salat_585x585.webp
            [description] => text
            [section_number] => 
            [total] => 
            [diameter] => 
            [weight] => 215
            [volume] => 
            [price] => 3
            [category_id] => 3
        )
)

result

Meilisearch\Search\SearchResult Object
(
    [hits:Meilisearch\Search\SearchResult:private] => Array
        (
        )

    [estimatedTotalHits:Meilisearch\Search\SearchResult:private] => 0
    [hitsCount:Meilisearch\Search\SearchResult:private] => 0
    [offset:Meilisearch\Search\SearchResult:private] => 0
    [limit:Meilisearch\Search\SearchResult:private] => 20
    [processingTimeMs:Meilisearch\Search\SearchResult:private] => 0
    [numberedPagination:Meilisearch\Search\SearchResult:private] => 
    [query:Meilisearch\Search\SearchResult:private] => 
    [facetDistribution:Meilisearch\Search\SearchResult:private] => Array
        (
        )

    [facetStats:Meilisearch\Search\SearchResult:private] => Array
        (
        )

    [raw:Meilisearch\Search\SearchResult:private] => Array
        (
            [hits] => Array
                (
                )

            [query] => 
            [processingTimeMs] => 0
            [limit] => 20
            [offset] => 0
            [estimatedTotalHits] => 0
            [nbHits] => 0
        )

)

Hi @Div-Man, I need to know which versions of Meilisearch and Meilisearch PHP you are using.

Also, we have similar tests that cover this issue you're reporting https://github.com/meilisearch/meilisearch-php/blob/main/tests/Endpoints/SearchTest.php#L330

Please, ensure you're waiting for your documents to be indexed properly. Methods like updateFilterableAttributes, addDocuments are async, and return a task.

@Div-Man do you still have this problem?

Closing due to inactivity.

Feel free to reopen if you still need help @Div-Man ;)