本文整理汇总了PHP中Elastica\Type\Mapping::setSource方法的典型用法代码示例。如果您正苦于以下问题:PHP Mapping::setSource方法的具体用法?PHP Mapping::setSource怎么用?PHP Mapping::setSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Type\Mapping
的用法示例。
在下文中一共展示了Mapping::setSource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSearch
/**
* @group functional
*/
public function testSearch()
{
$client = $this->_getClient();
$index = new Index($client, 'test');
$index->create(array(), true);
$index->getSettings()->setNumberOfReplicas(0);
//$index->getSettings()->setNumberOfShards(1);
$type = new Type($index, 'helloworldmlt');
$mapping = new Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed')));
$mapping->setSource(array('enabled' => false));
$type->setMapping($mapping);
$doc = new Document(1000, array('email' => 'testemail@gmail.com', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
$type->addDocument($doc);
$doc = new Document(1001, array('email' => 'nospam@gmail.com', 'content' => 'This is a fake nospam email address for gmail'));
$type->addDocument($doc);
// Refresh index
$index->refresh();
$mltQuery = new MoreLikeThis();
$mltQuery->setLike('fake gmail sample');
$mltQuery->setFields(array('email', 'content'));
$mltQuery->setMaxQueryTerms(3);
$mltQuery->setMinDocFrequency(1);
$mltQuery->setMinTermFrequency(1);
$query = new Query();
$query->setQuery($mltQuery);
$resultSet = $type->search($query);
$resultSet->getResponse()->getData();
$this->assertEquals(2, $resultSet->count());
}
示例2: testNoSource
public function testNoSource()
{
$index = $this->_createIndex();
$type = new Type($index, 'user');
$mapping = new Mapping($type, array('id' => array('type' => 'integer', 'store' => 'yes'), 'username' => array('type' => 'string', 'store' => 'no')));
$mapping->setSource(array('enabled' => false));
$type->setMapping($mapping);
$mapping = $type->getMapping();
$this->assertArrayHasKey('user', $mapping);
$this->assertArrayHasKey('properties', $mapping['user']);
$this->assertArrayHasKey('id', $mapping['user']['properties']);
$this->assertArrayHasKey('type', $mapping['user']['properties']['id']);
$this->assertEquals('integer', $mapping['user']['properties']['id']['type']);
// Adds 1 document to the index
$doc1 = new Document(1, array('username' => 'hans', 'test' => array('2', '3', '5')));
$type->addDocument($doc1);
// Adds a list of documents with _bulk upload to the index
$docs = array();
$docs[] = new Document(2, array('username' => 'john', 'test' => array('1', '3', '6')));
$docs[] = new Document(3, array('username' => 'rolf', 'test' => array('2', '3', '7')));
$type->addDocuments($docs);
// To update index
$index->refresh();
$resultSet = $type->search('rolf');
$this->assertEquals(1, $resultSet->count());
// Tests if no source is in response except id
$result = $resultSet->current();
$this->assertEquals(3, $result->getId());
$this->assertEmpty($result->getData());
}
示例3: testSearch
public function testSearch()
{
$client = $this->_getClient();
$index = new Index($client, 'test');
$index->create(array(), true);
$index->getSettings()->setNumberOfReplicas(0);
//$index->getSettings()->setNumberOfShards(1);
$type = new Type($index, 'helloworldfuzzy');
$mapping = new Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed')));
$mapping->setSource(array('enabled' => false));
$type->setMapping($mapping);
$doc = new Document(1000, array('email' => 'testemail@gmail.com', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
$type->addDocument($doc);
// Refresh index
$index->refresh();
$fltQuery = new FuzzyLikeThis();
$fltQuery->setLikeText("sample gmail");
$fltQuery->addFields(array("email", "content"));
$fltQuery->setMinSimilarity(0.3);
$fltQuery->setMaxQueryTerms(3);
$resultSet = $type->search($fltQuery);
$this->assertEquals(1, $resultSet->count());
}
示例4: create
/**
* Creates the index and sets the mapping for this type.
*
* @param bool $recreate OPTIONAL Recreates the index if true (default = false)
*/
public function create($recreate = false)
{
$this->getIndex()->create($this->_indexParams, $recreate);
$mapping = new Mapping($this->getType());
$mapping->setProperties($this->_mapping);
$mapping->setSource(array('enabled' => $this->_source));
$mapping->send();
}
示例5: testSearchSetAnalyzer
public function testSearchSetAnalyzer()
{
$client = $this->_getClient();
$index = new Index($client, 'test');
$index->create(array('analysis' => array('analyzer' => array('searchAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('myStopWords'))), 'filter' => array('myStopWords' => array('type' => 'stop', 'stopwords' => array('The'))))), true);
$index->getSettings()->setNumberOfReplicas(0);
//$index->getSettings()->setNumberOfShards(1);
$type = new Type($index, 'helloworldfuzzy');
$mapping = new Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed')));
$mapping->setSource(array('enabled' => false));
$type->setMapping($mapping);
$doc = new Document(1000, array('email' => 'testemail@gmail.com', 'content' => 'The Fuzzy Test!'));
$type->addDocument($doc);
$doc = new Document(1001, array('email' => 'testemail@gmail.com', 'content' => 'Elastica Fuzzy Test'));
$type->addDocument($doc);
// Refresh index
$index->refresh();
$fltQuery = new FuzzyLikeThis();
$fltQuery->addFields(array("email", "content"));
$fltQuery->setLikeText("The");
$fltQuery->setMinSimilarity(0.1);
$fltQuery->setMaxQueryTerms(3);
// Test before analyzer applied, should return 1 result
$resultSet = $type->search($fltQuery);
$this->assertEquals(1, $resultSet->count());
$fltQuery->setParam('analyzer', 'searchAnalyzer');
$resultSet = $type->search($fltQuery);
$this->assertEquals(0, $resultSet->count());
}