setSource() публичный Метод

To disable source, argument is array('enabled' => false)
public setSource ( array $source )
$source array Source array
 /**
  * @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());
 }
Пример #2
0
 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
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());
 }
Пример #4
0
 /**
  * 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();
 }
 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());
 }