当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Search_Lucene_Search_Query_Boolean类代码示例

本文整理汇总了PHP中Zend_Search_Lucene_Search_Query_Boolean的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Search_Query_Boolean类的具体用法?PHP Zend_Search_Lucene_Search_Query_Boolean怎么用?PHP Zend_Search_Lucene_Search_Query_Boolean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Zend_Search_Lucene_Search_Query_Boolean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: rewrite

 public function rewrite(Zend_Search_Lucene_Interface $index)
 {
     if (count($this->_terms) == 0) {
         return new Zend_Search_Lucene_Search_Query_Empty();
     }
     // Check, that all fields are qualified
     $allQualified = true;
     foreach ($this->_terms as $term) {
         if ($term->field === null) {
             $allQualified = false;
             break;
         }
     }
     if ($allQualified) {
         return $this;
     } else {
         $query = new Zend_Search_Lucene_Search_Query_Boolean();
         $query->setBoost($this->getBoost());
         foreach ($this->_terms as $termId => $term) {
             $subquery = new Zend_Search_Lucene_Search_Query_Term($term);
             $query->addSubquery($subquery->rewrite($index), $this->_signs === null ? true : $this->_signs[$termId]);
         }
         return $query;
     }
 }
开发者ID:hackingman,项目名称:TubeX,代码行数:25,代码来源:MultiTerm.php

示例2: execute

 public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $this->resource = $this->getRoute()->resource;
     // Check that this isn't the root
     if (!isset($this->resource->parent)) {
         $this->forward404();
     }
     $search = new QubitSearch();
     $query = new Zend_Search_Lucene_Search_Query_Boolean();
     $query->addSubquery(new Zend_Search_Lucene_Search_Query_Term(new Zend_Search_Lucene_Index_Term($this->resource->id, 'parentId')), true);
     if (isset($request->query)) {
         $query = $request->query;
     }
     $query = QubitAcl::searchFilterByRepository($query, 'read');
     $query = QubitAcl::searchFilterDrafts($query);
     $this->pager = new QubitArrayPager();
     $this->pager->hits = $search->getEngine()->getIndex()->find($query);
     $this->pager->setMaxPerPage($request->limit);
     $this->pager->setPage($request->page);
     $ids = array();
     foreach ($this->pager->getResults() as $hit) {
         $ids[] = $hit->getDocument()->id;
     }
     $criteria = new Criteria();
     $criteria->add(QubitInformationObject::ID, $ids, Criteria::IN);
     $this->informationObjects = QubitInformationObject::get($criteria);
 }
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:30,代码来源:fileListAction.class.php

示例3: searchAction

 public function searchAction()
 {
     $filters = array('q' => array('StringTrim', 'StripTags'));
     $validators = array('q' => array('presence' => 'required'));
     $input = new Zend_Filter_Input($filters, $validators, $_GET);
     if (is_string($this->_request->getParam('q'))) {
         $queryString = $input->getEscaped('q');
         $this->view->queryString = $queryString;
         if ($input->isValid()) {
             $config = Zend_Registry::get('config');
             $index = App_Search_Lucene::open($config->luceneIndex);
             $query = new Zend_Search_Lucene_Search_Query_Boolean();
             $pathTerm = new Zend_Search_Lucene_Index_Term($queryString);
             $pathQuery = new Zend_Search_Lucene_Search_Query_Term($pathTerm);
             $query->addSubquery($pathQuery, true);
             $pathTerm = new Zend_Search_Lucene_Index_Term('20091023', 'CreationDate');
             $pathQuery = new Zend_Search_Lucene_Search_Query_Term($pathTerm);
             $query->addSubquery($pathQuery, true);
             try {
                 $hits = $index->find($query);
             } catch (Zend_Search_Lucene_Exception $ex) {
                 $hits = array();
             }
             $this->view->hits = $hits;
         } else {
             $this->view->messages = $input->getMessages();
         }
     }
 }
开发者ID:philipnorton42,项目名称:PDFSearch,代码行数:29,代码来源:IndexController.php

示例4: toString

 /**
  * Generates a Lucene object from the expression objects.
  *
  * @param array $names Associative list of variable or column names as keys and their corresponding types
  * @param array $translations Associative list of variable or column names that should be translated
  * @param array $plugins Associative list of item names and plugins implementing MW_Common_Criteria_Plugin_Interface
  * @return Zend_Search_Lucene_Search_Query_MultiTerm Combined search objects
  */
 public function toString(array $types, array $translations = array(), array $plugins = array())
 {
     $query = new Zend_Search_Lucene_Search_Query_Boolean();
     foreach ($this->_expressions as $expr) {
         if (($itemstr = $expr->toString($types, $translations, $plugins)) !== '') {
             $query->addSubquery($itemstr, self::$_operators[$this->_operator]);
         }
     }
     return $query;
 }
开发者ID:arcavias,项目名称:ext-zend,代码行数:18,代码来源:Lucene.php

示例5: generateSitemap

 public function generateSitemap()
 {
     $this->prepareSiteMapFolder();
     if (!is_null($this->sitemapDir)) {
         $hosts = $this->getValidHosts();
         if (is_array($hosts)) {
             foreach ($hosts as $hostName) {
                 $query = new \Zend_Search_Lucene_Search_Query_Boolean();
                 $hostTerm = new \Zend_Search_Lucene_Index_Term($hostName, 'host');
                 $hostQuery = new \Zend_Search_Lucene_Search_Query_Term($hostTerm);
                 $query->addSubquery($hostQuery, TRUE);
                 $hostTerm = new \Zend_Search_Lucene_Index_Term(TRUE, 'restrictionGroup_default');
                 $hostQuery = new \Zend_Search_Lucene_Search_Query_Term($hostTerm);
                 $query->addSubquery($hostQuery, TRUE);
                 $hits = $this->index->find($query);
                 $name = str_replace('.', '-', $hostName);
                 $filePath = $this->sitemapDir . '/sitemap-' . $name . '.xml';
                 $fh = fopen($filePath, 'w');
                 fwrite($fh, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
                 fwrite($fh, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
                 fwrite($fh, "\r\n");
                 for ($i = 0; $i < count($hits); $i++) {
                     $url = $hits[$i]->getDocument()->getField('url');
                     $uri = str_replace(array('?pimcore_outputfilters_disabled=1', '&pimcore_outputfilters_disabled=1'), '', $url->value);
                     fwrite($fh, '<url>' . "\r\n");
                     fwrite($fh, '    <loc>' . htmlspecialchars($uri, ENT_QUOTES) . '</loc>' . "\r\n");
                     fwrite($fh, '</url>' . "\r\n");
                 }
                 fwrite($fh, '</urlset>' . "\r\n");
                 fclose($fh);
             }
             $filePath = $this->sitemapDir . '/sitemap.xml';
             $fh = fopen($filePath, 'w');
             fwrite($fh, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
             fwrite($fh, '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
             fwrite($fh, "\r\n");
             foreach ($hosts as $hostName) {
                 $name = str_replace('.', '-', $hostName);
                 //first host must be main domain - see hint in plugin settings
                 $currenthost = $hosts[0];
                 fwrite($fh, '<sitemap>' . "\r\n");
                 fwrite($fh, '    <loc>http://' . $currenthost . '/plugin/LuceneSearch/frontend/sitemap/?sitemap=sitemap-' . $name . '.xml' . '</loc>' . "\r\n");
                 fwrite($fh, '</sitemap>' . "\r\n");
                 \Pimcore\Logger::debug('LuceneSearch: ' . $hostName . ' for sitemap.xml added.');
             }
             fwrite($fh, '</sitemapindex>' . "\r\n");
             fclose($fh);
         } else {
             \Pimcore\Logger::debug('LuceneSearch: could not generate sitemaps, did not find any hosts in index.');
         }
     } else {
         \Pimcore\Logger::emerg('LuceneSearch: Cannot generate sitemap. Sitemap directory [ ' . $this->sitemapDir . ' ]  not available/not writeable and cannot be created');
     }
 }
开发者ID:dachcom-digital,项目名称:pimcore-lucene-search,代码行数:54,代码来源:SitemapBuilder.php

示例6: find

 /**
  * @param $queryString
  * @return array
  */
 public function find($queryString)
 {
     $queryString = trim($queryString);
     if (empty($queryString)) {
         return ["queryString" => $queryString, "message" => "No String"];
     } else {
         $index = \Zend_Search_Lucene::open($this->indexfile);
         $res = explode(' ', $queryString);
         \Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(1);
         \Zend_Search_Lucene::setResultSetLimit(5);
         $query = new \Zend_Search_Lucene_Search_Query_Boolean();
         foreach ($res as $val) {
             if (!empty($val)) {
                 $subquery = new \Zend_Search_Lucene_Search_Query_Boolean();
                 $searchkey1 = $val . "*";
                 $pattern = new \Zend_Search_Lucene_Index_Term($searchkey1, "name");
                 $userQuery = new \Zend_Search_Lucene_Search_Query_Wildcard($pattern);
                 $patternUsername = new \Zend_Search_Lucene_Index_Term($searchkey1, "username");
                 $usernameQuery = new \Zend_Search_Lucene_Search_Query_Wildcard($patternUsername);
                 $subquery->addSubquery($userQuery, null);
                 $subquery->addSubquery($usernameQuery, null);
                 $query->addSubquery($subquery, true);
             }
         }
         $hits = $index->find($query);
         if (!empty($hits)) {
             $results = [];
             foreach ($hits as $hit) {
                 if ($hit->username != $_SESSION['user']->username) {
                     $results[] = $hit->username;
                 }
             }
             if (!empty($results)) {
                 /** @noinspection PhpUndefinedMethodInspection */
                 /** @var Users $users */
                 $users = $_SESSION['user']->getTable();
                 if (isset($_POST['friends'])) {
                     /** @noinspection PhpUndefinedMethodInspection */
                     $friends = $_SESSION['user']->getFriendList();
                     if (empty($friends)) {
                         return ["queryString" => $queryString, "users" => []];
                     } else {
                         $userresult = $users->getSet($results, 'u.username');
                     }
                 } else {
                     $userresult = $users->getSet($results, "u.username", ["u.userid", "u.username", "u.name"]);
                 }
                 return ["queryString" => $queryString, "users" => $userresult->toArray()];
             }
         }
     }
     return ["queryString" => $queryString];
 }
开发者ID:rcrrich,项目名称:cunity,代码行数:57,代码来源:Process.php

示例7: parseQuery

 public function parseQuery()
 {
     try {
         // Parse query string
         $queryParsed = QubitSearch::getInstance()->parse($this->request->query);
     } catch (Exception $e) {
         $this->error = $e->getMessage();
         return null;
     }
     $query = new Zend_Search_Lucene_Search_Query_Boolean();
     $query->addSubquery($queryParsed, true);
     return $query;
 }
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:13,代码来源:indexAction.class.php

示例8: getLuceneQuery

 protected function getLuceneQuery($query)
 {
     $words = str_word_count($query, 1);
     $query = new Zend_Search_Lucene_Search_Query_Boolean();
     foreach ($words as $word) {
         $term = new Zend_Search_Lucene_Index_Term($word);
         $subQuery = new Zend_Search_Lucene_Search_Query_Fuzzy($term, 0.4);
         $query->addSubquery($subQuery, true);
     }
     return $query;
     //  return Zend_Search_Lucene_Search_QueryParser::parse($query);
     //    $term = new Zend_Search_Lucene_Index_Term($query);
     //    return new Zend_Search_Lucene_Search_Query_Fuzzy($term, 0.4);
 }
开发者ID:eXtreme,项目名称:diem,代码行数:14,代码来源:dmSearchIndex.php

示例9: searchDocsByContent

 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;
 }
开发者ID:cyberformed,项目名称:i2tree,代码行数:17,代码来源:js_data_model.php

示例10: userSearch

 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);
 }
开发者ID:nsams,项目名称:koala-framework,代码行数:42,代码来源:ZendSearch.php

示例11: prepareLuceneQuery

 protected function prepareLuceneQuery($keyword)
 {
     $keyword = strtolower($keyword);
     $query = new Zend_Search_Lucene_Search_Query_Boolean();
     # multiterm query
     $subquery1 = new Zend_Search_Lucene_Search_Query_MultiTerm();
     foreach (explode(' ', $keyword) as $key) {
         if (!trim($key)) {
             continue;
         }
         $subquery1->addTerm(new Zend_Search_Lucene_Index_Term($key));
     }
     # wildcard query
     Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(1);
     $tokens = preg_split('/ /', $keyword, -1, PREG_SPLIT_NO_EMPTY);
     $lastWord = trim(array_pop($tokens)) . "*";
     $pattern = new Zend_Search_Lucene_Index_Term($lastWord);
     $subquery2 = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
     $query->addSubquery($subquery1);
     $query->addSubquery($subquery2);
     return $query;
 }
开发者ID:vcgato29,项目名称:poff,代码行数:22,代码来源:actions.class.php

示例12: rewrite

 public function rewrite(Zend_Search_Lucene_Interface $index)
 {
     if (count($this->_terms) == 0) {
         return new Zend_Search_Lucene_Search_Query_Empty();
     } else {
         if ($this->_terms[0]->field !== null) {
             return $this;
         } else {
             $query = new Zend_Search_Lucene_Search_Query_Boolean();
             $query->setBoost($this->getBoost());
             foreach ($index->getFieldNames(true) as $fieldName) {
                 $subquery = new Zend_Search_Lucene_Search_Query_Phrase();
                 $subquery->setSlop($this->getSlop());
                 foreach ($this->_terms as $termId => $term) {
                     $qualifiedTerm = new Zend_Search_Lucene_Index_Term($term->text, $fieldName);
                     $subquery->addTerm($qualifiedTerm, $this->_offsets[$termId]);
                 }
                 $query->addSubquery($subquery);
             }
             return $query;
         }
     }
 }
开发者ID:hackingman,项目名称:TubeX,代码行数:23,代码来源:Phrase.php

示例13: _booleanExpressionQuery

 /**
  * Generate 'boolean style' query from the context
  * 'term1 and term2   or   term3 and (<subquery1>) and not (<subquery2>)'
  *
  * @return Zend_Search_Lucene_Search_Query
  * @throws Zend_Search_Lucene
  */
 private function _booleanExpressionQuery()
 {
     /**
      * We treat each level of an expression as a boolean expression in
      * a Disjunctive Normal Form
      *
      * AND operator has higher precedence than OR
      *
      * Thus logical query is a disjunction of one or more conjunctions of
      * one or more query entries
      */
     require_once 'Zend/Search/Lucene/Search/BooleanExpressionRecognizer.php';
     $expressionRecognizer = new Zend_Search_Lucene_Search_BooleanExpressionRecognizer();
     require_once 'Zend/Search/Lucene/Exception.php';
     try {
         foreach ($this->_entries as $entry) {
             if ($entry instanceof Zend_Search_Lucene_Search_QueryEntry) {
                 $expressionRecognizer->processLiteral($entry);
             } else {
                 switch ($entry) {
                     case Zend_Search_Lucene_Search_QueryToken::TT_AND_LEXEME:
                         $expressionRecognizer->processOperator(Zend_Search_Lucene_Search_BooleanExpressionRecognizer::IN_AND_OPERATOR);
                         break;
                     case Zend_Search_Lucene_Search_QueryToken::TT_OR_LEXEME:
                         $expressionRecognizer->processOperator(Zend_Search_Lucene_Search_BooleanExpressionRecognizer::IN_OR_OPERATOR);
                         break;
                     case Zend_Search_Lucene_Search_QueryToken::TT_NOT_LEXEME:
                         $expressionRecognizer->processOperator(Zend_Search_Lucene_Search_BooleanExpressionRecognizer::IN_NOT_OPERATOR);
                         break;
                     default:
                         throw new Zend_Search_Lucene('Boolean expression error. Unknown operator type.');
                 }
             }
         }
         $conjuctions = $expressionRecognizer->finishExpression();
     } catch (Zend_Search_Exception $e) {
         // throw new Zend_Search_Lucene_Search_QueryParserException('Boolean expression error. Error message: \'' .
         //                                                          $e->getMessage() . '\'.' );
         // It's query syntax error message and it should be user friendly. So FSM message is omitted
         require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
         throw new Zend_Search_Lucene_Search_QueryParserException('Boolean expression error.', 0, $e);
     }
     // Remove 'only negative' conjunctions
     foreach ($conjuctions as $conjuctionId => $conjuction) {
         $nonNegativeEntryFound = false;
         foreach ($conjuction as $conjuctionEntry) {
             if ($conjuctionEntry[1]) {
                 $nonNegativeEntryFound = true;
                 break;
             }
         }
         if (!$nonNegativeEntryFound) {
             unset($conjuctions[$conjuctionId]);
         }
     }
     $subqueries = array();
     foreach ($conjuctions as $conjuction) {
         // Check, if it's a one term conjuction
         if (count($conjuction) == 1) {
             $subqueries[] = $conjuction[0][0]->getQuery($this->_encoding);
         } else {
             require_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
             $subquery = new Zend_Search_Lucene_Search_Query_Boolean();
             foreach ($conjuction as $conjuctionEntry) {
                 $subquery->addSubquery($conjuctionEntry[0]->getQuery($this->_encoding), $conjuctionEntry[1]);
             }
             $subqueries[] = $subquery;
         }
     }
     if (count($subqueries) == 0) {
         require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
         return new Zend_Search_Lucene_Search_Query_Insignificant();
     }
     if (count($subqueries) == 1) {
         return $subqueries[0];
     }
     require_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
     $query = new Zend_Search_Lucene_Search_Query_Boolean();
     foreach ($subqueries as $subquery) {
         // Non-requirered entry/subquery
         $query->addSubquery($subquery);
     }
     return $query;
 }
开发者ID:sepano,项目名称:open-social-media-monitoring,代码行数:91,代码来源:QueryParserContext.php

示例14: rewrite


//.........这里部分代码省略.........
     //$1 'Zend/Search/Lucene.php';
     $maxTerms = Zend_Search_Lucene::getTermsPerQueryLimit();
     foreach ($fields as $field) {
         $index->resetTermsStream();
         //$1 'Zend/Search/Lucene/Index/Term.php';
         if ($prefix != '') {
             $index->skipTo(new Zend_Search_Lucene_Index_Term($prefix, $field));
             while ($index->currentTerm() !== null && $index->currentTerm()->field == $field && substr($index->currentTerm()->text, 0, $prefixByteLength) == $prefix) {
                 // Calculate similarity
                 $target = substr($index->currentTerm()->text, $prefixByteLength);
                 $maxDistance = isset($this->_maxDistances[strlen($target)]) ? $this->_maxDistances[strlen($target)] : $this->_calculateMaxDistance($prefixUtf8Length, $termRestLength, strlen($target));
                 if ($termRestLength == 0) {
                     // we don't have anything to compare.  That means if we just add
                     // the letters for current term we get the new word
                     $similarity = $prefixUtf8Length == 0 ? 0 : 1 - strlen($target) / $prefixUtf8Length;
                 } else {
                     if (strlen($target) == 0) {
                         $similarity = $prefixUtf8Length == 0 ? 0 : 1 - $termRestLength / $prefixUtf8Length;
                     } else {
                         if ($maxDistance < abs($termRestLength - strlen($target))) {
                             //just adding the characters of term to target or vice-versa results in too many edits
                             //for example "pre" length is 3 and "prefixes" length is 8.  We can see that
                             //given this optimal circumstance, the edit distance cannot be less than 5.
                             //which is 8-3 or more precisesly abs(3-8).
                             //if our maximum edit distance is 4, then we can discard this word
                             //without looking at it.
                             $similarity = 0;
                         } else {
                             $similarity = 1 - levenshtein($termRest, $target) / ($prefixUtf8Length + min($termRestLength, strlen($target)));
                         }
                     }
                 }
                 if ($similarity > $this->_minimumSimilarity) {
                     $this->_matches[] = $index->currentTerm();
                     $this->_termKeys[] = $index->currentTerm()->key();
                     $this->_scores[] = ($similarity - $this->_minimumSimilarity) * $scaleFactor;
                     if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
                         //$1 'Zend/Search/Lucene/Exception.php';
                         throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.');
                     }
                 }
                 $index->nextTerm();
             }
         } else {
             $index->skipTo(new Zend_Search_Lucene_Index_Term('', $field));
             while ($index->currentTerm() !== null && $index->currentTerm()->field == $field) {
                 // Calculate similarity
                 $target = $index->currentTerm()->text;
                 $maxDistance = isset($this->_maxDistances[strlen($target)]) ? $this->_maxDistances[strlen($target)] : $this->_calculateMaxDistance(0, $termRestLength, strlen($target));
                 if ($maxDistance < abs($termRestLength - strlen($target))) {
                     //just adding the characters of term to target or vice-versa results in too many edits
                     //for example "pre" length is 3 and "prefixes" length is 8.  We can see that
                     //given this optimal circumstance, the edit distance cannot be less than 5.
                     //which is 8-3 or more precisesly abs(3-8).
                     //if our maximum edit distance is 4, then we can discard this word
                     //without looking at it.
                     $similarity = 0;
                 } else {
                     $similarity = 1 - levenshtein($termRest, $target) / min($termRestLength, strlen($target));
                 }
                 if ($similarity > $this->_minimumSimilarity) {
                     $this->_matches[] = $index->currentTerm();
                     $this->_termKeys[] = $index->currentTerm()->key();
                     $this->_scores[] = ($similarity - $this->_minimumSimilarity) * $scaleFactor;
                     if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
                         //$1 'Zend/Search/Lucene/Exception.php';
                         throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.');
                     }
                 }
                 $index->nextTerm();
             }
         }
         $index->closeTermsStream();
     }
     if (count($this->_matches) == 0) {
         //$1 'Zend/Search/Lucene/Search/Query/Empty.php';
         return new Zend_Search_Lucene_Search_Query_Empty();
     } else {
         if (count($this->_matches) == 1) {
             //$1 'Zend/Search/Lucene/Search/Query/Term.php';
             return new Zend_Search_Lucene_Search_Query_Term(reset($this->_matches));
         } else {
             //$1 'Zend/Search/Lucene/Search/Query/Boolean.php';
             $rewrittenQuery = new Zend_Search_Lucene_Search_Query_Boolean();
             array_multisort($this->_scores, SORT_DESC, SORT_NUMERIC, $this->_termKeys, SORT_ASC, SORT_STRING, $this->_matches);
             $termCount = 0;
             //$1 'Zend/Search/Lucene/Search/Query/Term.php';
             foreach ($this->_matches as $id => $matchedTerm) {
                 $subquery = new Zend_Search_Lucene_Search_Query_Term($matchedTerm);
                 $subquery->setBoost($this->_scores[$id]);
                 $rewrittenQuery->addSubquery($subquery);
                 $termCount++;
                 if ($termCount >= self::MAX_CLAUSE_COUNT) {
                     break;
                 }
             }
             return $rewrittenQuery;
         }
     }
 }
开发者ID:netconstructor,项目名称:Centurion,代码行数:101,代码来源:Fuzzy.php

示例15: rewrite

 /**
  * Re-write query into primitive queries in the context of specified index
  *
  * @param Zend_Search_Lucene_Interface $index
  * @return Zend_Search_Lucene_Search_Query
  */
 public function rewrite(Zend_Search_Lucene_Interface $index)
 {
     if (count($this->_terms) == 0) {
         require_once 'Zend/Search/Lucene/Search/Query/Empty.php';
         return new Zend_Search_Lucene_Search_Query_Empty();
     }
     // Check, that all fields are qualified
     $allQualified = true;
     foreach ($this->_terms as $term) {
         if ($term->field === null) {
             $allQualified = false;
             break;
         }
     }
     if ($allQualified) {
         return $this;
     } else {
         /** transform multiterm query to boolean and apply rewrite() method to subqueries. */
         require_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
         $query = new Zend_Search_Lucene_Search_Query_Boolean();
         $query->setBoost($this->getBoost());
         require_once 'Zend/Search/Lucene/Search/Query/Term.php';
         foreach ($this->_terms as $termId => $term) {
             $subquery = new Zend_Search_Lucene_Search_Query_Term($term);
             $query->addSubquery($subquery->rewrite($index), $this->_signs === null ? true : $this->_signs[$termId]);
         }
         return $query;
     }
 }
开发者ID:bizanto,项目名称:Hooked,代码行数:35,代码来源:MultiTerm.php


注:本文中的Zend_Search_Lucene_Search_Query_Boolean类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。