MacFJA / php-redisearch

PHP Client for RediSearch
MIT License
66 stars 9 forks source link

What to do with the search results?ths #50

Closed itmeicn closed 2 years ago

itmeicn commented 2 years ago
$search=$this->initSearch->setIndex($this->name)
            ->setQuery('*');
        $result=$this->clientPhprearch->execute($search);
        dump($result);
^ MacFJA\RediSearch\Redis\Response\PaginatedResponse {#135 ▼
  -items: array:10 [▼
    0 => MacFJA\RediSearch\Redis\Response\SearchResponseItem {#140 ▶}
    1 => MacFJA\RediSearch\Redis\Response\SearchResponseItem {#139 ▶}
    2 => MacFJA\RediSearch\Redis\Response\SearchResponseItem {#141 ▶}
    3 => MacFJA\RediSearch\Redis\Response\SearchResponseItem {#137 ▶}
    4 => MacFJA\RediSearch\Redis\Response\SearchResponseItem {#138 ▶}
    5 => MacFJA\RediSearch\Redis\Response\SearchResponseItem {#142 ▶}
    6 => MacFJA\RediSearch\Redis\Response\SearchResponseItem {#143 ▶}
    7 => MacFJA\RediSearch\Redis\Response\SearchResponseItem {#144 ▶}
    8 => MacFJA\RediSearch\Redis\Response\SearchResponseItem {#145 ▶}
    9 => MacFJA\RediSearch\Redis\Response\SearchResponseItem {#146 ▶}
  ]
  -lastCommand: MacFJA\RediSearch\Redis\Command\Search {#62 ▶}
  -totalCount: 152
  -client: null
  -requestedOffset: null
  -requestedSize: null
}
MacFJA commented 2 years ago

What you have here is the first page of result. You have 10 documents (the default page size of RediSearch is 10).

For example you can get the 10 documents:

$items = $results->current();
dump($items); // That will be your documents

$first = reset($items);
dump($first->getFieldValue('name')); // will the content of the field 'name' of the document

Or read the next page of documents:

$results->next();
$items = $results->current();
dump($items); // That will be your next 10 documents

By default, RediSearch will return the complete Redis document, even if there are fields that are not indexed


This is (hopefully) all explained in this documentation: https://github.com/MacFJA/php-redisearch/blob/main/docs/UsingResult.md

itmeicn commented 2 years ago

ths