Created
July 12, 2013 12:34
-
-
Save damour/5984125 to your computer and use it in GitHub Desktop.
lucene
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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