Beispiel #1
0
 /**
  * Search into files
  *
  * @param   string      $query      The query
  * @return  array                   The file list
  */
 public function find($query)
 {
     $result = array();
     $hits = $this->_data->find($query);
     foreach ($hits as $hit) {
         $document = $hit->getDocument();
         $result[] = $document->path;
     }
     return $result;
 }
 /**
  * Return a list of posts that are similar to the current post.
  * This is not a very good implementation, so do not expect 
  * amazing results - the term vector is not available for a doc
  * in ZSL, which limits how far you can go!
  *
  * @return array ids 
  */
 public function get_similar_posts($post, $max_recommended = 5)
 {
     Zend_Search_Lucene::setResultSetLimit($max_recommended + 1);
     $title = $post->title;
     $tags = $post->tags;
     $tagstring = '';
     foreach ($tags as $tag) {
         $tagstring .= $tag . ' ';
     }
     $analyser = Zend_Search_Lucene_Analysis_Analyzer::getDefault();
     $tokens = $analyser->tokenize(strtolower($tagstring) . ' ' . strtolower($title));
     $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
     foreach ($tokens as $token) {
         $query->addTerm(new Zend_Search_Lucene_Index_Term($token->getTermText()));
     }
     $hits = $this->_index->find($query);
     $ids = array();
     $counter = 0;
     foreach ($hits as $hit) {
         if ($hit->postid != $post->id) {
             $ids[] = $hit->postid;
             $counter++;
         }
         if ($counter == $max_recommended) {
             break;
         }
     }
     return $ids;
 }
Beispiel #3
0
 /**
  * Execute the query
  *
  * @param string|Zym_Search_Lucene_IQuery $query
  * @param int $resultSetLimit
  * @return array
  */
 public function search($query, $resultSetLimit = null)
 {
     if (!$resultSetLimit) {
         $resultSetLimit = self::$_defaultResultSetLimit;
     }
     Zend_Search_Lucene::setResultSetLimit((int) $resultSetLimit);
     return $this->_searchIndex->find((string) $query);
 }
Beispiel #4
0
 public static function removeFromIndex($term)
 {
     $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('website');
     $searchIndexFolder = $websiteHelper->getPath() . 'cache/' . Widgets_Search_Search::INDEX_FOLDER;
     if (!is_dir($searchIndexFolder)) {
         return false;
     }
     if (!self::initIndex()) {
         return false;
     }
     $hits = self::$_index->find(strval($term));
     if (is_array($hits) && !empty($hits)) {
         foreach ($hits as $hit) {
             self::$_index->delete($hit->id);
         }
         return true;
     }
     return false;
 }
 /**
  * Find, format, return results
  *
  * @param \Zend_Search_Lucene_Interface $index
  * @param string $query
  * @return array
  */
 public function query(\Zend_Search_Lucene_Interface $index, $query)
 {
     $preparedQuery = $this->prepareQuery($query);
     $q = Parser::parse($preparedQuery);
     /* @var $hits \Zend_Search_Lucene_Search_QueryHit[] */
     $hits = $index->find($q, 'type', SORT_REGULAR, SORT_DESC);
     // if no hits are found with an exact phrase, fall back to token search
     if (count($hits) === 0) {
         $q = Parser::parse($query);
         $hits = $index->find($q, 'type', SORT_REGULAR, SORT_ASC);
     }
     $results = array();
     foreach ($hits as $hit) {
         $h = array();
         $h['title'] = $hit->getDocument()->getFieldValue('title');
         $h['url'] = $hit->getDocument()->getFieldValue('url');
         $h['score'] = $hit->score;
         $h['type'] = $hit->getDocument()->getFieldValue('type');
         $results[] = $h;
     }
     return $results;
 }
Beispiel #6
0
 /**
  * Performs a query against the index and returns an array
  * of Zend_Search_Lucene_Search_QueryHit objects.
  * Input is a string or Zend_Search_Lucene_Search_Query.
  *
  * @param mixed $query
  * @return array Zend_Search_Lucene_Search_QueryHit
  * @throws Zend_Search_Lucene_Exception
  */
 public function find($query)
 {
     return $this->_index->find($query);
 }
 /**
  * Find all existing lucene documents based on the parent url
  * @param Zend_Search_Lucene_Interface $index
  * @param AJXP_Node $ajxpNode
  * @return Zend_Search_Lucene_Search_QueryHit
  */
 public function getIndexedChildrenDocuments($index, $ajxpNode)
 {
     // Try getting doc by url
     $testQ = str_replace("/", "AJXPFAKESEP", SystemTextEncoding::toUTF8($ajxpNode->getPath()));
     $pattern = new Zend_Search_Lucene_Index_Term($testQ . '*', 'node_path');
     $query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
     $hits = $index->find($query);
     return $hits;
 }
 /**
  *  finds similar terms
  * @param string $queryStr
  * @param \Zend_Search_Lucene_Interface $index
  * @param integer $prefixLength optionally specify prefix length, default 0
  * @param float $similarity optionally specify similarity, default 0.5
  * @return string[] $similarSearchTerms
  */
 public static function fuzzyFindTerms($queryStr, $index, $prefixLength = 0, $similarity = 0.5)
 {
     if ($index != NULL) {
         \Zend_Search_Lucene_Search_Query_Fuzzy::setDefaultPrefixLength($prefixLength);
         $term = new \Zend_Search_Lucene_Index_Term($queryStr);
         $fuzzyQuery = new \Zend_Search_Lucene_Search_Query_Fuzzy($term, $similarity);
         $hits = $index->find($fuzzyQuery);
         $terms = $fuzzyQuery->getQueryTerms();
         return $terms;
     }
 }
Beispiel #9
0
 /**
  * Execute the search and return the results
  *
  * @param string|Zym_Search_Lucene_IQuery $query
  * @return array
  */
 protected function _executeSearch($query)
 {
     return $this->_searchIndex->find((string) $query);
 }