Exemplo n.º 1
0
 /**
  * Check if precision setting works as expected.
  */
 public function testContextSuggesterPrecision()
 {
     $geoContext = new Context\GeoContext('location', ['lat' => 0, 'lon' => 0]);
     $geoContext->setPrecision('10000km');
     $categoryContext = new Context\CategoryContext('price', '500');
     $context = new Context('suggestions', 'cons');
     $context->addContext($geoContext);
     $context->addContext($categoryContext);
     $repository = $this->getManager()->getRepository('AcmeTestBundle:Product');
     $search = $repository->createSearch()->addSuggester($context);
     $result = $repository->execute($search, Repository::RESULTS_RAW);
     $this->assertEmpty($result['suggest']['suggestions-completion'][0]['options']);
 }
Exemplo n.º 2
0
 /**
  * Tests toArray method when $this->getSize() !== null.
  */
 public function testToArrayNotNull()
 {
     $name = 'testName';
     $context = new Context('', '', $name);
     $context->setSize(123);
     $context->setContext(new Phrase('', ''));
     $result = $context->toArray();
     $this->assertArrayHasKey($name, $result);
     $data = $result[$name];
     $this->assertArrayHasKey('completion', $data);
     $completion = $data['completion'];
     $this->assertArrayHasKey('size', $completion);
     $this->assertEquals($completion['size'], 123);
 }
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * Data provider for testSuggest().
  *
  * @return array
  */
 public function getSuggestData()
 {
     $out = [];
     // Case #0: simple single term suggester.
     $expectedResults = ['description-term' => [['text' => 'distibutd', 'offset' => '0', 'length' => '9', 'options' => [new TermOption('disributed', 0.0, 1), new TermOption('distributed', 0.0, 1)]]]];
     $suggesters = [new Term('description', 'distibutd')];
     $out[] = ['suggesters' => $suggesters, 'expectedResults' => $expectedResults];
     // Case #1: simple single phrase suggester.
     $expectedResults = ['description-phrase' => [['text' => 'Lorm adip', 'offset' => '0', 'length' => '9', 'options' => [new SimpleOption('lorem adip', 0.0)]]]];
     $suggesters = [new Phrase('description', 'Lorm adip')];
     $out[] = ['suggesters' => $suggesters, 'expectedResults' => $expectedResults];
     // Case #2: simple context suggester.
     $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);
     $expectedResults = ['suggestions-completion' => [['text' => 'cons', 'offset' => '0', 'length' => '4', 'options' => [new CompletionOption('Lorem ipsum', 0.0, ['test' => true])]]]];
     $out[] = ['suggesters' => $context, 'expectedResults' => $expectedResults];
     // Case #3: simple completion suggester.
     $completion = new Completion('completion_suggesting', 'ipsum');
     $expectedResults = ['completion_suggesting-completion' => [['text' => 'ipsum', 'offset' => '0', 'length' => '5', 'options' => [new SimpleOption('Lorem ipsum', 0.0, null)]]]];
     $out[] = ['suggesters' => $completion, 'expectedResults' => $expectedResults];
     // Case #4: all together.
     $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);
     $suggesters = [new Term('description', 'distibutd'), new Phrase('description', 'Lorm adip'), $context, new Completion('completion_suggesting', 'ipsum')];
     $expectedResults = ['description-term' => [['text' => 'distibutd', 'offset' => '0', 'length' => '9', 'options' => [new TermOption('disributed', 0.0, 1), new TermOption('distributed', 0.0, 1)]]], 'description-phrase' => [['text' => 'Lorm adip', 'offset' => '0', 'length' => '9', 'options' => [new SimpleOption('lorem adip', 0.0)]]], 'suggestions-completion' => [['text' => 'cons', 'offset' => '0', 'length' => '4', 'options' => [new CompletionOption('Lorem ipsum', 0.0, ['test' => true])]]], 'completion_suggesting-completion' => [['text' => 'ipsum', 'offset' => '0', 'length' => '5', 'options' => [new SimpleOption('Lorem ipsum', 0.0, null)]]]];
     $out[] = ['suggesters' => $suggesters, 'expectedResults' => $expectedResults];
     return $out;
 }