From 94ce1c5a74b051edaedf0f983c65a071baad2d53 Mon Sep 17 00:00:00 2001 From: Gordon Franke Date: Wed, 7 Jul 2010 15:37:05 +0200 Subject: [PATCH 1/5] remove require_once problems with symlinked plugins and not needed --- lib/task/sfLuceneBaseTask.class.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/task/sfLuceneBaseTask.class.php b/lib/task/sfLuceneBaseTask.class.php index b219acb..0001af0 100644 --- a/lib/task/sfLuceneBaseTask.class.php +++ b/lib/task/sfLuceneBaseTask.class.php @@ -8,9 +8,6 @@ * file that was distributed with this source code. */ -require_once(dirname(__FILE__).'/../sfLucene.class.php'); -require_once(dirname(__FILE__).'/../../../../config/ProjectConfiguration.class.php'); - /** * This class represents a base task for all sfLucene tasks. * @@ -45,4 +42,4 @@ protected function setupEventDispatcher($search) new sfLuceneEventConnectorLogger($source, 'lucene.log', $target, 'command.log', $formatter, 'Lucene'); new sfLuceneEventConnectorLogger($source, 'indexer.log', $target, 'command.log', $formatter, 'Indexer'); } -} \ No newline at end of file +} From 111ed917c8aa82cc0814d918013af32fc2b44ba5 Mon Sep 17 00:00:00 2001 From: Gordon Franke Date: Thu, 8 Jul 2010 15:24:05 +0200 Subject: [PATCH 2/5] change to Doctrine_Core and fix getFetchRecord for doctrine --- lib/indexer/sfLuceneDoctrineIndexerHandler.class.php | 2 +- lib/results/sfLuceneDoctrineResult.class.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/indexer/sfLuceneDoctrineIndexerHandler.class.php b/lib/indexer/sfLuceneDoctrineIndexerHandler.class.php index 08dde4a..9b00d4f 100644 --- a/lib/indexer/sfLuceneDoctrineIndexerHandler.class.php +++ b/lib/indexer/sfLuceneDoctrineIndexerHandler.class.php @@ -52,7 +52,7 @@ public function rebuildModel($name, $start_page = null, $limit = null) public function getBaseQuery($model) { - $table = Doctrine::getTable($model); + $table = Doctrine_Core::getTable($model); if(method_exists($table, 'getLuceneQuery')) { diff --git a/lib/results/sfLuceneDoctrineResult.class.php b/lib/results/sfLuceneDoctrineResult.class.php index 302d803..ddbc0bd 100644 --- a/lib/results/sfLuceneDoctrineResult.class.php +++ b/lib/results/sfLuceneDoctrineResult.class.php @@ -30,8 +30,9 @@ public function getFetchRecord() { $model = $this->getInternalModel(); $id = $this->getId(); - - return Doctrine::getTable($model)->findOne($id); + + return Doctrine_Core::getTable($model) + ->find($id); } /** @@ -44,7 +45,7 @@ public function getFetchArray() $model = $this->getInternalModel(); $id = $this->getId(); - $results = Doctrine::getTable($model) + $results = Doctrine_Core::getTable($model) ->createQuery() ->where('id = ?', $id) ->limit(1) From 26c9220afff591995d8da94132393b923fd73754 Mon Sep 17 00:00:00 2001 From: Gordon Franke Date: Fri, 9 Jul 2010 09:46:30 +0200 Subject: [PATCH 3/5] use real form name instate of hardcoded name --- modules/sfLucene/lib/BasesfLuceneActions.class.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/sfLucene/lib/BasesfLuceneActions.class.php b/modules/sfLucene/lib/BasesfLuceneActions.class.php index 7dcca5d..1c725a3 100644 --- a/modules/sfLucene/lib/BasesfLuceneActions.class.php +++ b/modules/sfLucene/lib/BasesfLuceneActions.class.php @@ -41,7 +41,7 @@ public function executeSearch($request) $form = new sfLuceneSimpleForm(); $this->configureCategories($form); - $form->bind($request->getParameter('form', array())); + $form->bind($request->getParameter($form->getName(), array())); $this->form = $form; @@ -121,13 +121,12 @@ public function executeAdvanced($request) $this->form = $form; // continue only if there was a submit - if (!$request->getParameter('form')) + if (!$request->getParameter($form->getName())) { - return sfView::SUCCESS; } - $form->bind($request->getParameter('form')); + $form->bind($request->getParameter($form->getName())); $values = $form->getValues(); From 1b4f25b56edb4b3de7e7f0862540cb31c8a54bd8 Mon Sep 17 00:00:00 2001 From: Gordon Franke Date: Fri, 9 Jul 2010 10:06:32 +0200 Subject: [PATCH 4/5] add search task --- lib/task/sfLuceneSearchTask.class.php | 104 ++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 lib/task/sfLuceneSearchTask.class.php diff --git a/lib/task/sfLuceneSearchTask.class.php b/lib/task/sfLuceneSearchTask.class.php new file mode 100644 index 0000000..16e4785 --- /dev/null +++ b/lib/task/sfLuceneSearchTask.class.php @@ -0,0 +1,104 @@ + + */ +class sfLuceneSearchTask extends sfBaseTask +{ + /** + * @see sfTask + */ + protected function configure() + { + // add your own arguments here + $this->addArguments(array( + new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'), + new sfCommandArgument('query', sfCommandArgument::REQUIRED, 'The query string'), + )); + + $this->addOptions(array( + new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), + new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', null), + new sfCommandOption('index', null, sfCommandOption::PARAMETER_REQUIRED, 'The index name', null), + new sfCommandOption('culture', null, sfCommandOption::PARAMETER_REQUIRED, 'The culture string', null), + new sfCommandOption('start', null, sfCommandOption::PARAMETER_REQUIRED, 'The search offset', 0), + new sfCommandOption('limit', null, sfCommandOption::PARAMETER_REQUIRED, 'The search limit', 10), + )); + + $this->namespace = 'lucene'; + $this->name = 'search'; + $this->briefDescription = 'search in solr'; + $this->detailedDescription = <<addPhrase($query) + ->setOffset($options['start']) + ->setLimit($options['limit']); + + // walk over the indexes + foreach($config as $index => $indexConfig) + { + // check culture + $cultures = $indexConfig['index']['cultures']; + if ($options['culture'] !== null) + { + if (!in_array($options['culture'], $cultures)) + { + //TODO: change to log error + throw new Exception(sprintf('Culture %s is not configurate for index %s', $options['culture'], $index)); + } + $cultures = array($options['culture']); + } + + $this->log(sprintf('search for `%s` from %u to %u', $query, $options['start'], $options['limit'])); + + // walk over the cultures + foreach($cultures as $culture) + { + // get lucene instance and retrieve the results + $results = sfLucene::getInstance($index, $culture) + ->friendlyFind($criteria); + + $this->log(sprintf('found %u results in index `%s` with culture `%s`', count($results), $index, $culture)); + + foreach ($results as $result) + { + $this->logSection('result ', sprintf('%s %s (%u%%)', $result->getInternalModel(), $result->getInternalTitle(), $result->getScore())); + } + } + } + } +} From 3e7e9d881be39e8d848ffdeb0cc55b4cfe7a339f Mon Sep 17 00:00:00 2001 From: Gordon Franke Date: Fri, 11 Feb 2011 20:52:14 +0100 Subject: [PATCH 5/5] add query param to noresult template --- modules/sfLucene/lib/BasesfLuceneActions.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/sfLucene/lib/BasesfLuceneActions.class.php b/modules/sfLucene/lib/BasesfLuceneActions.class.php index 1c725a3..00bd6f5 100644 --- a/modules/sfLucene/lib/BasesfLuceneActions.class.php +++ b/modules/sfLucene/lib/BasesfLuceneActions.class.php @@ -77,10 +77,12 @@ public function executeSearch($request) $pager = new sfLucenePager($this->getLuceneInstance()->friendlyFind($query)); + $this->query = $values['query']; + // were any results returned? if ($pager->getNbResults() == 0) { - // display error + // display error $this->setTitleI18n('No Results Found'); $this->setTemplate('searchNoResults'); @@ -92,7 +94,6 @@ public function executeSearch($request) $pager = $this->configurePager($pager, $form); $this->pager = $pager; - $this->query = $values['query']; $this->setTitleNumResults($pager);