From 65ce2585789590732a1f14a7b917a637ecb4dc9e Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 3 Sep 2012 16:20:22 +0200 Subject: [PATCH] ENHANCEMENT Custom query params support in SolrIndex->search() --- code/solr/SolrIndex.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/code/solr/SolrIndex.php b/code/solr/SolrIndex.php index e023b02..f0baea4 100644 --- a/code/solr/SolrIndex.php +++ b/code/solr/SolrIndex.php @@ -169,8 +169,16 @@ abstract class SolrIndex extends SearchIndex { Solr::service(get_class($this))->commit(false, false, false); } - public function search($query, $offset = -1, $limit = -1) { - $service = Solr::service(get_class($this)); + /** + * @param SearchQuery $query + * @param integer $offset + * @param integer $limit + * @param Array $params Extra request parameters passed through to Solr + * @return ArrayData Map with the following keys: + * - 'Matches': ArrayList of the matched object instances + */ + public function search(SearchQuery $query, $offset = -1, $limit = -1, $params = array()) { + $service = $this->getService(); SearchVariant::with(count($query->classes) == 1 ? $query->classes[0]['class'] : null)->call('alterQuery', $query, $this); @@ -266,7 +274,15 @@ abstract class SolrIndex extends SearchIndex { if ($limit == -1) $limit = $query->limit; if ($limit == -1) $limit = SearchQuery::$default_page_size; - $res = $service->search($q ? implode(' ', $q) : '*:*', $offset, $limit, array('fq' => implode(' ', $fq)), Apache_Solr_Service::METHOD_POST); + $params = array_merge($params, array('fq' => implode(' ', $fq))); + + $res = $service->search( + $q ? implode(' ', $q) : '*:*', + $offset, + $limit, + $params, + Apache_Solr_Service::METHOD_POST + ); $results = new ArrayList();