/**
  * Store an index
  * @param  Index  $index
  * @param  string $namespace
  * @return void
  */
 public function store(Index $index, string $namespace)
 {
     foreach ($index->permutations() as $permutation) {
         $namespaced = $this->data[$namespace] ?? [];
         $indexes = $namespaced[$permutation] ?? [];
         $indexes[] = $index->getId();
         $this->data[$namespace][$permutation] = $indexes;
     }
 }
 /**
  * Store an index
  * @param  Index  $index
  * @param  string $namespace
  * @return void
  */
 public function store(Index $index, string $namespace)
 {
     $this->redis->pipeline(function ($redis) use($index, $namespace) {
         // Store all indexes for this under ID separately
         $id = "autocomplete:" . $index->getId() . ":{$namespace}";
         foreach ($index->permutations() as $permutation) {
             // Store the index
             $key = "autocomplete:{$permutation}:{$namespace}";
             $redis->sadd($key, $index->getId());
             // Record the index by ID for easier deletes later
             $redis->sadd($id, $key);
             // Store all indexes in a separate array so we can clear
             $redis->sadd("autocomplete:{$namespace}", $key);
         }
         // Add the IDs indexes to a general indexes set
         $redis->sadd("autocomplete:{$namespace}", $id);
     });
 }
Example #3
0
 public function test_index_returns_no_permutations_when_term_is_shorter_than_index_length()
 {
     $index = new Index(1, 'comp');
     return $this->assertEquals([], $index->permutations(5));
 }