Beispiel #1
0
 protected function useSearchIndex($slug)
 {
     if (!dmConfig::get('smart_404')) {
         return false;
     }
     try {
         $searchIndex = $this->serviceContainer->get('search_engine')->getCurrentIndex();
         $queryString = str_replace('/', ' ', dmString::unSlugify($slug));
         $query = Zend_Search_Lucene_Search_QueryParser::parse($queryString);
         $results = $searchIndex->search($query);
         $foundPage = null;
         foreach ($results as $result) {
             if ($result->getScore() > 0.5) {
                 if ($foundPage = $result->getPage()) {
                     break;
                 }
             } else {
                 break;
             }
         }
         if ($foundPage) {
             return $this->serviceContainer->getService('helper')->link($foundPage)->getHref();
         }
     } catch (Exception $e) {
         $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Can not use search index to find redirection for slug ' . $slug, sfLogger::ERR)));
         if (sfConfig::get('dm_debug')) {
             throw $e;
         }
     }
 }
 public static function searchLuceneWithValues(Doctrine_Table $table, $luceneQueryString, $culture = null)
 {
     // Ugh: UTF8 Lucene is case sensitive work around this
     if (function_exists('mb_strtolower')) {
         $luceneQueryString = mb_strtolower($luceneQueryString);
     } else {
         $luceneQueryString = strtolower($luceneQueryString);
     }
     // We have to register the autoloader before we can use these classes
     self::registerZend();
     $luceneQuery = Zend_Search_Lucene_Search_QueryParser::parse($luceneQueryString);
     $query = new Zend_Search_Lucene_Search_Query_Boolean();
     $query->addSubquery($luceneQuery, true);
     if (!is_null($culture)) {
         $culture = self::normalizeCulture($culture);
         $cultureTerm = new Zend_Search_Lucene_Index_Term($culture, 'culture');
         // Oops, this said $aTerm before. Thanks to Quentin Dugauthier
         $cultureQuery = new Zend_Search_Lucene_Search_Query_Term($cultureTerm);
         $query->addSubquery($cultureQuery, true);
     }
     $index = $table->getLuceneIndex();
     $hits = $index->find($query);
     $ids = array();
     foreach ($hits as $hit) {
         $ids[$hit->primarykey] = $hit;
     }
     return $ids;
 }
 /**
  * Method to perform a search. This function returns results from Zend_Lucene_Search
  * and is unpolished as it doesn't check permission issues, etc.
  * 
  * @access private
  * @param string $text Text to search for
  * @param string $module Module to search items for
  * @param string $context Context in which to search
  * @param array $extra Any additional items
  * @return object
  */
 private function search($text, $module = NULL, $context = NULL, $extra = array())
 {
     $objIndexData = $this->getObject('indexdata');
     $indexer = $objIndexData->checkIndexPath();
     // Some cllean up till we can find a better way
     $phrase = trim(str_replace(':', ' ', $text));
     $phrase = trim(str_replace('+', ' ', $phrase));
     $phrase = trim(str_replace('-', ' ', $phrase));
     if ($module != NULL) {
         if ($text != '') {
             $phrase .= ' AND ';
         }
         $phrase .= ' module:' . $module . ' ';
     }
     if ($context != NULL) {
         if ($phrase != '') {
             $phrase .= ' AND ';
         }
         $phrase .= ' context:' . $context . ' ';
     }
     if (is_array($extra) && count($extra) > 0) {
         foreach ($extra as $item => $value) {
             if ($phrase != '') {
                 $phrase .= ' AND ';
             }
             $phrase .= $item . ':' . $value . ' ';
         }
     }
     //echo $phrase;
     $query = Zend_Search_Lucene_Search_QueryParser::parse($phrase);
     return $indexer->find($query);
 }
Beispiel #4
0
 public function index($msg = NULL)
 {
     $results = NULL;
     $results2 = NULL;
     $query = NULL;
     $view = new View('search_example');
     $view->bind("results", $results)->bind("results2", $results2)->bind("query", $query)->bind("msg", $msg);
     if (!empty($_GET["q"])) {
         try {
             $query = $_GET["q"];
             $form = $_GET["form"];
             if ($form == "artists") {
                 $results = Search::instance()->find($query);
             } else {
                 Search::instance()->load_search_libs();
                 $query = Zend_Search_Lucene_Search_QueryParser::parse($query);
                 $hits = Search::instance()->find($query);
                 if (sizeof($hits) > 0) {
                     $results2 = $query->highlightMatches(iconv('UTF-8', 'ASCII//TRANSLIT', $hits[0]->body));
                 } else {
                     $results2 = '<p style="color:#f00">No results found</p>';
                 }
             }
         } catch (Exception $e) {
             Kohana::log("error", $e);
         }
     }
     $view->render(TRUE);
 }
Beispiel #5
0
 public function actionIndex()
 {
     $this->webpageType = 'SearchResultsPage';
     $type = '';
     if (isset($_GET['type'])) {
         $type = $_GET['type'];
     }
     if (isset($_GET['q'])) {
         //            $originalQuery = $_GET['q'];
         $queryString = $originalQuery = isset($_GET['q']) ? $_GET['q'] : '';
         $index = new Zend_Search_Lucene($this->_indexFile);
         //only look for queryString in title and content, well if advanced search techniques aren't used
         if (!(strpos(strtolower($queryString), 'and') || strpos(strtolower($queryString), 'or') || strpos(strtolower($queryString), ':'))) {
             $queryString = "title:{$queryString} OR content:{$queryString}";
         }
         if ($type) {
             $queryString .= ' AND type:' . $type;
         }
         $results = $index->find($queryString);
         $query = Zend_Search_Lucene_Search_QueryParser::parse($queryString);
         $this->render('index', compact('results', 'originalQuery', 'query', 'type'));
     } else {
         $this->render('advanced', array('type' => $type));
     }
 }
 /**
  * Adds a string that is parsed into Zend API queries
  * @param string $query The query to parse
  * @param string $encoding The encoding to parse query as
  * 
  * @return sfLuceneCriteria
  */
 public function addString($query, $encoding = null, $type = true)
 {
     $this->search->configure();
     // setup query parser
     $this->add(Zend_Search_Lucene_Search_QueryParser::parse($query, $encoding), $type);
     return $this;
 }
 public function search($keywords, $charset = 'utf-8')
 {
     $index = new Zend_Search_Lucene(ZY_ROOT . '/index');
     $query = Zend_Search_Lucene_Search_QueryParser::parse($keywords, $charset);
     $hits = $index->find($query);
     return $hits;
 }
 /**
  * Process and render search results. Uses the Lucene_results.ss template to
  * render the form.
  * 
  * @access public
  * @param   array           $data       The raw request data submitted by user
  * @param   Form            $form       The form instance that was submitted
  * @param   SS_HTTPRequest  $request    Request generated for this action
  * @return  String                      The rendered form, for inclusion into the page template.
  */
 public function ZendSearchLuceneResults($data, $form, $request)
 {
     $querystring = $form->Fields()->dataFieldByName('Search')->dataValue();
     $query = Zend_Search_Lucene_Search_QueryParser::parse($querystring);
     $hits = ZendSearchLuceneWrapper::find($query);
     $data = $this->getDataArrayFromHits($hits, $request);
     return $this->owner->customise($data)->renderWith(array('Lucene_results', 'Page'));
 }
Beispiel #9
0
 public function searchTag($tag, $value)
 {
     if (!$this->_enabled) {
         return array();
     }
     Zend_Search_Lucene::setDefaultSearchField($tag);
     $query = Zend_Search_Lucene_Search_QueryParser::parse($value);
     return $this->_index->find($query);
 }
 private function search($terms)
 {
     Yii::import('application.vendor.*');
     require_once 'Zend/Search/Lucene.php';
     $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.index'));
     $result = $index->find($terms);
     $query = Zend_Search_Lucene_Search_QueryParser::parse($terms);
     return $result;
 }
 //    public function init(){
 //       Yii::import('application.vendors.*');
 //       require_once('Zend/Search/Lucene.php');
 //       parent::init();
 //   }
 public function actionSearch()
 {
     $this->layout = 'column2';
     if (($term = Yii::app()->getRequest()->getParam('q', null)) !== null) {
         $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
 public function parse($query)
 {
     $query = Zend_Search_Lucene_Search_QueryParser::parse($query, 'UTF-8');
     if ($query instanceof Zend_Search_Lucene_Search_Query_Insignificant) {
         throw new Exception('No search terms specified.');
     } elseif ($query instanceof Zend_Search_Lucene_Search_Query_MultiTerm) {
         throw new Exception('Error parsing search terms.');
     }
     return $query;
 }
Beispiel #13
0
 public function searchAction()
 {
     if ($this->_request->isPost() && Digitalus_Filter_Post::has('submitSearchForm')) {
         $index = Zend_Search_Lucene::open('./application/modules/search/data/index');
         $queryString = Digitalus_Filter_Post::get('keywords');
         $query = Zend_Search_Lucene_Search_QueryParser::parse($queryString);
         $this->view->searchResults = $index->find($query);
         $this->view->keywords = $queryString;
     }
 }
Beispiel #14
0
 public function testQueryParser()
 {
     $queries = array('title:"The Right Way" AND text:go', 'title:"Do it right" AND right', 'title:Do it right', '"jakarta apache"~10', 'jakarta apache', 'jakarta^4 apache', '"jakarta apache"^4 "Apache Lucene"', '"jakarta apache" jakarta', '"jakarta apache" OR jakarta', '"jakarta apache" || jakarta', '"jakarta apache" AND "Apache Lucene"', '"jakarta apache" && "Apache Lucene"', '+jakarta apache', '"jakarta apache" AND NOT "Apache Lucene"', '"jakarta apache" && !"Apache Lucene"', 'NOT "jakarta apache"', '!"jakarta apache"', '"jakarta apache" -"Apache Lucene"', '(jakarta OR apache) AND website', '(jakarta || apache) && website', 'title:(+return +"pink panther")', 'title:(+re\\turn\\ value +"pink panther\\"" +body:cool)', '+type:1 +id:5', 'type:1 AND id:5', 'f1:word1 f1:word2 and f1:word3', 'f1:word1 not f1:word2 and f1:word3');
     $rewritedQueries = array('+(title:"the right way") +(text:go)', '+(title:"do it right") +(path:right modified:right contents:right)', '(title:do) (path:it modified:it contents:it) (path:right modified:right contents:right)', '((path:"jakarta apache"~10) (modified:"jakarta apache"~10) (contents:"jakarta apache"~10))', '(path:jakarta modified:jakarta contents:jakarta) (path:apache modified:apache contents:apache)', '((path:jakarta modified:jakarta contents:jakarta)^4)^4 (path:apache modified:apache contents:apache)', '((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache"))^4 ((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))', '((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) (path:jakarta modified:jakarta contents:jakarta)', '((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) (path:jakarta modified:jakarta contents:jakarta)', '((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) (path:jakarta modified:jakarta contents:jakarta)', '+((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) +((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))', '+((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) +((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))', '+(path:jakarta modified:jakarta contents:jakarta) (path:apache modified:apache contents:apache)', '+((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) -((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))', '+((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) -((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))', '<EmptyQuery>', '<EmptyQuery>', '((path:"jakarta apache") (modified:"jakarta apache") (contents:"jakarta apache")) -((path:"apache lucene") (modified:"apache lucene") (contents:"apache lucene"))', '+((path:jakarta modified:jakarta contents:jakarta) (path:apache modified:apache contents:apache)) +(path:website modified:website contents:website)', '+((path:jakarta modified:jakarta contents:jakarta) (path:apache modified:apache contents:apache)) +(path:website modified:website contents:website)', '(+(title:return) +(title:"pink panther"))', '(+(+title:return +title:value) +(title:"pink panther") +(body:cool))', '+(<EmptyQuery>) +(<EmptyQuery>)', '+(<EmptyQuery>) +(<EmptyQuery>)', '(f1:word) (+(f1:word) +(f1:word))', '(f1:word) (-(f1:word) +(f1:word))');
     $index = Zend_Search_Lucene::open(dirname(__FILE__) . '/_files/_indexSample');
     foreach ($queries as $id => $queryString) {
         $query = Zend_Search_Lucene_Search_QueryParser::parse($queryString);
         $this->assertTrue($query instanceof Zend_Search_Lucene_Search_Query);
         $this->assertEquals($query->rewrite($index)->__toString(), $rewritedQueries[$id]);
     }
 }
Beispiel #15
0
 function __construct($query)
 {
     $qstr = $query->__toString();
     // query needs the object_type field removing for highlighting
     $qstr = preg_replace('/\\+?\\(\\(object_type.*?\\)\\)/', '', $qstr);
     // this is the only way i can find to remove a term form a query
     $query = Zend_Search_Lucene_Search_QueryParser::parse($qstr, 'UTF-8');
     // rebuild
     $this->query = $query;
     $this->snippetHelper = new Search_ResultSet_SnippetHelper();
 }
 public function actionSearch()
 {
     //working.
     $this->layout = 'column2';
     if (($term = Yii::app()->getRequest()->getParam('q', null)) !== null) {
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
         $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
         $results = $index->find($term);
         $query = Zend_Search_Lucene_Search_QueryParser::parse($term);
         $this->render('search', compact('results', 'term', 'query'));
     }
 }
 public function parse()
 {
     $data = $this->_data;
     $query = Zend_Search_Lucene_Search_QueryParser::parse($data['query']);
     if ('' != $data['pricefrom'] && '' != $data['priceto']) {
         $from = new Zend_Search_Lucene_Index_Term($this->_formatPrice($data['pricefrom']), 'price');
         $to = new Zend_Search_Lucene_Index_Term($this->_formatPrice($data['priceto']), 'price');
         $q = new Zend_Search_Lucene_Search_Query_Range($from, $to, true);
         $query = Zend_Search_Lucene_Search_QueryParser::parse($data['query'] . ' +' . $q);
     }
     return $query;
 }
Beispiel #18
0
 /**
  * php index.php docx search "Licence"
  *
  * @param $phrase
  * @return mixed|void
  */
 public function search($phrase)
 {
     $index = self::open(APP_PATH . '/' . self::INDEX_DIR);
     echo sprintf("Keyword : %s\n\n", $phrase);
     $phrase = iconv('gbk', 'utf-8', $phrase);
     $phrase = Zend_Search_Lucene_Search_QueryParser::parse($phrase, "utf-8");
     $results = $index->find($phrase);
     foreach ($results as $index => $hit) {
         echo sprintf("%s : %s - %s\n", $index, basename($hit->filename), $hit->score);
     }
     echo "\n###Done###\n";
 }
Beispiel #19
0
 public function indexAction()
 {
     if ($this->_request->isPost()) {
         $keywords = $this->_request->getParam('keywords');
         $query = Zend_Search_Lucene_Search_QueryParser::parse($keywords);
         $index = Zend_Search_Lucene::open(APPLICATION_PATH . '/indexes');
         $hits = $index->find($query);
         $this->view->results = $hits;
         $this->view->keywords = $keywords;
     } else {
         $this->view->results = null;
     }
 }
Beispiel #20
0
 public function searchAction()
 {
     $query = $this->getRequest()->getParam('q');
     if ($query) {
         $qo = Zend_Search_Lucene_Search_QueryParser::parse($query);
         $options = $this->getInvokeArg('bootstrap')->getOption('lucene');
         $luceneDir = $options['dir'];
         $index = Zend_Search_Lucene::open($luceneDir);
         $results = $index->find($query);
         $this->view->matches = $results;
         $this->view->query = $qo;
     }
 }
Beispiel #21
0
 public function actionSearch()
 {
     $indexFiles = Yii::app()->getModule('zendsearch')->indexFiles;
     SetLocale(LC_ALL, 'ru_RU.UTF-8');
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
     if (($term = Yii::app()->getRequest()->getQuery('q', null)) !== null) {
         $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $indexFiles));
         $results = $index->find($term);
         $query = Zend_Search_Lucene_Search_QueryParser::parse($term);
         $this->render('search', compact('results', 'term', 'query'));
     }
 }
Beispiel #22
0
 public static function highlightIfSuitable($html, $request_uri, $referer)
 {
     if (self::suitable($request_uri) && ($query = self::query($referer))) {
         $queryObj = Zend_Search_Lucene_Search_QueryParser::parse($query);
         $out = $queryObj->highlightMatches($html);
         if (!$out) {
             return $html;
         }
         $htmlNice = self::joinHtml($html, $out);
         if ($htmlNice) {
             return $htmlNice;
         }
     }
     return $html;
 }
 public function searchAction()
 {
     $searchForm = new Search_Form();
     if ($this->_request->isPost() && $searchForm->isValid($_POST) && Digitalus_Filter_Post::has('submitSearchForm')) {
         $index = Zend_Search_Lucene::open(APPLICATION_PATH . '/modules/search/data/index');
         $queryString = Digitalus_Filter_Post::get('keywords');
         $query = Zend_Search_Lucene_Search_QueryParser::parse($queryString);
         $this->view->searchResults = $index->find($query);
         if (!empty($queryString)) {
             $keywordsElement = $searchForm->getElement('keywords');
             $keywordsElement->setValue($queryString);
         }
     }
     $this->view->form = $searchForm;
 }
Beispiel #24
0
 function searchDocsByContent($q)
 {
     $hits = array();
     try {
         $this->initLuceneEngine();
         $indexer = $this->zend->get_Zend_Search_Lucene();
         $query = new Zend_Search_Lucene_Search_Query_Boolean();
         $subquery = Zend_Search_Lucene_Search_QueryParser::parse('+(' . $q . ')');
         $query->addSubquery($subquery, true);
         // $query->addSubquery(self::makeTermQuery('object_type', JS_TEXT_DATA), true);
         $hits = $indexer->find($query);
         return $hits;
     } catch (Exception $e) {
         echo $e->getTraceAsString();
     }
     return $hits;
 }
 function searchDocsByContent($q, $userid)
 {
     $hits = array();
     try {
         $this->initLuceneEngine();
         $indexer = $this->zend->get_Zend_Search_Lucene();
         echo $indexer->count();
         $query = Zend_Search_Lucene_Search_QueryParser::parse("(title:{$q} OR keywords:{$q} OR content:{$q}) AND userid:{$userid}");
         //            var_dump($query);
         $hits = $indexer->find($query);
     } catch (Exception $e) {
         echo $e->getTraceAsString();
     }
     //  var_dump($indexer);
     // var_dump($hits); exit;
     return $hits;
 }
Beispiel #26
0
 /**
  * DOCUMENT ME
  * @param Doctrine_Table $table
  * @param mixed $luceneQueryString
  * @param mixed $culture
  * @param mixed $andLuceneQuery
  * @return mixed
  */
 public static function searchLuceneWithValues(Doctrine_Table $table, $luceneQueryString, $culture = null, $andLuceneQuery = null)
 {
     // Ugh: UTF8 Lucene is case sensitive work around this
     if (function_exists('mb_strtolower')) {
         $luceneQueryString = mb_strtolower($luceneQueryString);
     } else {
         $luceneQueryString = strtolower($luceneQueryString);
     }
     // We have to register the autoloader before we can use these classes
     self::registerZend();
     // Specify character set. Apostrophe is always UTF-8
     $luceneQuery = Zend_Search_Lucene_Search_QueryParser::parse($luceneQueryString, 'utf-8');
     $query = new Zend_Search_Lucene_Search_Query_Boolean();
     $query->addSubquery($luceneQuery, true);
     if (!is_null($culture)) {
         $culture = self::normalizeCulture($culture);
         $cultureTerm = new Zend_Search_Lucene_Index_Term($culture, 'culture');
         // Oops, this said $aTerm before. Thanks to Quentin Dugauthier
         $cultureQuery = new Zend_Search_Lucene_Search_Query_Term($cultureTerm);
         $query->addSubquery($cultureQuery, true);
     }
     if (!is_null($andLuceneQuery)) {
         $query->addSubquery($andLuceneQuery, true);
     }
     $index = $table->getLuceneIndex();
     $hits = $index->find($query);
     // Never look at more than n results, no matter what. This is necessary
     // to avoid out of memory errors on large sites. We suggest setting this
     // to 1000. Note that if 1,000 locked pages precede the first unlocked page
     // and you are logged out, you could theoretically not get your result. In
     // practice unlocked pages tend to be prominent and come up early. Thanks to
     // recent improvements that avoid holding on to the memory for most of the
     // information about a search result indefinitely you can set this higher
     // than previously
     if (sfConfig::get('app_a_search_hard_limit', false)) {
         $hits = array_splice($hits, 0, sfConfig::get('app_a_search_hard_limit'));
     }
     $ids = array();
     foreach ($hits as $hit) {
         // New way: don't touch anything but $hit->id directly and you won't force a persistent
         // use of memory for the lazy loaded columns http://zendframework.com/issues/browse/ZF-8267
         $ids[$index->getDocument($hit->id)->getFieldValue('primarykey')] = $hit;
     }
     return $ids;
 }
Beispiel #27
0
 /**
  * php index.php db search "City:London"
  * php index.php db search "Tofu"
  * php index.php db search "Seafood"
  *
  * @param $phrase
  * @return mixed|void
  */
 public function search($phrase)
 {
     $index = self::open(APP_PATH . '/' . self::INDEX_DIR);
     echo sprintf("Keyword : %s\n\n", $phrase);
     $phrase = iconv('gbk', 'utf-8', $phrase);
     $phrase = Zend_Search_Lucene_Search_QueryParser::parse($phrase, "utf-8");
     $results = $index->find($phrase);
     foreach ($results as $index => $hit) {
         $fields = $hit->getDocument($hit->id)->getFieldNames();
         echo sprintf("[%s] : Score: %s\n", $hit->id, $hit->score);
         foreach ($fields as $field) {
             if ($field == 'Description' || $field == 'Picture') {
                 continue;
             }
             echo sprintf("%s: %s\n", $field, $hit->{$field});
         }
         echo "----------------------------\n";
     }
 }
Beispiel #28
0
 public function indexAction()
 {
     if (!isset($_POST['search'])) {
         $this->_redirect('/');
     }
     $options = $this->getInvokeArg('bootstrap')->getOptions();
     try {
         $index = Zend_Search_Lucene::open($options['search']['indexPath']);
     } catch (Zend_Search_Lucene_Exception $e) {
         $index = Zend_Search_Lucene::create($options['search']['indexPath']);
     }
     try {
         $query = Zend_Search_Lucene_Search_QueryParser::parse($_POST['search'], 'utf-8');
         $hits = $index->find($_POST['search']);
     } catch (Zend_Search_Lucene_Exception $e) {
         $hits = array();
     }
     $this->view->results = $hits;
 }
Beispiel #29
0
 public function userSearch(Kwf_Component_Data $subroot, $queryString, $offset, $limit, $params = array())
 {
     $index = Kwf_Util_Fulltext_Lucene::getInstance($subroot);
     $error = false;
     $userQuery = false;
     if ($queryString) {
         try {
             $userQuery = Zend_Search_Lucene_Search_QueryParser::parse($queryString);
         } catch (ErrorException $e) {
             //ignore iconv errors that happen with invalid input
         }
     }
     $hits = array();
     if ($userQuery) {
         $query = new Zend_Search_Lucene_Search_Query_Boolean();
         $query->addSubquery($userQuery, true);
         if (isset($params['type'])) {
             $pathTerm = new Zend_Search_Lucene_Index_Term($params['type'], 'type');
             $pathQuery = new Zend_Search_Lucene_Search_Query_Term($pathTerm);
             $query->addSubquery($pathQuery, true);
         }
         $time = microtime(true);
         try {
             $hits = $index->find($query);
         } catch (Zend_Search_Lucene_Exception $e) {
             $error = $subroot->trlKwf('Invalid search terms');
         }
     }
     $ret = array();
     if (count($hits)) {
         $numStart = $offset;
         $numEnd = min(count($hits), $offset + $limit);
         for ($i = $numStart; $i < $numEnd; $i++) {
             $h = $hits[$i];
             $c = Kwf_Component_Data_Root::getInstance()->getComponentById($h->componentId);
             if ($c) {
                 $ret[] = array('data' => $c, 'content' => $h->content);
             }
         }
     }
     return array('error' => $error, 'numHits' => count($hits), 'hits' => $ret);
 }
Beispiel #30
0
 public function search($apiKey, $keywords)
 {
     if (!$this->_validateKey($apiKey)) {
         return array('error' => 'invalid api key', 'status' => false);
     }
     // fetch the index and run the search
     $query = Zend_Search_Lucene_Search_QueryParser::parse($keywords);
     $index = Zend_Search_Lucene::open(APPLICATION_PATH . '/indexes');
     $hits = $index->find($query);
     // build the response array
     if (is_array($hits) && count($hits) > 0) {
         $response['hits'] = count($hits);
         foreach ($hits as $page) {
             $pageObj = new CMS_Content_Item_Page($page->page_id);
             $response['results']['page_' . $page->page_id] = $pageObj->toArray();
         }
     } else {
         $response['hits'] = 0;
     }
 }