Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make Geo field sortable in MacFJA / php-redisearch library? #20

Closed
mahendran-kcube opened this issue Nov 8, 2021 · 3 comments
Closed
Labels
question Further information is requested

Comments

@mahendran-kcube
Copy link

How to make Geo field sortable in MacFJA / php-redisearch library?

@MacFJA MacFJA added the question Further information is requested label Nov 8, 2021
@MacFJA
Copy link
Owner

MacFJA commented Nov 8, 2021

With the version 2.0.0 (that was not possible with version 1.x of the lib):

use MacFJA\RediSearch\Index;
use MacFJA\RediSearch\IndexBuilder;
use MacFJA\RediSearch\Redis\Client\PredisClient;
use MacFJA\RediSearch\Redis\Command\CreateCommand\GeoFieldOption;
use MacFJA\RediSearch\Redis\Command\Search;
use Predis\Client;

$client = PredisClient::make(new Client(['scheme' => 'tcp', 'host' => 'localhost', 'port' => '6379', 'db' => 0]));
// Or whatever client you need/have
// Or $client = (new \MacFJA\RediSearch\Redis\Client\ClientFacade)->getClient($redisInstance);

$indexBuilder = new IndexBuilder();
$indexBuilder
    ->setIndex('place')
    ->addPrefixes('p-')
    ->addField(
        (new GeoFieldOption())
            ->setField('gps')
            ->setSortable(true)
    );
$indexBuilder->create($client);

$index = new Index('place', $client);
$index->addDocumentFromArray(['gps' => '-0.1277583,51.5073509'], 'p-london');
$index->addDocumentFromArray(['gps' => '2.3522219,48.856614'],  'p-paris');
$index->addDocumentFromArray(['gps' => '11.5819806,48.1351253'],  'p-munich');
$index->addDocumentFromArray(['gps' => '-74.005941,40.712784'],  'p-nyc');
$index->addDocumentFromArray(['gps' => '139.731992,35.709026'],  'p-tokyo');

$result = $client->execute(
    (new Search())
        ->setIndex('place')
        ->setQuery('*')
        ->setSortBy('gps', 'DESC')
);

var_dump($result);

@mahendran-kcube
Copy link
Author

I am not able to install Version 2.0.0 of this library using the following command?
composer require macfja/redisearch

@MacFJA
Copy link
Owner

MacFJA commented Nov 10, 2021

The package is available on Packagist: https://packagist.org/packages/macfja/redisearch#2.0.0

You need to have:

  • PHP >=7.2
  • The PHP extension Intl (in any version)

@MacFJA MacFJA closed this as completed Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants