本文整理汇总了PHP中Zend_Search_Lucene_Search_Query_Boolean::addSubquery方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Search_Query_Boolean::addSubquery方法的具体用法?PHP Zend_Search_Lucene_Search_Query_Boolean::addSubquery怎么用?PHP Zend_Search_Lucene_Search_Query_Boolean::addSubquery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Search_Lucene_Search_Query_Boolean
的用法示例。
在下文中一共展示了Zend_Search_Lucene_Search_Query_Boolean::addSubquery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
}
}
示例2: 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');
}
}
示例3: 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;
}
}
示例4: 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);
}
示例5: rewrite
public function rewrite(Zend_Search_Lucene_Interface $index)
{
$query = new Zend_Search_Lucene_Search_Query_Boolean();
$query->setBoost($this->getBoost());
foreach ($this->_subqueries as $subqueryId => $subquery) {
$query->addSubquery($subquery->rewrite($index), $this->_signs === null ? true : $this->_signs[$subqueryId]);
}
return $query;
}
示例6: 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;
}
示例7: 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);
}
示例8: 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];
}
示例9: 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;
}
示例10: 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;
}
示例11: 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);
}
示例12: 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;
}
示例13: 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;
}
}
}
示例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;
}
}
}
示例15: _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;
}