Ejemplo n.º 1
0
 /**
  * Executes phrase suggester and checks values.
  */
 public function testPhraseSuggester()
 {
     $phrase = new Phrase('description', 'Lorm adip');
     $phrase->setAnalyzer('simple');
     $phrase->setSize(1);
     $phrase->setRealWordErrorLikelihood(0.95);
     $phrase->setMaxErrors(0.5);
     $phrase->setGramSize(2);
     $phrase->setHighlight(['pre_tag' => '<span class="highlight">', 'post_tag' => '</span>']);
     $repository = $this->getManager()->getRepository('AcmeTestBundle:Product');
     $search = $repository->createSearch()->addSuggester($phrase);
     $results = $repository->execute($search, Repository::RESULTS_RAW);
     $score = array_pop($results['suggest']['description-phrase'][0]['options'][0]);
     $this->assertEquals(['description-phrase' => [['text' => 'Lorm adip', 'offset' => 0, 'length' => 9, 'options' => [['text' => 'lorem adip', 'highlighted' => '<span class="highlight">lorem</span> adip']]]]], $results['suggest']);
     $this->assertTrue($score > 0 && $score <= 1, 'Score is out of bounds');
 }
 /**
  * Data provider for testSuggestionIterator().
  *
  * @return array
  */
 public function getSuggestIterationData()
 {
     $out = [];
     // Case #0, Phrase type with all parameters set.
     $phrase = new Phrase('description', 'Lorm adip');
     $phrase->setAnalyzer('simple');
     $phrase->setSize(1);
     $phrase->setRealWordErrorLikelihood(0.95);
     $phrase->setMaxErrors(0.5);
     $phrase->setGramSize(2);
     $phrase->setHighlight(['pre_tag' => '<span class="highlight">', 'post_tag' => '</span>']);
     $expectedOption = new PhraseOption('lorem adip', 0.0, '<span class="highlight">lorem</span> adip');
     $out[] = ['suggesters' => [$phrase], 'expectedOptions' => [$expectedOption]];
     // Case #1, Phrase type with almost nothing set.
     $phrase = new Phrase('description', 'Lorm adip');
     $expectedOption = new SimpleOption('lorem adip', 0.0);
     $out[] = ['suggesters' => [$phrase], 'expectedOptions' => [$expectedOption]];
     // Case #2, Term type with almost nothing set.
     $term = new Term('description', 'ipsu');
     $expectedOption = new TermOption('ipsum', 0.0, 3);
     $out[] = ['suggesters' => [$term], 'expectedOptions' => [$expectedOption]];
     // Case #3, Multiple suggesters.
     $term = new Term('description', 'ipsu');
     $phrase = new Phrase('description', 'Lorm adip');
     $expectedOptions = [new SimpleOption('lorem adip', 0.0), new TermOption('ipsum', 0.0, 3)];
     $out[] = ['suggesters' => [$term, $phrase], 'expectedOptions' => $expectedOptions];
     // Case #4, Multiple options within multiple suggesters.
     $term = new Term('description', 'distibutd');
     $phrase = new Phrase('description', 'Lorm adip');
     $expectedOptions = [new SimpleOption('lorem adip', 0.0), new TermOption('disributed', 0.0, 1), new TermOption('distributed', 0.0, 1)];
     $out[] = ['suggesters' => [$term, $phrase], 'expectedOptions' => $expectedOptions];
     // Case #5, completion option using context suggester, with payload.
     $geoContext = new Context\GeoContext('location', ['lat' => 0, 'lon' => 0]);
     $categoryContext = new Context\CategoryContext('price', '500');
     $context = new Context('suggestions', 'cons');
     $context->addContext($geoContext);
     $context->addContext($categoryContext);
     $expectedOption = new CompletionOption('Lorem ipsum', 0.0, ['test' => true]);
     $out[] = ['suggesters' => [$context], 'expectedOptions' => [$expectedOption]];
     // Case #6, completion option using completion suggester, no payload.
     $completion = new Completion('completion_suggesting', 'ipsum');
     $expectedOption = new SimpleOption('Lorem ipsum', 0.0, null);
     $out[] = ['suggesters' => [$completion], 'expectedOptions' => [$expectedOption]];
     return $out;
 }
Ejemplo n.º 3
0
 /**
  * Tests toArray method exception.
  *
  * @expectedException \LogicException
  */
 public function testToArrayException()
 {
     $phrase = new Phrase('', '');
     $phrase->toArray();
 }