示例#1
0
 /**
  * Test exact duplication.
  *
  * @return void
  */
 public function testExactDuplication()
 {
     $s1 = new Spellcheck([['a', []]], 'fake');
     $s2 = new Spellcheck([['a', []]], 'fake');
     $s1->mergeWith($s2);
     $this->assertCount(1, $s1);
 }
示例#2
0
 /**
  * Merge in other spellcheck information.
  *
  * @param Spellcheck $spellcheck Other spellcheck information
  *
  * @return void
  */
 public function mergeWith(Spellcheck $spellcheck)
 {
     // Merge primary suggestions:
     $this->terms->uksort([$this, 'compareTermLength']);
     foreach ($spellcheck as $term => $info) {
         if (!$this->contains($term)) {
             $this->terms->offsetSet($term, $info);
         }
     }
     // Store secondary suggestions in case merge yielded non-useful
     // result set:
     if (!$this->secondary) {
         $this->secondary = $spellcheck;
     } else {
         $this->secondary->mergeWith($spellcheck);
     }
 }
 /**
  * AggregateSpellcheck
  *
  * @param Spellcheck $spellcheck Spellcheck
  * @param string     $query      Query
  *
  * @return void
  */
 protected function aggregateSpellcheck(Spellcheck $spellcheck, $query)
 {
     foreach ($this->dictionaries as $dictionary) {
         $params = new ParamBag();
         $params->set('spellcheck', 'true');
         $params->set('spellcheck.dictionary', $dictionary);
         $queryObj = new Query($query, 'AllFields');
         $collection = $this->backend->search($queryObj, 0, 0, $params);
         $spellcheck->mergeWith($collection->getSpellcheck());
     }
 }
 /**
  * Submit requests for more spelling suggestions.
  *
  * @param Spellcheck $spellcheck Aggregating spellcheck object
  * @param string     $query      Spellcheck query
  *
  * @return void
  */
 protected function aggregateSpellcheck(Spellcheck $spellcheck, $query)
 {
     while (next($this->dictionaries) !== false) {
         $params = new ParamBag();
         $params->set('spellcheck', 'true');
         $params->set('spellcheck.dictionary', current($this->dictionaries));
         $queryObj = new Query($query, 'AllFields');
         try {
             $collection = $this->backend->search($queryObj, 0, 0, $params);
             $spellcheck->mergeWith($collection->getSpellcheck());
         } catch (\Exception $ex) {
             if ($this->logger) {
                 $this->logger->err("Exception thrown when aggregating spellcheck, ignoring.", array('exception' => $ex));
             }
         }
     }
 }