本文整理汇总了PHP中Elastica\Type::getDocument方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::getDocument方法的具体用法?PHP Type::getDocument怎么用?PHP Type::getDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Type
的用法示例。
在下文中一共展示了Type::getDocument方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSearchByDocument
/**
* @group functional
*/
public function testSearchByDocument()
{
$client = $this->_getClient(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->addDocuments(array(new Document(1, array('visible' => true, 'name' => 'bruce wayne batman')), new Document(2, array('visible' => true, 'name' => 'bruce wayne')), new Document(3, array('visible' => false, 'name' => 'bruce wayne')), new Document(4, array('visible' => true, 'name' => 'batman')), new Document(5, array('visible' => false, 'name' => 'batman')), new Document(6, array('visible' => true, 'name' => 'superman')), new Document(7, array('visible' => true, 'name' => 'spiderman'))));
$index->refresh();
$doc = $type->getDocument(1);
// Return all similar from id
$mltQuery = new MoreLikeThis();
$mltQuery->setMinTermFrequency(1);
$mltQuery->setMinDocFrequency(1);
$mltQuery->setLike($doc);
$query = new Query($mltQuery);
$resultSet = $type->search($query);
$this->assertEquals(4, $resultSet->count());
$mltQuery = new MoreLikeThis();
$mltQuery->setMinTermFrequency(1);
$mltQuery->setMinDocFrequency(1);
$mltQuery->setLike($doc);
$query = new Query\BoolQuery();
$query->addMust($mltQuery);
$this->hideDeprecated();
// Return just the visible similar from id
$filter = new Query\BoolQuery();
$filterTerm = new Query\Term();
$filterTerm->setTerm('visible', true);
$filter->addMust($filterTerm);
$query->addFilter($filter);
$this->showDeprecated();
$resultSet = $type->search($query);
$this->assertEquals(2, $resultSet->count());
// Return all similar from source
$mltQuery = new MoreLikeThis();
$mltQuery->setMinTermFrequency(1);
$mltQuery->setMinDocFrequency(1);
$mltQuery->setMinimumShouldMatch(90);
$mltQuery->setLike($type->getDocument(1)->setId(''));
$query = new Query($mltQuery);
$resultSet = $type->search($query);
$this->assertEquals(1, $resultSet->count());
// Legacy test with filter
$mltQuery = new MoreLikeThis();
$mltQuery->setMinTermFrequency(1);
$mltQuery->setMinDocFrequency(1);
$mltQuery->setLike($doc);
$query = new Query\BoolQuery();
$query->addMust($mltQuery);
$this->hideDeprecated();
// Return just the visible similar
$filter = new BoolFilter();
$filterTerm = new Term();
$filterTerm->setTerm('visible', true);
$filter->addMust($filterTerm);
$query->addFilter($filter);
$this->showDeprecated();
$resultSet = $type->search($query);
$this->assertEquals(2, $resultSet->count());
}
示例2: setUp
protected function setUp()
{
$typeName = Cache::TYPE_NAME;
$this->type = $this->prophesize('\\Elastica\\Type');
$this->type->request(Argument::any(), Argument::cetera())->willReturn(true);
$this->type->getName()->willReturn($typeName);
$this->index = $this->prophesize('\\Elastica\\Index');
$this->index->getType($typeName)->willReturn($this->type->reveal());
$this->index->exists()->willReturn(true);
$nsDoc = new Document('DoctrineNamespaceCacheKey[]', [Cache::VALUE_FIELD => serialize($this->namespaceId)]);
$this->type->getIndex()->willReturn($this->index->reveal());
$this->type->getDocument("DoctrineNamespaceCacheKey[]")->willReturn($nsDoc);
$this->client = $this->prophesize('\\Elastica\\Client');
$this->client->getIndex($this->indexName)->willReturn($this->index->reveal());
$this->cache = new Cache($this->client->reveal(), ['index' => $this->indexName]);
}
示例3: removeCities
/**
* @param array $removeCities
*/
public function removeCities($removeCities)
{
foreach ($removeCities as $departmentId => $newCities) {
$document = $this->departmentType->getDocument($departmentId);
$data = $document->getData();
if (isset($data['citiesIds'])) {
$cities = $data['citiesIds'];
foreach ($newCities as $newCity) {
unset($cities[$newCity]);
}
$data['citiesIds'] = $cities;
$document->setData($data);
$this->departmentType->updateDocument($document);
}
}
}
示例4: addDocumentToElastic
/**
* @param array $document
* @param string $type
* @throws \Exception
*/
protected function addDocumentToElastic(array $document, $type = 'issue')
{
switch ($type) {
case 'issue':
if (isset($document['custom_fields'])) {
foreach ($document['custom_fields'] as $customField) {
switch ($customField['id']) {
case 4:
$document['typo3_version'] = isset($customField['value']) ? $customField['value'] : '-';
break;
case 5:
$document['php_version'] = isset($customField['value']) ? $customField['value'] : '-';
break;
case 8:
$document['complexity'] = isset($customField['value']) ? $customField['value'] : '-';
break;
case 15:
$document['isregression'] = isset($customField['value']) ? true : false;
break;
case 18:
$document['focus']['name'] = isset($customField['value']) ? $customField['value'] : '-';
break;
default:
}
}
}
$document['updated_on'] = $this->fixDateFormat($document['updated_on']);
$document['created_on'] = $this->fixDateFormat($document['created_on']);
$type = new Elastica\Type($this->elasticIndex, 'issue');
try {
$testIfDocExists = $type->getDocument($document['id']);
} catch (\Exception $e) {
$message = new \WMDB\Forger\Utilities\Slack\Message();
$message->sendMessage($document);
}
break;
case 'review':
$type = new Elastica\Type($this->elasticIndex, 'review');
break;
case 'user':
$type = new Elastica\Type($this->elasticIndex, 'user');
break;
default:
}
#\TYPO3\Flow\var_dump($type);
$doc = new Elastica\Document($document['id'], $document);
#\TYPO3\Flow\var_dump($doc);
$type->addDocument($doc);
#sleep(1);
}
示例5: findById
/**
* @inheritdoc
*/
public function findById(\string $id) : ProductView
{
$result = $this->type->getDocument($id);
$product = $this->transformer->transformObject($result->getData());
return $product;
}
示例6: testGetDocumentWithFieldsSelection
/**
* Test to see if Elastica_Type::getDocument() is properly using
* the fields array when available instead of _source.
*
* @group functional
*/
public function testGetDocumentWithFieldsSelection()
{
$index = $this->_createIndex();
$type = new Type($index, 'test');
$type->addDocument(new Document(1, array('name' => 'loris', 'country' => 'FR', 'email' => 'test@test.com')));
$index->refresh();
$document = $type->getDocument(1, array('fields' => 'name,email'));
$data = $document->getData();
$this->assertArrayHasKey('name', $data);
$this->assertArrayHasKey('email', $data);
$this->assertArrayNotHasKey('country', $data);
}
示例7: 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());
}