Elastica\Search::getPath PHP Méthode

getPath() public méthode

Combines indices and types to the search request path.
public getPath ( ) : string
Résultat string Search path
    public function getPath()
    {
        if (isset($this->_options[self::OPTION_SCROLL_ID])) {
            return '_search/scroll';
        }
        $indices = $this->getIndices();
        $path = '';
        $types = $this->getTypes();
        if (empty($indices)) {
            if (!empty($types)) {
                $path .= '_all';
            }
        } else {
            $path .= implode(',', $indices);
        }
        if (!empty($types)) {
            $path .= '/' . implode(',', $types);
        }
        // Add full path based on indices and types -> could be all
        return $path . '/_search';
    }

Usage Example

Exemple #1
0
 /**
  * @group functional
  */
 public function testGetPath()
 {
     $client = $this->_getClient();
     $search1 = new Search($client);
     $search2 = new Search($client);
     $index1 = $this->_createIndex();
     $index2 = $this->_createIndex();
     $type1 = $index1->getType('type1');
     $type2 = $index1->getType('type2');
     // No index
     $this->assertEquals('/_search', $search1->getPath());
     // Only index
     $search1->addIndex($index1);
     $this->assertEquals($index1->getName() . '/_search', $search1->getPath());
     // MUltiple index, no types
     $search1->addIndex($index2);
     $this->assertEquals($index1->getName() . ',' . $index2->getName() . '/_search', $search1->getPath());
     // Single type, no index
     $search2->addType($type1);
     $this->assertEquals('_all/' . $type1->getName() . '/_search', $search2->getPath());
     // Multiple types
     $search2->addType($type2);
     $this->assertEquals('_all/' . $type1->getName() . ',' . $type2->getName() . '/_search', $search2->getPath());
     // Combine index and types
     $search2->addIndex($index1);
     $this->assertEquals($index1->getName() . '/' . $type1->getName() . ',' . $type2->getName() . '/_search', $search2->getPath());
 }