本文整理汇总了PHP中Elastica\Type::moreLikeThis方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::moreLikeThis方法的具体用法?PHP Type::moreLikeThis怎么用?PHP Type::moreLikeThis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Type
的用法示例。
在下文中一共展示了Type::moreLikeThis方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMoreLikeThisApi
public function testMoreLikeThisApi()
{
$client = new Client(array('persistent' => false));
$index = $client->getIndex('elastica_test');
$index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true);
$type = new Type($index, 'mlt_test');
$type->addDocument(new Document(1, array('visible' => true, 'name' => 'bruce wayne batman')));
$type->addDocument(new Document(2, array('visible' => true, 'name' => 'bruce wayne')));
$type->addDocument(new Document(3, array('visible' => false, 'name' => 'bruce wayne')));
$type->addDocument(new Document(4, array('visible' => true, 'name' => 'batman')));
$type->addDocument(new Document(5, array('visible' => false, 'name' => 'batman')));
$type->addDocument(new Document(6, array('visible' => true, 'name' => 'superman')));
$type->addDocument(new Document(7, array('visible' => true, 'name' => 'spiderman')));
$index->refresh();
$document = $type->getDocument(1);
// Return all similar
$resultSet = $type->moreLikeThis($document, array('min_term_freq' => '1', 'min_doc_freq' => '1'));
$this->assertEquals(4, $resultSet->count());
// Return just the visible similar
$query = new Query();
$filterTerm = new Term();
$filterTerm->setTerm('visible', true);
$query->setFilter($filterTerm);
$resultSet = $type->moreLikeThis($document, array('min_term_freq' => '1', 'min_doc_freq' => '1'), $query);
$this->assertEquals(2, $resultSet->count());
}