private function applyOptions(ESphinxSearchCriteria $queryCriteria)
 {
     if ($queryCriteria->booleanSimplify !== null) {
         $this->sphinxClient->SetQueryFlag('boolean_simplify', $queryCriteria->booleanSimplify);
     }
     if (($revScan = $queryCriteria->getReverseScan()) !== null) {
         $this->sphinxClient->SetQueryFlag('reverse_scan', $revScan ? 1 : 0);
     }
     if (($sortMode = $queryCriteria->getSortMethod()) !== null) {
         $this->sphinxClient->SetQueryFlag('sort_method', $sortMode);
     }
     if ($queryCriteria->globalIdf !== null) {
         $this->sphinxClient->SetQueryFlag('global_idf', $queryCriteria->globalIdf);
     }
     if (($idf = $queryCriteria->getIdf()) !== null) {
         $this->sphinxClient->SetQueryFlag('idf', $idf);
     }
 }
 public function testExtendedSort()
 {
     $sphinx = $this->createConnection();
     $criteria = new ESphinxSearchCriteria();
     $criteria->sortMode = ESphinxSort::EXTENDED;
     $criteria->addOrder('user_id', 'ASC');
     $criteria->addOrder('id', 'DESC');
     $query = new ESphinxQuery('', 'article', $criteria);
     $result = $sphinx->executeQuery($query);
     $this->assertEquals($result->getFound(), 5);
     $this->assertEquals($result[0]->id, 1);
     $this->assertEquals($result[1]->id, 2);
     $this->assertEquals($result[2]->id, 3);
     $this->assertEquals($result[3]->id, 5);
     $this->assertEquals($result[4]->id, 4);
 }
 public function testIndexWeights()
 {
     $criteria = new ESphinxSearchCriteria();
     try {
         $criteria->addIndexWeight('', '');
         $this->setExpectedException('ESphinxException');
     } catch (Exception $e) {
         $this->assertInstanceOf('ESphinxException', $e);
     }
     try {
         $criteria->addIndexWeight('index', '123');
         $this->setExpectedException('ESphinxException');
     } catch (Exception $e) {
         $this->assertInstanceOf('ESphinxException', $e);
     }
     try {
         $criteria->addIndexWeight('index', 123.0);
         $this->setExpectedException('ESphinxException');
     } catch (Exception $e) {
         $this->assertInstanceOf('ESphinxException', $e);
     }
     $criteria->addIndexWeight('index', 123);
     $criteria->addIndexWeight('index2', 123);
     $this->assertEquals($criteria->getIndexWeights(), array('index' => 123, 'index2' => 123));
     $criteria->cleanIndexWeights();
     $this->assertEquals($criteria->getIndexWeights(), array());
     $criteria->addIndexWeights(array('index' => 123, 'index2' => 123));
     $this->assertEquals($criteria->getIndexWeights(), array('index' => 123, 'index2' => 123));
 }
 private function applyOptions(ESphinxQlCriteria $criteria, ESphinxSearchCriteria $queryCriteria)
 {
     $options = array();
     if ($queryCriteria->maxMatches !== null) {
         $options['max_matches'] = $queryCriteria->maxMatches;
     }
     if ($queryCriteria->cutOff !== null) {
         $options['cutoff'] = $queryCriteria->cutOff;
     }
     if ($idxWeights = $queryCriteria->getIndexWeights()) {
         $options['index_weights'] = '(' . $this->implodeKV($idxWeights, '=') . ')';
     }
     if ($fieldsWeights = $queryCriteria->getFieldWeights()) {
         $options['field_weights'] = '(' . $this->implodeKV($fieldsWeights, '=') . ')';
     }
     if ($queryCriteria->comment) {
         $options['comment'] = $queryCriteria->comment;
     }
     if ($queryCriteria->booleanSimplify !== null) {
         $options['boolean_simplify'] = $queryCriteria->booleanSimplify;
     }
     if (($revScan = $queryCriteria->getReverseScan()) !== null) {
         $options['reverse_scan'] = $revScan ? 1 : 0;
     }
     if (($sortMode = $queryCriteria->getSortMethod()) !== null) {
         $options['sort_method'] = $sortMode;
     }
     if ($queryCriteria->globalIdf !== null) {
         $options['global_idf'] = $queryCriteria->globalIdf;
     }
     if (($idf = $queryCriteria->getIdf()) !== null) {
         $options['idf'] = $idf;
     }
     $options['max_query_time'] = $queryCriteria->queryTimeout !== null ? $queryCriteria->queryTimeout : $this->queryTimeout;
     // ranking mode
     if ($queryCriteria->rankingMode) {
         $ranker = ESphinxRank::item($queryCriteria->rankingMode);
         if ($queryCriteria->rankingMode != ESphinxRank::EXPR) {
             $options['ranker'] = $ranker;
         } else {
             $options['ranker'] = $ranker . "('" . $queryCriteria->rankingExpression . "')";
         }
     }
     $criteria->option = $this->implodeKV($options, '=');
 }