From 01490a47ba09e2883f07f87ee4cc00a09886e8d4 Mon Sep 17 00:00:00 2001 From: Ethan Hann Date: Sat, 2 Nov 2019 21:21:18 +1100 Subject: [PATCH] Update docs --- docs-src/searching.md | 11 ++-- docs/indexing/index.html | 100 ++++++++++++++++++++++++++++++-- docs/laravel-support/index.html | 86 ++++++++++++++++++++++++++- docs/search/search_index.json | 2 +- docs/searching/index.html | 99 +++++++++++++++++++++++-------- docs/sitemap.xml | 14 ++--- docs/sitemap.xml.gz | Bin 201 -> 199 bytes src/Query/Builder.php | 2 +- 8 files changed, 271 insertions(+), 43 deletions(-) diff --git a/docs-src/searching.md b/docs-src/searching.md index aacc916..cf53fd4 100644 --- a/docs-src/searching.md +++ b/docs-src/searching.md @@ -19,7 +19,8 @@ $result = $bookIndex->search('two cities', true); $result->documents(); // Array of arrays. ``` -## Filtering Tag Fields +## Filtering +### Tag Fields Tag fields can be filtered with the index's tagFilter method. @@ -40,7 +41,7 @@ $result = $bookIndex ->search('two cities'); ``` -## Filtering Numeric Fields +### Numeric Fields Numeric fields can be filtered with the index's numericFilter method. @@ -50,7 +51,7 @@ $result = $bookIndex ->search('two cities'); ``` -## Filtering Geo Fields +### Geo Fields Numeric fields can be filtered with the index's geoFilter method. @@ -69,9 +70,9 @@ $result = $bookIndex ->sortBy('price') ->search('two cities'); ``` + - -## Number of Search Results +## Number of Results The number of documents can be retrieved after performing a search. diff --git a/docs/indexing/index.html b/docs/indexing/index.html index 704c5ba..4d6f39c 100644 --- a/docs/indexing/index.html +++ b/docs/indexing/index.html @@ -337,12 +337,46 @@
  • - - Indexing from a Hash + + Indexing From a Hash
  • +
  • + + Aliasing + + + + +
  • + @@ -468,11 +502,45 @@
  • - - Indexing from a Hash + + Indexing From a Hash + + +
  • + +
  • + + Aliasing + + + + +
  • @@ -640,7 +708,7 @@

    Batch Indexing$bookIndex->addMany($documents, true); -

    Indexing from a Hash

    +

    Indexing From a Hash

    Redis hashes are key/value pairs referenced by a key. It is possible to index an existing hash with the addHash method. The document's ID has to be the same as the hash's key. @@ -654,6 +722,28 @@

    Indexing from a Hash
    $document = $bookIndex->makeDocument('foo');
     $bookIndex->replaceHash($document);
     
    + +

    Aliasing

    +

    Indexes can be aliased.

    +

    Note that an exception will be thrown if any alias method is called before an index's schema is created.

    +

    Adding an Alias

    +

    An alias can be added for an index like this:

    +
    $index->addAlias('foo');
    +
    + +

    Updating an Alias

    +

    Assuming an alias has already been added to an index, like this:

    +
    $oldIndex->addAlias('foo');
    +
    + +

    ...it can be reassigned to a different index like this:

    +
    $newIndex->updateAlias('foo');
    +
    + +

    Deleting an Alias

    +

    An alias can be deleted like this:

    +
    $index->deleteAlias('foo');
    +
    diff --git a/docs/laravel-support/index.html b/docs/laravel-support/index.html index 656e5db..48e233c 100644 --- a/docs/laravel-support/index.html +++ b/docs/laravel-support/index.html @@ -386,6 +386,13 @@ Configure the Scout Driver + + +
  • + + Define Searchable Schema + +
  • @@ -393,6 +400,13 @@ Import a Model +
  • + +
  • + + Query Filters + +
  • @@ -477,6 +491,13 @@ Configure the Scout Driver + + +
  • + + Define Searchable Schema + +
  • @@ -484,6 +505,13 @@ Import a Model +
  • + +
  • + + Query Filters + +
  • @@ -535,6 +563,54 @@

    Configure the Scout Driver
    'driver' => env('SCOUT_DRIVER', 'ehann-redisearch'),
     
    +

    Define Searchable Schema

    +

    Define the field types that will be used on indexing

    +
    <?php
    +
    +namespace App;
    +
    +use Laravel\Scout\Searchable;
    +...
    +use Ehann\RediSearch\Fields\TextField;
    +use Ehann\RediSearch\Fields\GeoField;
    +use Ehann\RediSearch\Fields\NumericField;
    +use Ehann\RediSearch\Fields\TagField;
    +use Ehann\RediSearch\Fields\GeoLocation;
    +...
    +
    +class User extends Model {
    +    use Searchable;
    +
    +    public function searchableAs()
    +    {
    +        return "user_index";
    +    }
    +
    +    public function toSearchableArray()
    +    {
    +        return [
    +            "name" => $this->name,
    +            "username" => $this->username,
    +            "location" => new GeoLocation(
    +                                $this->longitude,
    +                                $this->latitude
    +                            )
    +            "age" => $this->age,
    +       ];
    +    }
    +
    +    public function searchableSchema()
    +    {
    +        return [
    +            "name" => TextField::class,
    +            "username" => TextField::class,
    +            "location" => GeoField::class,
    +            "age" => NumericField::class
    +      ];
    +    }
    +}
    +
    +

    Import a Model

    Import a "Product" model that is configured to be searchable:

    artisan ehann:redisearch:import App\\Product
    @@ -548,8 +624,16 @@ 

    Import a Model
    artisan ehann:redisearch:import App\\Product --no-id
     

    +

    Query Filters

    +

    How To Query Filters? Filtering Tag Fields

    +
    App\User::search("Search Query", function($index){
    +    return $filter->geoFilter("location", 5.56475, 5.75516, 100)
    +                  ->numericFilter('age', 18, 32)
    +})->get()
    +
    +

    What now?

    -

    See the Laravel Scout documentation for additional information.

    +

    See the Laravel Scout documentation for additional information.

    diff --git a/docs/search/search_index.json b/docs/search/search_index.json index 7742115..c1966b1 100644 --- a/docs/search/search_index.json +++ b/docs/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"RediSearch-PHP RediSearch-PHP is a PHP client library for the RediSearch module which adds full-text search to Redis. Requirements Redis running with the RediSearch module loaded . PHP =7 PhpRedis , Predis , or php-redis-client . Install composer require ethanhann/redisearch-php Load require_once vendor/autoload.php ; Create a Redis Client use Ehann\\RedisRaw\\PredisAdapter ; use Ehann\\RedisRaw\\PhpRedisAdapter ; use Ehann\\RedisRaw\\RedisClientAdapter ; $redis = ( new PredisAdapter ()) - connect ( 127.0.0.1 , 6379 ); // or $redis = ( new PhpRedisAdapter ()) - connect ( 127.0.0.1 , 6379 ); // or $redis = ( new RedisClientAdapter ()) - connect ( 127.0.0.1 , 6379 ); Create the Schema use Ehann\\RediSearch\\Index ; $bookIndex = new Index ( $redis ); $bookIndex - addTextField ( title ) - addTextField ( author ) - addNumericField ( price ) - addNumericField ( stock ) - create (); Add a Document $bookIndex - add ([ new TextField ( title , Tale of Two Cities ), new TextField ( author , Charles Dickens ), new NumericField ( price , 9.99 ), new NumericField ( stock , 231 ), ]); Search the Index $result = $bookIndex - search ( two cities ); $result - count (); // Number of documents. $result - documents (); // Array of matches. // Documents are returned as objects by default. $firstResult = $result - documents ()[ 0 ]; $firstResult - title ; $firstResult - author ;","title":"Getting Started"},{"location":"#redisearch-php","text":"RediSearch-PHP is a PHP client library for the RediSearch module which adds full-text search to Redis.","title":"RediSearch-PHP"},{"location":"#requirements","text":"Redis running with the RediSearch module loaded . PHP =7 PhpRedis , Predis , or php-redis-client .","title":"Requirements"},{"location":"#install","text":"composer require ethanhann/redisearch-php","title":"Install"},{"location":"#load","text":"require_once vendor/autoload.php ;","title":"Load"},{"location":"#create-a-redis-client","text":"use Ehann\\RedisRaw\\PredisAdapter ; use Ehann\\RedisRaw\\PhpRedisAdapter ; use Ehann\\RedisRaw\\RedisClientAdapter ; $redis = ( new PredisAdapter ()) - connect ( 127.0.0.1 , 6379 ); // or $redis = ( new PhpRedisAdapter ()) - connect ( 127.0.0.1 , 6379 ); // or $redis = ( new RedisClientAdapter ()) - connect ( 127.0.0.1 , 6379 );","title":"Create a Redis Client"},{"location":"#create-the-schema","text":"use Ehann\\RediSearch\\Index ; $bookIndex = new Index ( $redis ); $bookIndex - addTextField ( title ) - addTextField ( author ) - addNumericField ( price ) - addNumericField ( stock ) - create ();","title":"Create the Schema"},{"location":"#add-a-document","text":"$bookIndex - add ([ new TextField ( title , Tale of Two Cities ), new TextField ( author , Charles Dickens ), new NumericField ( price , 9.99 ), new NumericField ( stock , 231 ), ]);","title":"Add a Document"},{"location":"#search-the-index","text":"$result = $bookIndex - search ( two cities ); $result - count (); // Number of documents. $result - documents (); // Array of matches. // Documents are returned as objects by default. $firstResult = $result - documents ()[ 0 ]; $firstResult - title ; $firstResult - author ;","title":"Search the Index"},{"location":"aggregating/","text":"Aggregating The Basics Make an index and add a few documents to it: use Ehann\\RediSearch\\Index ; $bookIndex = new Index ( $redis ); $bookIndex - add ([ title = How to be awesome , price = 9.99 ]); $bookIndex - add ([ title = Aggregating is awesome , price = 19.99 ]); Now group by title and get the average price: $results = $bookIndex - makeAggregateBuilder () - groupBy ( title ) - avg ( price );","title":"Aggregating"},{"location":"aggregating/#aggregating","text":"","title":"Aggregating"},{"location":"aggregating/#the-basics","text":"Make an index and add a few documents to it: use Ehann\\RediSearch\\Index ; $bookIndex = new Index ( $redis ); $bookIndex - add ([ title = How to be awesome , price = 9.99 ]); $bookIndex - add ([ title = Aggregating is awesome , price = 19.99 ]); Now group by title and get the average price: $results = $bookIndex - makeAggregateBuilder () - groupBy ( title ) - avg ( price );","title":"The Basics"},{"location":"changelog/","text":"Changelog 1.1.2 Changes since last release Loosen version requirement for redis raw to pull in bug fix(es). 1.1.1 Changes since last release Fix issue with implicitly named indexes. 1.1.0 Changes since last release Support aggregations . 1.0.1 Changes since last release Support NOINDEX fields. 1.0.0 Changes since last release Support complete RediSearch API, now including RETURN, SUMMARIZE, HIGHLIGHT, EXPANDER, and PAYLOAD in search queries. 0.11.0 Changes since last release Add hash indexing . 0.10.1 Changes since last release Polished docs, and added a section on the Laravel RediSearch package. Made internal changes to how numeric and geo search queries are generated. 0.10.0 Changes since last release Remove RedisClient class and add adapter functionality. There are now adapters for Predis, PhpRedis, and the Cheprasov client. They all extend AbstractRedisClient which implements RedisClientInterface . An additional adapter can be created by extending AbstractRedisClient or by implementing RedisClientInterface if needed for some reason. Handle RediSearch module error when index is created on a Redis database other than 0. Return boolean true instead of \"OK\" when using PredisAdapter. A new index now requires that a redis client is passed into its constructor - removed the magic behavior where a default RedisClient instance was auto initialized. 0.9.0 Changes since last release An exception is now thrown when the RediSearch module is not loaded in Redis. Allow a language to be specified when searching. 0.8.0 Changes since last release Add search result sorting . Remove NoScoreIdx and Optimize methods as they are deprecated and/or non-functional in RediSearch. Add explain method for explaining a query. Add optional query logging . Add suggestions . 0.7.0 Changes since last release Many bug fixes and code quality improvements. 0.6.0 Changes since last release Add batch indexing . 0.5.0 Rename vendor namespace from Eeh to Ehann AbstractIndex was renamed to Index and is no longer abstract. Custom document ID is now properly set when adding to an index.","title":"Changelog"},{"location":"changelog/#changelog","text":"","title":"Changelog"},{"location":"changelog/#112","text":"Changes since last release Loosen version requirement for redis raw to pull in bug fix(es).","title":"1.1.2"},{"location":"changelog/#111","text":"Changes since last release Fix issue with implicitly named indexes.","title":"1.1.1"},{"location":"changelog/#110","text":"Changes since last release Support aggregations .","title":"1.1.0"},{"location":"changelog/#101","text":"Changes since last release Support NOINDEX fields.","title":"1.0.1"},{"location":"changelog/#100","text":"Changes since last release Support complete RediSearch API, now including RETURN, SUMMARIZE, HIGHLIGHT, EXPANDER, and PAYLOAD in search queries.","title":"1.0.0"},{"location":"changelog/#0110","text":"Changes since last release Add hash indexing .","title":"0.11.0"},{"location":"changelog/#0101","text":"Changes since last release Polished docs, and added a section on the Laravel RediSearch package. Made internal changes to how numeric and geo search queries are generated.","title":"0.10.1"},{"location":"changelog/#0100","text":"Changes since last release Remove RedisClient class and add adapter functionality. There are now adapters for Predis, PhpRedis, and the Cheprasov client. They all extend AbstractRedisClient which implements RedisClientInterface . An additional adapter can be created by extending AbstractRedisClient or by implementing RedisClientInterface if needed for some reason. Handle RediSearch module error when index is created on a Redis database other than 0. Return boolean true instead of \"OK\" when using PredisAdapter. A new index now requires that a redis client is passed into its constructor - removed the magic behavior where a default RedisClient instance was auto initialized.","title":"0.10.0"},{"location":"changelog/#090","text":"Changes since last release An exception is now thrown when the RediSearch module is not loaded in Redis. Allow a language to be specified when searching.","title":"0.9.0"},{"location":"changelog/#080","text":"Changes since last release Add search result sorting . Remove NoScoreIdx and Optimize methods as they are deprecated and/or non-functional in RediSearch. Add explain method for explaining a query. Add optional query logging . Add suggestions .","title":"0.8.0"},{"location":"changelog/#070","text":"Changes since last release Many bug fixes and code quality improvements.","title":"0.7.0"},{"location":"changelog/#060","text":"Changes since last release Add batch indexing .","title":"0.6.0"},{"location":"changelog/#050","text":"Rename vendor namespace from Eeh to Ehann AbstractIndex was renamed to Index and is no longer abstract. Custom document ID is now properly set when adding to an index.","title":"0.5.0"},{"location":"indexing/","text":"Indexing Field Types There are three types of fields that can be added to a document: TextField , NumericField , and GeoField . They are instantiated like this: new TextField ( author , Charles Dickens ); new NumericField ( price , 9.99 ); new GeoField ( place , new GeoLocation ( - 77.0366 , 38.8977 )); new TagField ( color , red ); Fields can also be made with the FieldFactory class: // Alternative syntax for: new TextField( author , Charles Dickens ); FieldFactory :: make ( author , Charles Dickens ); // Alternative syntax for: new NumericField( price , 9.99); FieldFactory :: make ( price , 9.99 ); // Alternative syntax for: new GeoField( place , new GeoLocation(-77.0366, 38.8977)); FieldFactory :: make ( place , new GeoLocation ( - 77.0366 , 38.8977 )); // Alternative syntax for: new TagField( color , red ); FieldFactory :: make ( color , red ); Adding Documents Add an array of field objects: $bookIndex - add ([ new TextField ( title , Tale of Two Cities ), new TextField ( author , Charles Dickens ), new NumericField ( price , 9.99 ), new GeoField ( place , new GeoLocation ( - 77.0366 , 38.8977 )), new TagField ( color , red ), ]); Add an associative array: $bookIndex - add ([ title = Tale of Two Cities , author = Charles Dickens , price = 9.99 , place = new GeoLocation ( - 77.0366 , 38.8977 ), color = new TagField ( color , red ),, ]); Create a document with the index's makeDocument method, then set field values: $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $this - add ( $document ); DocBlocks can (optionally) be used to type hint field property names: /** @var BookDocument $document */ $document = $bookIndex - makeDocument (); // title will auto-complete correctly in your IDE provided BookDocument has a title property or @property annotation. $document - title - setValue ( How to be awesome. ); $this - add ( $document ); ?php namespace Your\\Documents ; use Ehann\\RediSearch\\Document\\Document ; use Ehann\\RediSearch\\Fields\\NumericField ; use Ehann\\RediSearch\\Fields\\TextField ; /** * @property TextField title * @property TextField author * @property NumericField price * @property GeoField place */ class BookDocument extends Document { } Updating a Document Documents are updated with an index's replace method. // Make a document. $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $bookIndex - add ( $document ); // Update a couple fields $document - title - setValue ( How to be awesome: Part 2. ); $document - price - setValue ( 19.99 ); // Update the document. $bookIndex - replace ( $document ); A document can also be updating when its ID is specified: // Make a document. $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $bookIndex - add ( $document ); // Create a new document and assign the old document s ID to it. $newDocument = $bookIndex - makeDocument ( $document - getId ()); // Set a couple fields. $document - title - setValue ( ); $document - author - setValue ( Jack ); $newDocument - title - setValue ( How to be awesome: Part 2. ); $newDocument - price - setValue ( 19.99 ); // Update the document. $bookIndex - replace ( $newDocument ); Batch Indexing Batch indexing is possible with the addMany method. To index an external collection, make sure to set the document's ID to the ID of the record in the external collection. // Get a record set from your DB (or some other datastore). $records = $someDatabase - findAll (); $documents = []; foreach ( $records as $record ) { // Make a new document with the external record s ID. $newDocument = $bookIndex - makeDocument ( $record - id ); $newDocument - title - setValue ( $record - title ); $newDocument - author - setValue ( $record - author ); $documents [] = $newDocument ; } // Add all the documents at once. $bookIndex - addMany ( $documents ); // It is possible to increase indexing speed by disabling atomicity by passing true as the second parameter. // Note that this is only possible when using the phpredis extension. $bookIndex - addMany ( $documents , true ); Indexing from a Hash Redis hashes are key/value pairs referenced by a key. It is possible to index an existing hash with the addHash method. The document's ID has to be the same as the hash's key. Attempting to index a hash that does not exist will result in an exception. Index a hash with the key \"foo\": $document = $bookIndex- makeDocument( foo ); $bookIndex- addHash($document); Replace a document in the index from a hash: $document = $bookIndex- makeDocument( foo ); $bookIndex- replaceHash($document);","title":"Indexing"},{"location":"indexing/#indexing","text":"","title":"Indexing"},{"location":"indexing/#field-types","text":"There are three types of fields that can be added to a document: TextField , NumericField , and GeoField . They are instantiated like this: new TextField ( author , Charles Dickens ); new NumericField ( price , 9.99 ); new GeoField ( place , new GeoLocation ( - 77.0366 , 38.8977 )); new TagField ( color , red ); Fields can also be made with the FieldFactory class: // Alternative syntax for: new TextField( author , Charles Dickens ); FieldFactory :: make ( author , Charles Dickens ); // Alternative syntax for: new NumericField( price , 9.99); FieldFactory :: make ( price , 9.99 ); // Alternative syntax for: new GeoField( place , new GeoLocation(-77.0366, 38.8977)); FieldFactory :: make ( place , new GeoLocation ( - 77.0366 , 38.8977 )); // Alternative syntax for: new TagField( color , red ); FieldFactory :: make ( color , red );","title":"Field Types"},{"location":"indexing/#adding-documents","text":"Add an array of field objects: $bookIndex - add ([ new TextField ( title , Tale of Two Cities ), new TextField ( author , Charles Dickens ), new NumericField ( price , 9.99 ), new GeoField ( place , new GeoLocation ( - 77.0366 , 38.8977 )), new TagField ( color , red ), ]); Add an associative array: $bookIndex - add ([ title = Tale of Two Cities , author = Charles Dickens , price = 9.99 , place = new GeoLocation ( - 77.0366 , 38.8977 ), color = new TagField ( color , red ),, ]); Create a document with the index's makeDocument method, then set field values: $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $this - add ( $document ); DocBlocks can (optionally) be used to type hint field property names: /** @var BookDocument $document */ $document = $bookIndex - makeDocument (); // title will auto-complete correctly in your IDE provided BookDocument has a title property or @property annotation. $document - title - setValue ( How to be awesome. ); $this - add ( $document ); ?php namespace Your\\Documents ; use Ehann\\RediSearch\\Document\\Document ; use Ehann\\RediSearch\\Fields\\NumericField ; use Ehann\\RediSearch\\Fields\\TextField ; /** * @property TextField title * @property TextField author * @property NumericField price * @property GeoField place */ class BookDocument extends Document { }","title":"Adding Documents"},{"location":"indexing/#updating-a-document","text":"Documents are updated with an index's replace method. // Make a document. $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $bookIndex - add ( $document ); // Update a couple fields $document - title - setValue ( How to be awesome: Part 2. ); $document - price - setValue ( 19.99 ); // Update the document. $bookIndex - replace ( $document ); A document can also be updating when its ID is specified: // Make a document. $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $bookIndex - add ( $document ); // Create a new document and assign the old document s ID to it. $newDocument = $bookIndex - makeDocument ( $document - getId ()); // Set a couple fields. $document - title - setValue ( ); $document - author - setValue ( Jack ); $newDocument - title - setValue ( How to be awesome: Part 2. ); $newDocument - price - setValue ( 19.99 ); // Update the document. $bookIndex - replace ( $newDocument );","title":"Updating a Document"},{"location":"indexing/#batch-indexing","text":"Batch indexing is possible with the addMany method. To index an external collection, make sure to set the document's ID to the ID of the record in the external collection. // Get a record set from your DB (or some other datastore). $records = $someDatabase - findAll (); $documents = []; foreach ( $records as $record ) { // Make a new document with the external record s ID. $newDocument = $bookIndex - makeDocument ( $record - id ); $newDocument - title - setValue ( $record - title ); $newDocument - author - setValue ( $record - author ); $documents [] = $newDocument ; } // Add all the documents at once. $bookIndex - addMany ( $documents ); // It is possible to increase indexing speed by disabling atomicity by passing true as the second parameter. // Note that this is only possible when using the phpredis extension. $bookIndex - addMany ( $documents , true );","title":"Batch Indexing"},{"location":"indexing/#indexing-from-a-hash","text":"Redis hashes are key/value pairs referenced by a key. It is possible to index an existing hash with the addHash method. The document's ID has to be the same as the hash's key. Attempting to index a hash that does not exist will result in an exception. Index a hash with the key \"foo\": $document = $bookIndex- makeDocument( foo ); $bookIndex- addHash($document); Replace a document in the index from a hash: $document = $bookIndex- makeDocument( foo ); $bookIndex- replaceHash($document);","title":"Indexing from a Hash"},{"location":"laravel-support/","text":"Laravel Support Laravel-RediSearch allows for indexing and searching Laravel models. It provides a Laravel Scout driver. Getting Started Install composer require ethanhann/laravel-redisearch Register the Provider Add this entry to the providers array in config/app.php. Ehann\\LaravelRediSearch\\RediSearchServiceProvider :: class Configure the Scout Driver Update the Scout driver in config/scout.php. driver = env ( SCOUT_DRIVER , ehann-redisearch ), Import a Model Import a \"Product\" model that is configured to be searchable : artisan ehann:redisearch:import App \\\\ Product Delete the index before importing: artisan ehann:redisearch:import App \\\\ Product --recreate-index Import models without an ID field (this should be rarely needed): artisan ehann:redisearch:import App \\\\ Product --no-id What now? See the Laravel Scout documentation for additional information.","title":"Laravel Support"},{"location":"laravel-support/#laravel-support","text":"Laravel-RediSearch allows for indexing and searching Laravel models. It provides a Laravel Scout driver.","title":"Laravel Support"},{"location":"laravel-support/#getting-started","text":"","title":"Getting Started"},{"location":"laravel-support/#install","text":"composer require ethanhann/laravel-redisearch","title":"Install"},{"location":"laravel-support/#register-the-provider","text":"Add this entry to the providers array in config/app.php. Ehann\\LaravelRediSearch\\RediSearchServiceProvider :: class","title":"Register the Provider"},{"location":"laravel-support/#configure-the-scout-driver","text":"Update the Scout driver in config/scout.php. driver = env ( SCOUT_DRIVER , ehann-redisearch ),","title":"Configure the Scout Driver"},{"location":"laravel-support/#import-a-model","text":"Import a \"Product\" model that is configured to be searchable : artisan ehann:redisearch:import App \\\\ Product Delete the index before importing: artisan ehann:redisearch:import App \\\\ Product --recreate-index Import models without an ID field (this should be rarely needed): artisan ehann:redisearch:import App \\\\ Product --no-id","title":"Import a Model"},{"location":"laravel-support/#what-now","text":"See the Laravel Scout documentation for additional information.","title":"What now?"},{"location":"searching/","text":"Searching Simple Text Search Text fields can be filtered with the index's search method. $result = $bookIndex - search ( two cities ); $result - count (); // Number of documents. $result - documents (); // Array of stdObjects. Documents can also be returned as arrays instead of objects by passing true as the second parameter to the search method. $result = $bookIndex - search ( two cities , true ); $result - documents (); // Array of arrays. Filtering Tag Fields Tag fields can be filtered with the index's tagFilter method. Specifying multiple tags creates a union of documents. $result = $bookIndex - tagFilter ( color , [ blue , red ]) - search ( two cities ); Use multiple separate tagFilter calls to create an intersection of documents. $result = $bookIndex - tagFilter ( color , [ blue ]) - tagFilter ( color , [ red ]) - search ( two cities ); Filtering Numeric Fields Numeric fields can be filtered with the index's numericFilter method. $result = $bookIndex - numericFilter ( price , 4.99 , 19.99 ) - search ( two cities ); Filtering Geo Fields Numeric fields can be filtered with the index's geoFilter method. $result = $bookIndex - geoFilter ( place , - 77.0366 , 38.897 , 100 ) - search ( two cities ); Sorting Results Search results can be sorted with the index's sort method. $result = $bookIndex - sortBy ( price ) - search ( two cities ); Setting a Language A supported language can be specified when running a query. Supported languages are represented as constants in the Ehann\\RediSearch\\Language class. $result = $bookIndex - language ( Language :: ITALIAN ) - search ( two cities ); Explaining a Query An explanation for a query can be generated with the index's explain method. This can be helpful for understanding why a query is returning a set of results. $result = $bookIndex - filter ( price , 4.99 , 19.99 ) - sortBy ( price ) - explain ( two cities ); Logging Queries Logging is optional. It can be enabled by injecting a PSR compliant logger, such as Monolog, into a RedisClient instance. Install Monolog: composer require monolog/monolog Inject a logger instance (with a stream handler in this example): $logger = new Logger ( Ehann\\RediSearch ); $logger - pushHandler ( new StreamHandler ( MyLogFile.log , Logger :: DEBUG )); $this - redisClient - setLogger ( $logger );","title":"Searching"},{"location":"searching/#searching","text":"","title":"Searching"},{"location":"searching/#simple-text-search","text":"Text fields can be filtered with the index's search method. $result = $bookIndex - search ( two cities ); $result - count (); // Number of documents. $result - documents (); // Array of stdObjects. Documents can also be returned as arrays instead of objects by passing true as the second parameter to the search method. $result = $bookIndex - search ( two cities , true ); $result - documents (); // Array of arrays.","title":"Simple Text Search"},{"location":"searching/#filtering-tag-fields","text":"Tag fields can be filtered with the index's tagFilter method. Specifying multiple tags creates a union of documents. $result = $bookIndex - tagFilter ( color , [ blue , red ]) - search ( two cities ); Use multiple separate tagFilter calls to create an intersection of documents. $result = $bookIndex - tagFilter ( color , [ blue ]) - tagFilter ( color , [ red ]) - search ( two cities );","title":"Filtering Tag Fields"},{"location":"searching/#filtering-numeric-fields","text":"Numeric fields can be filtered with the index's numericFilter method. $result = $bookIndex - numericFilter ( price , 4.99 , 19.99 ) - search ( two cities );","title":"Filtering Numeric Fields"},{"location":"searching/#filtering-geo-fields","text":"Numeric fields can be filtered with the index's geoFilter method. $result = $bookIndex - geoFilter ( place , - 77.0366 , 38.897 , 100 ) - search ( two cities );","title":"Filtering Geo Fields"},{"location":"searching/#sorting-results","text":"Search results can be sorted with the index's sort method. $result = $bookIndex - sortBy ( price ) - search ( two cities );","title":"Sorting Results"},{"location":"searching/#setting-a-language","text":"A supported language can be specified when running a query. Supported languages are represented as constants in the Ehann\\RediSearch\\Language class. $result = $bookIndex - language ( Language :: ITALIAN ) - search ( two cities );","title":"Setting a Language"},{"location":"searching/#explaining-a-query","text":"An explanation for a query can be generated with the index's explain method. This can be helpful for understanding why a query is returning a set of results. $result = $bookIndex - filter ( price , 4.99 , 19.99 ) - sortBy ( price ) - explain ( two cities );","title":"Explaining a Query"},{"location":"searching/#logging-queries","text":"Logging is optional. It can be enabled by injecting a PSR compliant logger, such as Monolog, into a RedisClient instance. Install Monolog: composer require monolog/monolog Inject a logger instance (with a stream handler in this example): $logger = new Logger ( Ehann\\RediSearch ); $logger - pushHandler ( new StreamHandler ( MyLogFile.log , Logger :: DEBUG )); $this - redisClient - setLogger ( $logger );","title":"Logging Queries"},{"location":"suggesting/","text":"Suggesting Creating a Suggestion Index Create a suggestion index called \"MySuggestions\": use Ehann\\RediSearch\\Suggestion ; $suggestion = new Suggestion ( $redisClient , MySuggestions ); Adding a Suggestion Add a suggestion with a score: $suggestion - add ( Tale of Two Cities , 1.10 ); Getting a Suggestion Pass a partial string to the get method: $result = $suggestion - get ( Cities ); Deleting a Suggestion Pass the entire suggestion string to the delete method: $result = $suggestion - delete ( Tale of Two Cities ); Getting the Number of Possible Suggestions Simply use the suggestion index's length method: $numberOfPossibleSuggestions = $suggestion - length ();","title":"Suggesting"},{"location":"suggesting/#suggesting","text":"","title":"Suggesting"},{"location":"suggesting/#creating-a-suggestion-index","text":"Create a suggestion index called \"MySuggestions\": use Ehann\\RediSearch\\Suggestion ; $suggestion = new Suggestion ( $redisClient , MySuggestions );","title":"Creating a Suggestion Index"},{"location":"suggesting/#adding-a-suggestion","text":"Add a suggestion with a score: $suggestion - add ( Tale of Two Cities , 1.10 );","title":"Adding a Suggestion"},{"location":"suggesting/#getting-a-suggestion","text":"Pass a partial string to the get method: $result = $suggestion - get ( Cities );","title":"Getting a Suggestion"},{"location":"suggesting/#deleting-a-suggestion","text":"Pass the entire suggestion string to the delete method: $result = $suggestion - delete ( Tale of Two Cities );","title":"Deleting a Suggestion"},{"location":"suggesting/#getting-the-number-of-possible-suggestions","text":"Simply use the suggestion index's length method: $numberOfPossibleSuggestions = $suggestion - length ();","title":"Getting the Number of Possible Suggestions"}]} \ No newline at end of file +{"config":{"lang":["en"],"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"RediSearch-PHP RediSearch-PHP is a PHP client library for the RediSearch module which adds full-text search to Redis. Requirements Redis running with the RediSearch module loaded . PHP =7 PhpRedis , Predis , or php-redis-client . Install composer require ethanhann/redisearch-php Load require_once vendor/autoload.php ; Create a Redis Client use Ehann\\RedisRaw\\PredisAdapter ; use Ehann\\RedisRaw\\PhpRedisAdapter ; use Ehann\\RedisRaw\\RedisClientAdapter ; $redis = ( new PredisAdapter ()) - connect ( 127.0.0.1 , 6379 ); // or $redis = ( new PhpRedisAdapter ()) - connect ( 127.0.0.1 , 6379 ); // or $redis = ( new RedisClientAdapter ()) - connect ( 127.0.0.1 , 6379 ); Create the Schema use Ehann\\RediSearch\\Index ; $bookIndex = new Index ( $redis ); $bookIndex - addTextField ( title ) - addTextField ( author ) - addNumericField ( price ) - addNumericField ( stock ) - create (); Add a Document $bookIndex - add ([ new TextField ( title , Tale of Two Cities ), new TextField ( author , Charles Dickens ), new NumericField ( price , 9.99 ), new NumericField ( stock , 231 ), ]); Search the Index $result = $bookIndex - search ( two cities ); $result - count (); // Number of documents. $result - documents (); // Array of matches. // Documents are returned as objects by default. $firstResult = $result - documents ()[ 0 ]; $firstResult - title ; $firstResult - author ;","title":"Getting Started"},{"location":"#redisearch-php","text":"RediSearch-PHP is a PHP client library for the RediSearch module which adds full-text search to Redis.","title":"RediSearch-PHP"},{"location":"#requirements","text":"Redis running with the RediSearch module loaded . PHP =7 PhpRedis , Predis , or php-redis-client .","title":"Requirements"},{"location":"#install","text":"composer require ethanhann/redisearch-php","title":"Install"},{"location":"#load","text":"require_once vendor/autoload.php ;","title":"Load"},{"location":"#create-a-redis-client","text":"use Ehann\\RedisRaw\\PredisAdapter ; use Ehann\\RedisRaw\\PhpRedisAdapter ; use Ehann\\RedisRaw\\RedisClientAdapter ; $redis = ( new PredisAdapter ()) - connect ( 127.0.0.1 , 6379 ); // or $redis = ( new PhpRedisAdapter ()) - connect ( 127.0.0.1 , 6379 ); // or $redis = ( new RedisClientAdapter ()) - connect ( 127.0.0.1 , 6379 );","title":"Create a Redis Client"},{"location":"#create-the-schema","text":"use Ehann\\RediSearch\\Index ; $bookIndex = new Index ( $redis ); $bookIndex - addTextField ( title ) - addTextField ( author ) - addNumericField ( price ) - addNumericField ( stock ) - create ();","title":"Create the Schema"},{"location":"#add-a-document","text":"$bookIndex - add ([ new TextField ( title , Tale of Two Cities ), new TextField ( author , Charles Dickens ), new NumericField ( price , 9.99 ), new NumericField ( stock , 231 ), ]);","title":"Add a Document"},{"location":"#search-the-index","text":"$result = $bookIndex - search ( two cities ); $result - count (); // Number of documents. $result - documents (); // Array of matches. // Documents are returned as objects by default. $firstResult = $result - documents ()[ 0 ]; $firstResult - title ; $firstResult - author ;","title":"Search the Index"},{"location":"aggregating/","text":"Aggregating The Basics Make an index and add a few documents to it: use Ehann\\RediSearch\\Index ; $bookIndex = new Index ( $redis ); $bookIndex - add ([ title = How to be awesome , price = 9.99 ]); $bookIndex - add ([ title = Aggregating is awesome , price = 19.99 ]); Now group by title and get the average price: $results = $bookIndex - makeAggregateBuilder () - groupBy ( title ) - avg ( price );","title":"Aggregating"},{"location":"aggregating/#aggregating","text":"","title":"Aggregating"},{"location":"aggregating/#the-basics","text":"Make an index and add a few documents to it: use Ehann\\RediSearch\\Index ; $bookIndex = new Index ( $redis ); $bookIndex - add ([ title = How to be awesome , price = 9.99 ]); $bookIndex - add ([ title = Aggregating is awesome , price = 19.99 ]); Now group by title and get the average price: $results = $bookIndex - makeAggregateBuilder () - groupBy ( title ) - avg ( price );","title":"The Basics"},{"location":"changelog/","text":"Changelog 1.1.2 Changes since last release Loosen version requirement for redis raw to pull in bug fix(es). 1.1.1 Changes since last release Fix issue with implicitly named indexes. 1.1.0 Changes since last release Support aggregations . 1.0.1 Changes since last release Support NOINDEX fields. 1.0.0 Changes since last release Support complete RediSearch API, now including RETURN, SUMMARIZE, HIGHLIGHT, EXPANDER, and PAYLOAD in search queries. 0.11.0 Changes since last release Add hash indexing . 0.10.1 Changes since last release Polished docs, and added a section on the Laravel RediSearch package. Made internal changes to how numeric and geo search queries are generated. 0.10.0 Changes since last release Remove RedisClient class and add adapter functionality. There are now adapters for Predis, PhpRedis, and the Cheprasov client. They all extend AbstractRedisClient which implements RedisClientInterface . An additional adapter can be created by extending AbstractRedisClient or by implementing RedisClientInterface if needed for some reason. Handle RediSearch module error when index is created on a Redis database other than 0. Return boolean true instead of \"OK\" when using PredisAdapter. A new index now requires that a redis client is passed into its constructor - removed the magic behavior where a default RedisClient instance was auto initialized. 0.9.0 Changes since last release An exception is now thrown when the RediSearch module is not loaded in Redis. Allow a language to be specified when searching. 0.8.0 Changes since last release Add search result sorting . Remove NoScoreIdx and Optimize methods as they are deprecated and/or non-functional in RediSearch. Add explain method for explaining a query. Add optional query logging . Add suggestions . 0.7.0 Changes since last release Many bug fixes and code quality improvements. 0.6.0 Changes since last release Add batch indexing . 0.5.0 Rename vendor namespace from Eeh to Ehann AbstractIndex was renamed to Index and is no longer abstract. Custom document ID is now properly set when adding to an index.","title":"Changelog"},{"location":"changelog/#changelog","text":"","title":"Changelog"},{"location":"changelog/#112","text":"Changes since last release Loosen version requirement for redis raw to pull in bug fix(es).","title":"1.1.2"},{"location":"changelog/#111","text":"Changes since last release Fix issue with implicitly named indexes.","title":"1.1.1"},{"location":"changelog/#110","text":"Changes since last release Support aggregations .","title":"1.1.0"},{"location":"changelog/#101","text":"Changes since last release Support NOINDEX fields.","title":"1.0.1"},{"location":"changelog/#100","text":"Changes since last release Support complete RediSearch API, now including RETURN, SUMMARIZE, HIGHLIGHT, EXPANDER, and PAYLOAD in search queries.","title":"1.0.0"},{"location":"changelog/#0110","text":"Changes since last release Add hash indexing .","title":"0.11.0"},{"location":"changelog/#0101","text":"Changes since last release Polished docs, and added a section on the Laravel RediSearch package. Made internal changes to how numeric and geo search queries are generated.","title":"0.10.1"},{"location":"changelog/#0100","text":"Changes since last release Remove RedisClient class and add adapter functionality. There are now adapters for Predis, PhpRedis, and the Cheprasov client. They all extend AbstractRedisClient which implements RedisClientInterface . An additional adapter can be created by extending AbstractRedisClient or by implementing RedisClientInterface if needed for some reason. Handle RediSearch module error when index is created on a Redis database other than 0. Return boolean true instead of \"OK\" when using PredisAdapter. A new index now requires that a redis client is passed into its constructor - removed the magic behavior where a default RedisClient instance was auto initialized.","title":"0.10.0"},{"location":"changelog/#090","text":"Changes since last release An exception is now thrown when the RediSearch module is not loaded in Redis. Allow a language to be specified when searching.","title":"0.9.0"},{"location":"changelog/#080","text":"Changes since last release Add search result sorting . Remove NoScoreIdx and Optimize methods as they are deprecated and/or non-functional in RediSearch. Add explain method for explaining a query. Add optional query logging . Add suggestions .","title":"0.8.0"},{"location":"changelog/#070","text":"Changes since last release Many bug fixes and code quality improvements.","title":"0.7.0"},{"location":"changelog/#060","text":"Changes since last release Add batch indexing .","title":"0.6.0"},{"location":"changelog/#050","text":"Rename vendor namespace from Eeh to Ehann AbstractIndex was renamed to Index and is no longer abstract. Custom document ID is now properly set when adding to an index.","title":"0.5.0"},{"location":"indexing/","text":"Indexing Field Types There are three types of fields that can be added to a document: TextField , NumericField , and GeoField . They are instantiated like this: new TextField ( author , Charles Dickens ); new NumericField ( price , 9.99 ); new GeoField ( place , new GeoLocation ( - 77.0366 , 38.8977 )); new TagField ( color , red ); Fields can also be made with the FieldFactory class: // Alternative syntax for: new TextField( author , Charles Dickens ); FieldFactory :: make ( author , Charles Dickens ); // Alternative syntax for: new NumericField( price , 9.99); FieldFactory :: make ( price , 9.99 ); // Alternative syntax for: new GeoField( place , new GeoLocation(-77.0366, 38.8977)); FieldFactory :: make ( place , new GeoLocation ( - 77.0366 , 38.8977 )); // Alternative syntax for: new TagField( color , red ); FieldFactory :: make ( color , red ); Adding Documents Add an array of field objects: $bookIndex - add ([ new TextField ( title , Tale of Two Cities ), new TextField ( author , Charles Dickens ), new NumericField ( price , 9.99 ), new GeoField ( place , new GeoLocation ( - 77.0366 , 38.8977 )), new TagField ( color , red ), ]); Add an associative array: $bookIndex - add ([ title = Tale of Two Cities , author = Charles Dickens , price = 9.99 , place = new GeoLocation ( - 77.0366 , 38.8977 ), color = new TagField ( color , red ),, ]); Create a document with the index's makeDocument method, then set field values: $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $this - add ( $document ); DocBlocks can (optionally) be used to type hint field property names: /** @var BookDocument $document */ $document = $bookIndex - makeDocument (); // title will auto-complete correctly in your IDE provided BookDocument has a title property or @property annotation. $document - title - setValue ( How to be awesome. ); $this - add ( $document ); ?php namespace Your\\Documents ; use Ehann\\RediSearch\\Document\\Document ; use Ehann\\RediSearch\\Fields\\NumericField ; use Ehann\\RediSearch\\Fields\\TextField ; /** * @property TextField title * @property TextField author * @property NumericField price * @property GeoField place */ class BookDocument extends Document { } Updating a Document Documents are updated with an index's replace method. // Make a document. $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $bookIndex - add ( $document ); // Update a couple fields $document - title - setValue ( How to be awesome: Part 2. ); $document - price - setValue ( 19.99 ); // Update the document. $bookIndex - replace ( $document ); A document can also be updating when its ID is specified: // Make a document. $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $bookIndex - add ( $document ); // Create a new document and assign the old document s ID to it. $newDocument = $bookIndex - makeDocument ( $document - getId ()); // Set a couple fields. $document - title - setValue ( ); $document - author - setValue ( Jack ); $newDocument - title - setValue ( How to be awesome: Part 2. ); $newDocument - price - setValue ( 19.99 ); // Update the document. $bookIndex - replace ( $newDocument ); Batch Indexing Batch indexing is possible with the addMany method. To index an external collection, make sure to set the document's ID to the ID of the record in the external collection. // Get a record set from your DB (or some other datastore). $records = $someDatabase - findAll (); $documents = []; foreach ( $records as $record ) { // Make a new document with the external record s ID. $newDocument = $bookIndex - makeDocument ( $record - id ); $newDocument - title - setValue ( $record - title ); $newDocument - author - setValue ( $record - author ); $documents [] = $newDocument ; } // Add all the documents at once. $bookIndex - addMany ( $documents ); // It is possible to increase indexing speed by disabling atomicity by passing true as the second parameter. // Note that this is only possible when using the phpredis extension. $bookIndex - addMany ( $documents , true ); Indexing From a Hash Redis hashes are key/value pairs referenced by a key. It is possible to index an existing hash with the addHash method. The document's ID has to be the same as the hash's key. Attempting to index a hash that does not exist will result in an exception. Index a hash with the key \"foo\": $document = $bookIndex- makeDocument( foo ); $bookIndex- addHash($document); Replace a document in the index from a hash: $document = $bookIndex- makeDocument( foo ); $bookIndex- replaceHash($document); Aliasing Indexes can be aliased. Note that an exception will be thrown if any alias method is called before an index's schema is created. Adding an Alias An alias can be added for an index like this: $index - addAlias ( foo ); Updating an Alias Assuming an alias has already been added to an index, like this: $oldIndex - addAlias ( foo ); ...it can be reassigned to a different index like this: $newIndex - updateAlias ( foo ); Deleting an Alias An alias can be deleted like this: $index - deleteAlias ( foo );","title":"Indexing"},{"location":"indexing/#indexing","text":"","title":"Indexing"},{"location":"indexing/#field-types","text":"There are three types of fields that can be added to a document: TextField , NumericField , and GeoField . They are instantiated like this: new TextField ( author , Charles Dickens ); new NumericField ( price , 9.99 ); new GeoField ( place , new GeoLocation ( - 77.0366 , 38.8977 )); new TagField ( color , red ); Fields can also be made with the FieldFactory class: // Alternative syntax for: new TextField( author , Charles Dickens ); FieldFactory :: make ( author , Charles Dickens ); // Alternative syntax for: new NumericField( price , 9.99); FieldFactory :: make ( price , 9.99 ); // Alternative syntax for: new GeoField( place , new GeoLocation(-77.0366, 38.8977)); FieldFactory :: make ( place , new GeoLocation ( - 77.0366 , 38.8977 )); // Alternative syntax for: new TagField( color , red ); FieldFactory :: make ( color , red );","title":"Field Types"},{"location":"indexing/#adding-documents","text":"Add an array of field objects: $bookIndex - add ([ new TextField ( title , Tale of Two Cities ), new TextField ( author , Charles Dickens ), new NumericField ( price , 9.99 ), new GeoField ( place , new GeoLocation ( - 77.0366 , 38.8977 )), new TagField ( color , red ), ]); Add an associative array: $bookIndex - add ([ title = Tale of Two Cities , author = Charles Dickens , price = 9.99 , place = new GeoLocation ( - 77.0366 , 38.8977 ), color = new TagField ( color , red ),, ]); Create a document with the index's makeDocument method, then set field values: $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $this - add ( $document ); DocBlocks can (optionally) be used to type hint field property names: /** @var BookDocument $document */ $document = $bookIndex - makeDocument (); // title will auto-complete correctly in your IDE provided BookDocument has a title property or @property annotation. $document - title - setValue ( How to be awesome. ); $this - add ( $document ); ?php namespace Your\\Documents ; use Ehann\\RediSearch\\Document\\Document ; use Ehann\\RediSearch\\Fields\\NumericField ; use Ehann\\RediSearch\\Fields\\TextField ; /** * @property TextField title * @property TextField author * @property NumericField price * @property GeoField place */ class BookDocument extends Document { }","title":"Adding Documents"},{"location":"indexing/#updating-a-document","text":"Documents are updated with an index's replace method. // Make a document. $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $bookIndex - add ( $document ); // Update a couple fields $document - title - setValue ( How to be awesome: Part 2. ); $document - price - setValue ( 19.99 ); // Update the document. $bookIndex - replace ( $document ); A document can also be updating when its ID is specified: // Make a document. $document = $bookIndex - makeDocument (); $document - title - setValue ( How to be awesome. ); $document - author - setValue ( Jack ); $document - price - setValue ( 9.99 ); $document - place - setValue ( new GeoLocation ( - 77.0366 , 38.8977 )); $bookIndex - add ( $document ); // Create a new document and assign the old document s ID to it. $newDocument = $bookIndex - makeDocument ( $document - getId ()); // Set a couple fields. $document - title - setValue ( ); $document - author - setValue ( Jack ); $newDocument - title - setValue ( How to be awesome: Part 2. ); $newDocument - price - setValue ( 19.99 ); // Update the document. $bookIndex - replace ( $newDocument );","title":"Updating a Document"},{"location":"indexing/#batch-indexing","text":"Batch indexing is possible with the addMany method. To index an external collection, make sure to set the document's ID to the ID of the record in the external collection. // Get a record set from your DB (or some other datastore). $records = $someDatabase - findAll (); $documents = []; foreach ( $records as $record ) { // Make a new document with the external record s ID. $newDocument = $bookIndex - makeDocument ( $record - id ); $newDocument - title - setValue ( $record - title ); $newDocument - author - setValue ( $record - author ); $documents [] = $newDocument ; } // Add all the documents at once. $bookIndex - addMany ( $documents ); // It is possible to increase indexing speed by disabling atomicity by passing true as the second parameter. // Note that this is only possible when using the phpredis extension. $bookIndex - addMany ( $documents , true );","title":"Batch Indexing"},{"location":"indexing/#indexing-from-a-hash","text":"Redis hashes are key/value pairs referenced by a key. It is possible to index an existing hash with the addHash method. The document's ID has to be the same as the hash's key. Attempting to index a hash that does not exist will result in an exception. Index a hash with the key \"foo\": $document = $bookIndex- makeDocument( foo ); $bookIndex- addHash($document); Replace a document in the index from a hash: $document = $bookIndex- makeDocument( foo ); $bookIndex- replaceHash($document);","title":"Indexing From a Hash"},{"location":"indexing/#aliasing","text":"Indexes can be aliased. Note that an exception will be thrown if any alias method is called before an index's schema is created.","title":"Aliasing"},{"location":"indexing/#adding-an-alias","text":"An alias can be added for an index like this: $index - addAlias ( foo );","title":"Adding an Alias"},{"location":"indexing/#updating-an-alias","text":"Assuming an alias has already been added to an index, like this: $oldIndex - addAlias ( foo ); ...it can be reassigned to a different index like this: $newIndex - updateAlias ( foo );","title":"Updating an Alias"},{"location":"indexing/#deleting-an-alias","text":"An alias can be deleted like this: $index - deleteAlias ( foo );","title":"Deleting an Alias"},{"location":"laravel-support/","text":"Laravel Support Laravel-RediSearch allows for indexing and searching Laravel models. It provides a Laravel Scout driver. Getting Started Install composer require ethanhann/laravel-redisearch Register the Provider Add this entry to the providers array in config/app.php. Ehann\\LaravelRediSearch\\RediSearchServiceProvider :: class Configure the Scout Driver Update the Scout driver in config/scout.php. driver = env ( SCOUT_DRIVER , ehann-redisearch ), Define Searchable Schema Define the field types that will be used on indexing ?php namespace App ; use Laravel\\Scout\\Searchable ; ... use Ehann\\RediSearch\\Fields\\TextField ; use Ehann\\RediSearch\\Fields\\GeoField ; use Ehann\\RediSearch\\Fields\\NumericField ; use Ehann\\RediSearch\\Fields\\TagField ; use Ehann\\RediSearch\\Fields\\GeoLocation ; ... class User extends Model { use Searchable ; public function searchableAs () { return user_index ; } public function toSearchableArray () { return [ name = $this - name , username = $this - username , location = new GeoLocation ( $this - longitude , $this - latitude ) age = $this - age , ]; } public function searchableSchema () { return [ name = TextField :: class , username = TextField :: class , location = GeoField :: class , age = NumericField :: class ]; } } Import a Model Import a \"Product\" model that is configured to be searchable : artisan ehann:redisearch:import App \\\\ Product Delete the index before importing: artisan ehann:redisearch:import App \\\\ Product --recreate-index Import models without an ID field (this should be rarely needed): artisan ehann:redisearch:import App \\\\ Product --no-id Query Filters How To Query Filters? Filtering Tag Fields App\\User::search( Search Query , function($index){ return $filter- geoFilter( location , 5.56475, 5.75516, 100) - numericFilter( age , 18, 32) })- get() What now? See the Laravel Scout documentation for additional information.","title":"Laravel Support"},{"location":"laravel-support/#laravel-support","text":"Laravel-RediSearch allows for indexing and searching Laravel models. It provides a Laravel Scout driver.","title":"Laravel Support"},{"location":"laravel-support/#getting-started","text":"","title":"Getting Started"},{"location":"laravel-support/#install","text":"composer require ethanhann/laravel-redisearch","title":"Install"},{"location":"laravel-support/#register-the-provider","text":"Add this entry to the providers array in config/app.php. Ehann\\LaravelRediSearch\\RediSearchServiceProvider :: class","title":"Register the Provider"},{"location":"laravel-support/#configure-the-scout-driver","text":"Update the Scout driver in config/scout.php. driver = env ( SCOUT_DRIVER , ehann-redisearch ),","title":"Configure the Scout Driver"},{"location":"laravel-support/#define-searchable-schema","text":"Define the field types that will be used on indexing ?php namespace App ; use Laravel\\Scout\\Searchable ; ... use Ehann\\RediSearch\\Fields\\TextField ; use Ehann\\RediSearch\\Fields\\GeoField ; use Ehann\\RediSearch\\Fields\\NumericField ; use Ehann\\RediSearch\\Fields\\TagField ; use Ehann\\RediSearch\\Fields\\GeoLocation ; ... class User extends Model { use Searchable ; public function searchableAs () { return user_index ; } public function toSearchableArray () { return [ name = $this - name , username = $this - username , location = new GeoLocation ( $this - longitude , $this - latitude ) age = $this - age , ]; } public function searchableSchema () { return [ name = TextField :: class , username = TextField :: class , location = GeoField :: class , age = NumericField :: class ]; } }","title":"Define Searchable Schema"},{"location":"laravel-support/#import-a-model","text":"Import a \"Product\" model that is configured to be searchable : artisan ehann:redisearch:import App \\\\ Product Delete the index before importing: artisan ehann:redisearch:import App \\\\ Product --recreate-index Import models without an ID field (this should be rarely needed): artisan ehann:redisearch:import App \\\\ Product --no-id","title":"Import a Model"},{"location":"laravel-support/#query-filters","text":"How To Query Filters? Filtering Tag Fields App\\User::search( Search Query , function($index){ return $filter- geoFilter( location , 5.56475, 5.75516, 100) - numericFilter( age , 18, 32) })- get()","title":"Query Filters"},{"location":"laravel-support/#what-now","text":"See the Laravel Scout documentation for additional information.","title":"What now?"},{"location":"searching/","text":"Searching Simple Text Search Text fields can be filtered with the index's search method. $result = $bookIndex - search ( two cities ); $result - count (); // Number of documents. $result - documents (); // Array of stdObjects. Documents can also be returned as arrays instead of objects by passing true as the second parameter to the search method. $result = $bookIndex - search ( two cities , true ); $result - documents (); // Array of arrays. Filtering Tag Fields Tag fields can be filtered with the index's tagFilter method. Specifying multiple tags creates a union of documents. $result = $bookIndex - tagFilter ( color , [ blue , red ]) - search ( two cities ); Use multiple separate tagFilter calls to create an intersection of documents. $result = $bookIndex - tagFilter ( color , [ blue ]) - tagFilter ( color , [ red ]) - search ( two cities ); Numeric Fields Numeric fields can be filtered with the index's numericFilter method. $result = $bookIndex - numericFilter ( price , 4.99 , 19.99 ) - search ( two cities ); Geo Fields Numeric fields can be filtered with the index's geoFilter method. $result = $bookIndex - geoFilter ( place , - 77.0366 , 38.897 , 100 ) - search ( two cities ); Sorting Results Search results can be sorted with the index's sort method. $result = $bookIndex - sortBy ( price ) - search ( two cities ); Number of Results The number of documents can be retrieved after performing a search. $result = $bookIndex - search ( two cities ); $result - count (); // Number of documents. Alternatively, the number of documents can be queried without returning the documents themselves. This is useful if you want to check the total number of documents without returning any other data from the Redis server. $numberOfDocuments = $bookIndex - count ( two cities ); Setting a Language A supported language can be specified when running a query. Supported languages are represented as constants in the Ehann\\RediSearch\\Language class. $result = $bookIndex - language ( Language :: ITALIAN ) - search ( two cities ); Explaining a Query An explanation for a query can be generated with the index's explain method. This can be helpful for understanding why a query is returning a set of results. $result = $bookIndex - filter ( price , 4.99 , 19.99 ) - sortBy ( price ) - explain ( two cities ); Logging Queries Logging is optional. It can be enabled by injecting a PSR compliant logger, such as Monolog, into a RedisClient instance. Install Monolog: composer require monolog/monolog Inject a logger instance (with a stream handler in this example): $logger = new Logger ( Ehann\\RediSearch ); $logger - pushHandler ( new StreamHandler ( MyLogFile.log , Logger :: DEBUG )); $this - redisClient - setLogger ( $logger );","title":"Searching"},{"location":"searching/#searching","text":"","title":"Searching"},{"location":"searching/#simple-text-search","text":"Text fields can be filtered with the index's search method. $result = $bookIndex - search ( two cities ); $result - count (); // Number of documents. $result - documents (); // Array of stdObjects. Documents can also be returned as arrays instead of objects by passing true as the second parameter to the search method. $result = $bookIndex - search ( two cities , true ); $result - documents (); // Array of arrays.","title":"Simple Text Search"},{"location":"searching/#filtering","text":"","title":"Filtering"},{"location":"searching/#tag-fields","text":"Tag fields can be filtered with the index's tagFilter method. Specifying multiple tags creates a union of documents. $result = $bookIndex - tagFilter ( color , [ blue , red ]) - search ( two cities ); Use multiple separate tagFilter calls to create an intersection of documents. $result = $bookIndex - tagFilter ( color , [ blue ]) - tagFilter ( color , [ red ]) - search ( two cities );","title":"Tag Fields"},{"location":"searching/#numeric-fields","text":"Numeric fields can be filtered with the index's numericFilter method. $result = $bookIndex - numericFilter ( price , 4.99 , 19.99 ) - search ( two cities );","title":"Numeric Fields"},{"location":"searching/#geo-fields","text":"Numeric fields can be filtered with the index's geoFilter method. $result = $bookIndex - geoFilter ( place , - 77.0366 , 38.897 , 100 ) - search ( two cities );","title":"Geo Fields"},{"location":"searching/#sorting-results","text":"Search results can be sorted with the index's sort method. $result = $bookIndex - sortBy ( price ) - search ( two cities );","title":"Sorting Results"},{"location":"searching/#number-of-results","text":"The number of documents can be retrieved after performing a search. $result = $bookIndex - search ( two cities ); $result - count (); // Number of documents. Alternatively, the number of documents can be queried without returning the documents themselves. This is useful if you want to check the total number of documents without returning any other data from the Redis server. $numberOfDocuments = $bookIndex - count ( two cities );","title":"Number of Results"},{"location":"searching/#setting-a-language","text":"A supported language can be specified when running a query. Supported languages are represented as constants in the Ehann\\RediSearch\\Language class. $result = $bookIndex - language ( Language :: ITALIAN ) - search ( two cities );","title":"Setting a Language"},{"location":"searching/#explaining-a-query","text":"An explanation for a query can be generated with the index's explain method. This can be helpful for understanding why a query is returning a set of results. $result = $bookIndex - filter ( price , 4.99 , 19.99 ) - sortBy ( price ) - explain ( two cities );","title":"Explaining a Query"},{"location":"searching/#logging-queries","text":"Logging is optional. It can be enabled by injecting a PSR compliant logger, such as Monolog, into a RedisClient instance. Install Monolog: composer require monolog/monolog Inject a logger instance (with a stream handler in this example): $logger = new Logger ( Ehann\\RediSearch ); $logger - pushHandler ( new StreamHandler ( MyLogFile.log , Logger :: DEBUG )); $this - redisClient - setLogger ( $logger );","title":"Logging Queries"},{"location":"suggesting/","text":"Suggesting Creating a Suggestion Index Create a suggestion index called \"MySuggestions\": use Ehann\\RediSearch\\Suggestion ; $suggestion = new Suggestion ( $redisClient , MySuggestions ); Adding a Suggestion Add a suggestion with a score: $suggestion - add ( Tale of Two Cities , 1.10 ); Getting a Suggestion Pass a partial string to the get method: $result = $suggestion - get ( Cities ); Deleting a Suggestion Pass the entire suggestion string to the delete method: $result = $suggestion - delete ( Tale of Two Cities ); Getting the Number of Possible Suggestions Simply use the suggestion index's length method: $numberOfPossibleSuggestions = $suggestion - length ();","title":"Suggesting"},{"location":"suggesting/#suggesting","text":"","title":"Suggesting"},{"location":"suggesting/#creating-a-suggestion-index","text":"Create a suggestion index called \"MySuggestions\": use Ehann\\RediSearch\\Suggestion ; $suggestion = new Suggestion ( $redisClient , MySuggestions );","title":"Creating a Suggestion Index"},{"location":"suggesting/#adding-a-suggestion","text":"Add a suggestion with a score: $suggestion - add ( Tale of Two Cities , 1.10 );","title":"Adding a Suggestion"},{"location":"suggesting/#getting-a-suggestion","text":"Pass a partial string to the get method: $result = $suggestion - get ( Cities );","title":"Getting a Suggestion"},{"location":"suggesting/#deleting-a-suggestion","text":"Pass the entire suggestion string to the delete method: $result = $suggestion - delete ( Tale of Two Cities );","title":"Deleting a Suggestion"},{"location":"suggesting/#getting-the-number-of-possible-suggestions","text":"Simply use the suggestion index's length method: $numberOfPossibleSuggestions = $suggestion - length ();","title":"Getting the Number of Possible Suggestions"}]} \ No newline at end of file diff --git a/docs/searching/index.html b/docs/searching/index.html index c5a4295..5da0f47 100644 --- a/docs/searching/index.html +++ b/docs/searching/index.html @@ -328,24 +328,37 @@
  • - - Filtering Tag Fields + + Filtering + + + +
  • @@ -353,6 +366,13 @@ Sorting Results +
  • + +
  • + + Number of Results + +
  • @@ -468,24 +488,37 @@
  • - - Filtering Tag Fields + + Filtering + + + +
  • @@ -493,6 +526,13 @@ Sorting Results +
  • + +
  • + + Number of Results + +
  • @@ -550,7 +590,8 @@

    Filtering

    +

    Tag Fields

    Tag fields can be filtered with the index's tagFilter method.

    Specifying multiple tags creates a union of documents.

    $result = $bookIndex
    @@ -565,14 +606,14 @@ 

    Filtering Tag Fields->search('two cities');

    -

    Filtering Numeric Fields

    +

    Numeric Fields

    Numeric fields can be filtered with the index's numericFilter method.

    $result = $bookIndex
         ->numericFilter('price', 4.99, 19.99)
         ->search('two cities');
     
    -

    Filtering Geo Fields

    +

    Geo Fields

    Numeric fields can be filtered with the index's geoFilter method.

    $result = $bookIndex
         ->geoFilter('place', -77.0366, 38.897, 100)
    @@ -586,6 +627,18 @@ 

    Sorting Results->search('two cities');

    +

    Number of Results

    +

    The number of documents can be retrieved after performing a search.

    +
    $result = $bookIndex->search('two cities');
    +
    +$result->count();     // Number of documents.
    +
    + +

    Alternatively, the number of documents can be queried without returning the documents themselves. +This is useful if you want to check the total number of documents without returning any other data from the Redis server.

    +
    $numberOfDocuments = $bookIndex->count('two cities');
    +
    +

    Setting a Language

    A supported language can be specified when running a query. Supported languages are represented as constants in the Ehann\RediSearch\Language class.

    diff --git a/docs/sitemap.xml b/docs/sitemap.xml index fa4e747..3aa4443 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -2,37 +2,37 @@ None - 2019-05-25 + 2019-11-02 daily None - 2019-05-25 + 2019-11-02 daily None - 2019-05-25 + 2019-11-02 daily None - 2019-05-25 + 2019-11-02 daily None - 2019-05-25 + 2019-11-02 daily None - 2019-05-25 + 2019-11-02 daily None - 2019-05-25 + 2019-11-02 daily \ No newline at end of file diff --git a/docs/sitemap.xml.gz b/docs/sitemap.xml.gz index bea2299a56765212975d6d0a1abd020c2ed4923d..d9562f7e706d2c8cfdf0e762f5ef5b2731412a43 100644 GIT binary patch literal 199 zcmV;&06702iwFpRSiM~W|8r?{Wo=<_E_iKh0PT}85`r)gMSD(>Nl!LVi4#I+X{86q zgb0}l2_{kW_69-6BUrG_{{8!BU$v}x3d41-_UKxB>qg_-^T`_zSUb5GsTN005lG BSE>L2 literal 201 zcmV;)05<<0iwFpk3F=$||8r?{Wo=<_E_iKh0PT}O4uUWcMfaSd>7EuyNW_$~bLmPC z(3A>IN{gK;dV7nY@dz%M&HVZEGjBDlc?<^Kl?Ux?jdPM=q^xwUwq1?Sr$f5K4Nut3 z8&Cnou!S1;A&h%Ur)eUfgBrvL#QBbb?Bf7*HEBjF%o7xAKCmdnjFbH6tYUOlA5%aW zT+53ruhOhci!!cPZ;i-a*iK!%y7E?N^JMhLSt#_2*?=4Hzk%--pNhW#0d)-^gaZHo D