本文整理汇总了PHP中Elastica\Index::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Index::create方法的具体用法?PHP Index::create怎么用?PHP Index::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Index
的用法示例。
在下文中一共展示了Index::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createIndex
/**
* Create the test index before tests run.
*/
protected static function createIndex()
{
self::$index->create(['analysis' => ['analyzer' => MappingFactory::getCustomAnalyzers()]], true);
$type = self::$index->getType('message');
$mapping = (new MappingFactory())->create(EmailMessage::schema(), 'english');
$mapping->setType($type);
$mapping->send();
}
示例2: getIndex
/**
* @return Index
*/
private function getIndex()
{
if (null === $this->index) {
$this->index = $this->client->getIndex($this->indexName);
if (!$this->index->exists()) {
$this->index->create();
}
}
return $this->index;
}
示例3: 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());
}
示例4: testSearch
/**
* @group functional
*/
public function testSearch()
{
$client = $this->_getClient();
$index = new Index($client, 'test');
$index->create(array(), true);
$type = new Type($index, 'helloworld');
$doc = new Document(1, array('id' => 1, 'email' => 'hans@test.com', 'username' => 'hans', 'test' => array('2', '3', '5')));
$type->addDocument($doc);
$doc = new Document(2, array('id' => 2, 'email' => 'emil@test.com', 'username' => 'emil', 'test' => array('1', '3', '6')));
$type->addDocument($doc);
$doc = new Document(3, array('id' => 3, 'email' => 'ruth@test.com', 'username' => 'ruth', 'test' => array('2', '3', '7')));
$type->addDocument($doc);
// Refresh index
$index->refresh();
$boolQuery = new BoolQuery();
$termQuery1 = new Term(array('test' => '2'));
$boolQuery->addMust($termQuery1);
$resultSet = $type->search($boolQuery);
$this->assertEquals(2, $resultSet->count());
$termQuery2 = new Term(array('test' => '5'));
$boolQuery->addMust($termQuery2);
$resultSet = $type->search($boolQuery);
$this->assertEquals(1, $resultSet->count());
$termQuery3 = new Term(array('username' => 'hans'));
$boolQuery->addMust($termQuery3);
$resultSet = $type->search($boolQuery);
$this->assertEquals(1, $resultSet->count());
$termQuery4 = new Term(array('username' => 'emil'));
$boolQuery->addMust($termQuery4);
$resultSet = $type->search($boolQuery);
$this->assertEquals(0, $resultSet->count());
}
示例5: testQuery
public function testQuery()
{
$client = $this->_getClient();
$index = new Index($client, 'test');
$index->create(array(), true);
$type = new Type($index, 'constant_score');
$doc = new Document(1, array('id' => 1, 'email' => 'hans@test.com', 'username' => 'hans'));
$type->addDocument($doc);
$doc = new Document(2, array('id' => 2, 'email' => 'emil@test.com', 'username' => 'emil'));
$type->addDocument($doc);
$doc = new Document(3, array('id' => 3, 'email' => 'ruth@test.com', 'username' => 'ruth'));
$type->addDocument($doc);
// Refresh index
$index->refresh();
$boost = 1.3;
$query_match = new MatchAll();
$query = new ConstantScore();
$query->setQuery($query_match);
$query->setBoost($boost);
$expectedArray = array('constant_score' => array('query' => $query_match->toArray(), 'boost' => $boost));
$this->assertEquals($expectedArray, $query->toArray());
$resultSet = $type->search($query);
$results = $resultSet->getResults();
$this->assertEquals($resultSet->count(), 3);
$this->assertEquals($results[1]->getScore(), 1);
}
示例6: createIndex
/**
* @param bool $rebuild
*/
private function createIndex($rebuild)
{
$maxShardsPerNode = $this->maxShardsPerNode === 'unlimited' ? -1 : $this->maxShardsPerNode;
$args = array('settings' => array('number_of_shards' => $this->shardCount, 'auto_expand_replicas' => $this->replicaCount, 'analysis' => $this->analysisConfigBuilder->buildConfig(), 'refresh_interval' => $this->refreshInterval . 's', 'merge.policy' => $this->mergeSettings, 'routing.allocation.total_shards_per_node' => $maxShardsPerNode));
if ($this->searchAllFields) {
// Use our weighted all field as the default rather than _all which is disabled.
$args['settings']['index.query.default_field'] = 'all';
}
$this->index->create($args, $rebuild);
}
示例7: initialize
/**
* Initialize the ElasticSearch client, and setup settings for the client.
*
* @return void
*/
public function initialize()
{
spl_autoload_register(array($this, 'autoLoad'));
$this->_connectionOptions = array('url' => $this->modx->getOption('sisea.elastic.hostname', null, 'http://127.0.0.1') . ':' . $this->modx->getOption('sisea.elastic.port', null, 9200) . '/');
try {
$this->client = new \Elastica\Client($this->_connectionOptions);
$this->index = $this->client->getIndex(strtolower($this->modx->getOption('sisea.elastic.index', null, 'siplesearchindex')));
if (!$this->index->exists()) {
$indexSetup = $this->modx->getObject('modSnippet', array('name' => 'SimpleSearchElasticIndexSetup'));
if ($indexSetup) {
$indexOptions = $this->modx->fromJSON($this->modx->runSnippet('SimpleSearchElasticIndexSetup'));
} else {
$indexOptions = $this->modx->fromJSON($this->modx->runSnippet('SimpleSearchElasticIndexSetup_default'));
}
$this->index->create($indexOptions, true);
}
} catch (Exception $e) {
$this->modx->log(xPDO::LOG_LEVEL_ERROR, 'Error connecting to ElasticSearch server: ' . $e->getMessage());
}
}
示例8: 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, 'helloworld');
$doc = new Document(1, array('email' => 'test@test.com', 'username' => 'hanswurst', 'test' => array('2', '3', '5')));
$type->addDocument($doc);
// Refresh index
$index->refresh();
$queryString = new QueryString('test*');
$resultSet = $type->search($queryString);
$this->assertEquals(1, $resultSet->count());
}
示例9: 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());
}
示例10: testQuery
public function testQuery()
{
$client = $this->_getClient();
$index = new Index($client, 'test');
$index->create(array(), true);
$type = new Type($index, 'multi_match');
$doc = new Document(1, array('id' => 1, 'name' => 'Rodolfo', 'last_name' => 'Moraes'));
$type->addDocument($doc);
// Refresh index
$index->refresh();
$multiMatch = new MultiMatch();
$query = new Query();
$multiMatch->setQuery('Rodolfo');
$multiMatch->setFields(array('name', 'last_name'));
$query->setQuery($multiMatch);
$resultSet = $index->search($query);
$this->assertEquals(1, $resultSet->count());
$multiMatch->setQuery('Moraes');
$multiMatch->setFields(array('name', 'last_name'));
$query->setQuery($multiMatch);
$resultSet = $index->search($query);
$this->assertEquals(1, $resultSet->count());
}
示例11: setAnalysis
/**
* Apply the analysis factory to the index
*
* @param Index $index
* @param AnalysisFactoryInterface $analysis
*/
public function setAnalysis(Index $index, AnalysisFactoryInterface $analysis)
{
$index->create(array('number_of_shards' => 4, 'number_of_replicas' => 1, 'analysis' => $analysis->build()));
}
示例12: testSearchWithLegacyFilter
/**
* @group functional
*/
public function testSearchWithLegacyFilter()
{
$client = $this->_getClient();
$index = new Index($client, 'test');
$index->create(array(), true);
$type = new Type($index, 'helloworld');
$doc = new Document(1, array('id' => 1, 'email' => 'hans@test.com', 'username' => 'hans', 'test' => array('2', '4', '5')));
$type->addDocument($doc);
$doc = new Document(2, array('id' => 2, 'email' => 'emil@test.com', 'username' => 'emil', 'test' => array('1', '3', '6')));
$type->addDocument($doc);
$doc = new Document(3, array('id' => 3, 'email' => 'ruth@test.com', 'username' => 'ruth', 'test' => array('2', '3', '7')));
$type->addDocument($doc);
$doc = new Document(4, array('id' => 4, 'email' => 'john@test.com', 'username' => 'john', 'test' => array('2', '4', '8')));
$type->addDocument($doc);
// Refresh index
$index->refresh();
$boolQuery = new BoolQuery();
$termQuery1 = new TermQuery(array('test' => '2'));
$boolQuery->addMust($termQuery1);
$resultSet = $type->search($boolQuery);
$this->assertEquals(3, $resultSet->count());
$this->hideDeprecated();
$termFilter = new TermFilter(array('test' => '4'));
$boolQuery->addFilter($termFilter);
$this->showDeprecated();
$resultSet = $type->search($boolQuery);
$this->assertEquals(2, $resultSet->count());
}
示例13: createPlaylistIndex
private function createPlaylistIndex()
{
// Create the index new
$this->trackIndex->create(['number_of_shards' => 4, 'number_of_replicas' => 1, 'analysis' => ['analyzer' => ['indexAnalyzer' => ['type' => 'snowball', 'tokenizer' => 'standard', 'filter' => ['lowercase', 'mySnowball'], 'language' => 'English', 'stopwords' => 'a, the, in'], 'searchAnalyzer' => ['type' => 'custom', 'tokenizer' => 'standard', 'filter' => ['standard', 'lowercase', 'mySnowball']]], 'filter' => ['mySnowball' => ['type' => 'snowball', 'language' => 'English']]]], true);
}
开发者ID:slaparra,项目名称:Training-Elastic-Search-Symfony,代码行数:5,代码来源:CreateElasticSearchTrackIndexCommand.php
示例14: 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());
}
示例15: setUp
protected function setUp()
{
/** @var ElasticaService elasticaService */
$elasticaService = $this->getContainer()->get("revinate_search.elasticsearch_service");
$this->elasticaClient = $elasticaService->getInstance();
$this->index = new \Elastica\Index($this->elasticaClient, View::INDEX_NAME);
if (!$this->index->exists()) {
$this->index->create(array("index.number_of_replicas" => "0", "index.number_of_shards" => "1"));
$this->type = new \Elastica\Type($this->index, View::INDEX_TYPE);
$mappingJson = json_decode(file_get_contents(__DIR__ . "/../data/es/mapping.json"), true);
$mapping = new \Elastica\Type\Mapping($this->type, $mappingJson['properties']);
$this->type->setMapping($mapping);
} else {
$this->type = new \Elastica\Type($this->index, View::INDEX_TYPE);
}
$this->timeSeriesIndex = new \Elastica\Index($this->elasticaClient, StatusLog::INDEX_NAME . self::$timeSeriesTestDateSuffix);
if (!$this->timeSeriesIndex->exists()) {
$this->timeSeriesIndex->create(array("index.number_of_replicas" => "0", "index.number_of_shards" => "1"));
$this->timeSeriesType = new \Elastica\Type($this->timeSeriesIndex, StatusLog::INDEX_TYPE);
$mappingJson = json_decode(file_get_contents(__DIR__ . "/../data/es/statusLogMapping.json"), true);
$mapping = new \Elastica\Type\Mapping($this->timeSeriesType, $mappingJson['properties']);
$this->timeSeriesType->setMapping($mapping);
} else {
$this->timeSeriesType = new \Elastica\Type($this->timeSeriesIndex, StatusLog::INDEX_TYPE);
}
}