Skip to content

Instantly share code, notes, and snippets.

@damour
Created July 12, 2013 12:34
Show Gist options
  • Select an option

  • Save damour/5984125 to your computer and use it in GitHub Desktop.

Select an option

Save damour/5984125 to your computer and use it in GitHub Desktop.
lucene
$luceneQueryString = sprintf('category_id_l:%s', $categoryId);
$queryObj = new SolrQuery();
$queryObj->setQuery($luceneQueryString);
$queryObj->addSortField("id", SolrQuery::ORDER_DESC);
$offset = Yii::app()->getRequest()->getParam('page', 0);
$queryObj->setStart($offset);
$queryObj->setRows(10);
$queryResponse = Yii::app()->lucene->getSearcher()->query($queryObj);
$result = $queryResponse->getResponse();
$ids = array();
if ($result->response->docs) {
foreach ($result->response->docs as $doc) {
$ids[] = $doc['id'];
}
} else {
//throw new CException('lol no products');
}
$productArray = Yii::app()->productCollection->loadByIds($ids)->getLastLoadedProducts();
$dataProvider = new CArrayDataProvider($productArray, array('keyField' => 'product_id'));
$pagination = new CPagination($result->response->numFound);
$this->renderPartial('_products',
array(
'pagination' => $pagination,
'dataProvider' => $dataProvider,
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment