public function testOrderModeExtended() { $criteria = new ESphinxSearchCriteria(); $criteria->sortMode = ESphinxSort::EXTENDED; try { $criteria->addOrder('', ''); $this->setExpectedException('ESphinxException'); } catch (Exception $e) { $this->assertInstanceOf('ESphinxException', $e); } try { $criteria->addOrder('field', 'OSC'); $this->setExpectedException('ESphinxException'); } catch (Exception $e) { $this->assertInstanceOf('ESphinxException', $e); } $criteria->addOrder('field1', 'asc'); $criteria->addOrder('field2', 'DESC'); $this->assertEquals($criteria->getOrders(), array('field1' => 'ASC', 'field2' => 'DESC')); $criteria->cleanOrders(); $this->assertEquals($criteria->getOrders(), array()); $criteria->addOrders(array('field1' => 'asc', 'field2' => 'desc')); $this->assertEquals($criteria->getOrders(), array('field1' => 'ASC', 'field2' => 'DESC')); }
private function applyOrder(ESphinxQlCriteria $criteria, ESphinxSearchCriteria $queryCriteria) { $order = null; if ($queryCriteria->sortMode == ESphinxSort::EXTENDED) { if ($orderArray = $queryCriteria->getOrders()) { $order = $this->implodeKV($orderArray); } } else { if ($queryCriteria->getSortBy()) { $order = $queryCriteria->getSortBy() . ' '; switch ($queryCriteria->sortMode) { case ESphinxSort::ATTR_ASC: $order .= 'ASC'; break; case ESphinxSort::ATTR_DESC: $order .= 'DESC'; break; case ESphinxSort::RELEVANCE: $order = '@weight DESC'; break; default: throw new ESphinxException('Not implemented for Sphinx Ql connection'); } } } if ($order) { if ($queryCriteria->groupBy) { $criteria->withinGroupOrder = $order; } else { $criteria->order = $order; } } }