refresh() public method

Refreshes the index.
public refresh ( ) : Response
return Response Response object
 protected function setUp()
 {
     parent::setUp();
     $this->_index = $this->_createIndex("simple_query_string_test");
     $docs = array(new Document(1, array('make' => 'Gibson', 'model' => 'Les Paul')), new Document(2, array('make' => 'Gibson', 'model' => 'SG Standard')), new Document(3, array('make' => 'Gibson', 'model' => 'SG Supreme')), new Document(4, array('make' => 'Gibson', 'model' => 'SG Faded')), new Document(5, array('make' => 'Fender', 'model' => 'Stratocaster')));
     $this->_index->getType("guitars")->addDocuments($docs);
     $this->_index->refresh();
 }
Beispiel #2
0
 protected function setUp()
 {
     parent::setUp();
     $this->_index = $this->_createIndex("query");
     $docs = array(new Document("1", array("color" => "green", "make" => "ford")), new Document("2", array("color" => "blue", "make" => "volvo")), new Document("3", array("color" => "red", "make" => "ford")), new Document("4", array("color" => "green", "make" => "renault")));
     $this->_index->getType("test")->addDocuments($docs);
     $this->_index->refresh();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->index = $this->_createIndex('test_functionscore');
     $this->type = $this->index->getType('test');
     $this->type->setMapping(array('name' => array('type' => 'string', 'index' => 'not_analyzed'), 'location' => array('type' => 'geo_point'), 'price' => array('type' => 'float')));
     $this->type->addDocument(new Document(1, array('name' => "Mr. Frostie's", 'location' => array('lat' => 32.799605, 'lon' => -117.243027), 'price' => 4.5)));
     $this->type->addDocument(new Document(2, array('name' => "Miller's Field", 'location' => array('lat' => 32.795964, 'lon' => -117.255028), 'price' => 9.5)));
     $this->index->refresh();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->index = $this->_createIndex('test_boostingquery');
     $this->type = $this->index->getType('test');
     $this->type->setMapping(array('name' => array('type' => 'string', 'index' => 'analyzed'), 'price' => array('type' => 'float')));
     $this->sampleData = array(array("name" => "Vital Lama", "price" => 5.2), array("name" => "Vital Match", "price" => 2.1), array("name" => "Mercury Vital", "price" => 7.5), array("name" => "Fist Mercury", "price" => 3.8), array("name" => "Lama Vital 2nd", "price" => 3.2));
     foreach ($this->sampleData as $key => $value) {
         $this->type->addDocument(new Document($key, $value));
     }
     $this->index->refresh();
 }
Beispiel #5
0
 protected function setUp()
 {
     parent::setUp();
     $this->_index1 = $this->_createIndex('indices_filter_1');
     $this->_index2 = $this->_createIndex('indices_filter_2');
     $this->_index1->addAlias("indices_filter");
     $this->_index2->addAlias("indices_filter");
     $docs = array(new Document("1", array("color" => "blue")), new Document("2", array("color" => "green")), new Document("3", array("color" => "blue")), new Document("4", array("color" => "yellow")));
     $this->_index1->getType("test")->addDocuments($docs);
     $this->_index2->getType("test")->addDocuments($docs);
     $this->_index1->refresh();
     $this->_index2->refresh();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->_index = $this->_createIndex('test_suggest_phrase');
     $docs = array();
     $docs[] = new Document(1, array('text' => 'Github is pretty cool'));
     $docs[] = new Document(2, array('text' => 'Elasticsearch is bonsai cool'));
     $docs[] = new Document(3, array('text' => 'This is a test phrase'));
     $docs[] = new Document(4, array('text' => 'Another sentence for testing'));
     $docs[] = new Document(5, array('text' => 'Some more words here'));
     $type = $this->_index->getType(self::TEST_TYPE);
     $type->addDocuments($docs);
     $this->_index->refresh();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->_index = $this->_createIndex('test_suggest');
     $docs = array();
     $docs[] = new Document(1, array('id' => 1, 'text' => 'GitHub'));
     $docs[] = new Document(2, array('id' => 1, 'text' => 'Elastic'));
     $docs[] = new Document(3, array('id' => 1, 'text' => 'Search'));
     $docs[] = new Document(4, array('id' => 1, 'text' => 'Food'));
     $docs[] = new Document(5, array('id' => 1, 'text' => 'Flood'));
     $docs[] = new Document(6, array('id' => 1, 'text' => 'Folks'));
     $type = $this->_index->getType(self::TEST_TYPE);
     $type->addDocuments($docs);
     $this->_index->refresh();
 }
 /**
  * @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' => '*****@*****.**', 'username' => 'hans', 'test' => array('2', '3', '5')));
     $type->addDocument($doc);
     $doc = new Document(2, array('id' => 2, 'email' => '*****@*****.**', 'username' => 'emil', 'test' => array('1', '3', '6')));
     $type->addDocument($doc);
     $doc = new Document(3, array('id' => 3, 'email' => '*****@*****.**', '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());
 }
 /**
  * Dump everything from the live index into the one being worked on.
  *
  * @param int $processes
  * @param int $refreshInterval
  * @param int $retryAttempts
  * @param int $chunkSize
  * @param float $acceptableCountDeviation
  */
 public function reindex($processes = 1, $refreshInterval = 1, $retryAttempts = 5, $chunkSize = 100, $acceptableCountDeviation = 0.05)
 {
     global $wgCirrusSearchWikimediaExtraPlugin;
     // Set some settings that should help io load during bulk indexing.  We'll have to
     // optimize after this to consolidate down to a proper number of shards but that is
     // is worth the price.  total_shards_per_node will help to make sure that each shard
     // has as few neighbors as possible.
     $settings = $this->index->getSettings();
     $maxShardsPerNode = $this->decideMaxShardsPerNodeForReindex();
     $settings->set(array('refresh_interval' => -1, 'merge.policy.segments_per_tier' => 40, 'merge.policy.max_merge_at_once' => 40, 'routing.allocation.total_shards_per_node' => $maxShardsPerNode));
     $sender = new DataSender($this->connection);
     $frozenIndexes = $this->connection->indexToIndexTypes($this->types);
     $sender->freezeIndexes($frozenIndexes);
     if ($processes > 1) {
         if (!isset($wgCirrusSearchWikimediaExtraPlugin['id_hash_mod_filter']) || !$wgCirrusSearchWikimediaExtraPlugin['id_hash_mod_filter']) {
             $this->error("Can't use multiple processes without \$wgCirrusSearchWikimediaExtraPlugin[ 'id_hash_mod_filter' ] = true", 1);
         }
         $fork = new ForkController($processes);
         $forkResult = $fork->start();
         // we don't want to share sockets between forks, so destroy the client.
         $this->connection->destroyClient();
         // destroying the client resets the timeout so we have to reinstate it.
         $this->setConnectionTimeout();
         switch ($forkResult) {
             case 'child':
                 foreach ($this->types as $i => $type) {
                     $oldType = $this->oldTypes[$i];
                     $this->reindexInternal($type, $oldType, $processes, $fork->getChildNumber(), $chunkSize, $retryAttempts);
                 }
                 die(0);
             case 'done':
                 break;
             default:
                 $this->error("Unexpected result while forking:  {$forkResult}", 1);
         }
         $this->outputIndented("Verifying counts...");
         // We can't verify counts are exactly equal because they won't be - we still push updates into
         // the old index while reindexing the new one.
         foreach ($this->types as $i => $type) {
             $oldType = $this->oldTypes[$i];
             $oldCount = (double) $oldType->count();
             $this->index->refresh();
             $newCount = (double) $type->count();
             $difference = $oldCount > 0 ? abs($oldCount - $newCount) / $oldCount : 0;
             if ($difference > $acceptableCountDeviation) {
                 $this->output("Not close enough!  old={$oldCount} new={$newCount} difference={$difference}\n");
                 $this->error('Failed to load index - counts not close enough.  ' . "old={$oldCount} new={$newCount} difference={$difference}.  " . 'Check for warnings above.', 1);
             }
         }
         $this->output("done\n");
     } else {
         foreach ($this->types as $i => $type) {
             $oldType = $this->oldTypes[$i];
             $this->reindexInternal($type, $oldType, 1, 1, $chunkSize, $retryAttempts);
         }
     }
     // Revert settings changed just for reindexing
     $settings->set(array('refresh_interval' => $refreshInterval . 's', 'merge.policy' => $this->mergeSettings));
     $sender->thawIndexes($frozenIndexes);
 }
 /**
  * @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' => '*****@*****.**', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
     $type->addDocument($doc);
     $doc = new Document(1001, array('email' => '*****@*****.**', '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());
 }
 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' => '*****@*****.**', 'username' => 'hans'));
     $type->addDocument($doc);
     $doc = new Document(2, array('id' => 2, 'email' => '*****@*****.**', 'username' => 'emil'));
     $type->addDocument($doc);
     $doc = new Document(3, array('id' => 3, 'email' => '*****@*****.**', '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);
 }
 /**
  * @test
  */
 public function createNewDocumentOnSave()
 {
     $id = 1;
     $data = 'foobar';
     $this->prophesizeGetDocumentThrowsException($id);
     $this->index->refresh()->shouldBeCalled();
     $doc = $this->getDocument($id, $data);
     $this->type->createDocument($this->getCacheId($id), [Cache::VALUE_FIELD => serialize($data)])->shouldBeCalled()->willReturn($doc);
     $this->type->addDocument($doc)->shouldBeCalled();
     self::assertTrue($this->cache->save($id, $data));
 }
 /**
  * @group functional
  */
 public function testSnapshotAndRestore()
 {
     $repositoryName = 'testrepo';
     $location = $this->_snapshotPath . 'backup2';
     // register the repository
     $response = $this->_snapshot->registerRepository($repositoryName, 'fs', array('location' => $location));
     $this->assertTrue($response->isOk());
     // create a snapshot of our test index
     $snapshotName = 'test_snapshot_1';
     $response = $this->_snapshot->createSnapshot($repositoryName, $snapshotName, array('indices' => $this->_index->getName()), true);
     // ensure that the snapshot was created properly
     $this->assertTrue($response->isOk());
     $this->assertArrayHasKey('snapshot', $response->getData());
     $data = $response->getData();
     $this->assertContains($this->_index->getName(), $data['snapshot']['indices']);
     $this->assertEquals(1, sizeof($data['snapshot']['indices']));
     // only the specified index should be present
     $this->assertEquals($snapshotName, $data['snapshot']['snapshot']);
     // retrieve data regarding the snapshot
     $response = $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
     $this->assertContains($this->_index->getName(), $response['indices']);
     // delete our test index
     $this->_index->delete();
     // restore the index from our snapshot
     $response = $this->_snapshot->restoreSnapshot($repositoryName, $snapshotName, array(), true);
     $this->assertTrue($response->isOk());
     $this->_index->refresh();
     $this->_index->optimize();
     // ensure that the index has been restored
     $count = $this->_index->getType('test')->count();
     $this->assertEquals(sizeof($this->_docs), $count);
     // delete the snapshot
     $response = $this->_snapshot->deleteSnapshot($repositoryName, $snapshotName);
     $this->assertTrue($response->isOk());
     // ensure that the snapshot has been deleted
     $this->setExpectedException('Elastica\\Exception\\NotFoundException');
     $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
 }
 public function testSnapshotAndRestore()
 {
     $repositoryName = "test_repository";
     $location = "/tmp/{$repositoryName}";
     // register the repository
     $response = $this->_snapshot->registerRepository($repositoryName, "fs", array("location" => $location));
     $this->assertTrue($response->isOk());
     // create a snapshot of our test index
     $snapshotName = "test_snapshot_1";
     $response = $this->_snapshot->createSnapshot($repositoryName, $snapshotName, array("indices" => $this->_index->getName()), true);
     // ensure that the snapshot was created properly
     $this->assertTrue($response->isOk());
     $this->assertArrayHasKey("snapshot", $response->getData());
     $data = $response->getData();
     $this->assertContains($this->_index->getName(), $data["snapshot"]["indices"]);
     $this->assertEquals(1, sizeof($data["snapshot"]["indices"]));
     // only the specified index should be present
     $this->assertEquals($snapshotName, $data["snapshot"]["snapshot"]);
     // retrieve data regarding the snapshot
     $response = $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
     $this->assertContains($this->_index->getName(), $response["indices"]);
     // delete our test index
     $this->_index->delete();
     // restore the index from our snapshot
     $response = $this->_snapshot->restoreSnapshot($repositoryName, $snapshotName, array(), true);
     $this->assertTrue($response->isOk());
     $this->_index->refresh();
     $this->_index->optimize();
     // ensure that the index has been restored
     $count = $this->_index->getType("test")->count();
     $this->assertEquals(sizeof($this->_docs), $count);
     // delete the snapshot
     $response = $this->_snapshot->deleteSnapshot($repositoryName, $snapshotName);
     $this->assertTrue($response->isOk());
     // ensure that the snapshot has been deleted
     $this->setExpectedException('Elastica\\Exception\\NotFoundException');
     $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
 }
 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' => '*****@*****.**', '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());
 }
Beispiel #16
0
 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' => '*****@*****.**', '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());
 }
Beispiel #17
0
 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());
 }
Beispiel #18
0
 public function testMatchDoc()
 {
     $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);
     $percolator = new Percolator($index);
     $percolatorName = 'percotest';
     $query = new Term(array('name' => 'ruflin'));
     $response = $percolator->registerQuery($percolatorName, $query);
     $this->assertTrue($response->isOk());
     $this->assertFalse($response->hasError());
     $doc1 = new Document();
     $doc1->set('name', 'ruflin');
     $doc2 = new Document();
     $doc2->set('name', 'nicolas');
     $index = new Index($index->getClient(), '_percolator');
     $index->optimize();
     $index->refresh();
     $matches1 = $percolator->matchDoc($doc1);
     $this->assertTrue(in_array($percolatorName, $matches1));
     $this->assertEquals(1, count($matches1));
     $matches2 = $percolator->matchDoc($doc2);
     $this->assertEmpty($matches2);
 }
Beispiel #19
0
 /**
  * Refreshes the elasticsearch index, should be run after adding
  * or deleting documents.
  *
  * @return \Elastica\Response
  */
 protected function refreshIndex()
 {
     return $this->index->refresh();
 }
 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' => '*****@*****.**', 'content' => 'The Fuzzy Test!'));
     $type->addDocument($doc);
     $doc = new Document(1001, array('email' => '*****@*****.**', '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());
 }
 /**
  * @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' => '*****@*****.**', 'username' => 'hans', 'test' => array('2', '4', '5')));
     $type->addDocument($doc);
     $doc = new Document(2, array('id' => 2, 'email' => '*****@*****.**', 'username' => 'emil', 'test' => array('1', '3', '6')));
     $type->addDocument($doc);
     $doc = new Document(3, array('id' => 3, 'email' => '*****@*****.**', 'username' => 'ruth', 'test' => array('2', '3', '7')));
     $type->addDocument($doc);
     $doc = new Document(4, array('id' => 4, 'email' => '*****@*****.**', '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());
 }