本文整理汇总了PHP中Zend_Search_Lucene_Search_Query_MultiTerm类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Search_Query_MultiTerm类的具体用法?PHP Zend_Search_Lucene_Search_Query_MultiTerm怎么用?PHP Zend_Search_Lucene_Search_Query_MultiTerm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Search_Lucene_Search_Query_MultiTerm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: delete
/**
* Removes search entry of current entity from the index.
*
* @return Mage_Lucene_Model_Index_Document_Abstract
**/
protected function delete()
{
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->addTerm(new Zend_Search_Lucene_Index_Term($this->_id, 'entity_id'), true);
$query->addTerm(new Zend_Search_Lucene_Index_Term($this->getDoctype(), 'doctype'), true);
$query->addTerm(new Zend_Search_Lucene_Index_Term($this->getStore()->getId(), self::STORE_ATTRIBUTE_CODE), true);
$this->deleteByQuery($query);
return $this;
}
开发者ID:rickboyau,项目名称:magento-lucene,代码行数:14,代码来源:Abstract.php
示例2: 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 ($this->_term->field != null) {
return $this;
} else {
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->setBoost($this->getBoost());
foreach ($index->getFieldNames(true) as $fieldName) {
$term = new Zend_Search_Lucene_Index_Term($this->_term->text, $fieldName);
$query->addTerm($term);
}
return $query->rewrite($index);
}
}
开发者ID:jorgenils,项目名称:zend-framework,代码行数:20,代码来源:Term.php
示例3: 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 ($this->_term->field != null) {
return $this;
} else {
require_once sfConfig::get('sf_lib_dir') . '/modules/search/lib/Lucene/Search/Query/MultiTerm.php';
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->setBoost($this->getBoost());
require_once sfConfig::get('sf_lib_dir') . '/modules/search/lib/Lucene/Index/Term.php';
foreach ($index->getFieldNames(true) as $fieldName) {
$term = new Zend_Search_Lucene_Index_Term($this->_term->text, $fieldName);
$query->addTerm($term);
}
return $query->rewrite($index);
}
}
开发者ID:kotow,项目名称:work,代码行数:22,代码来源:Term.php
示例4: 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 ($this->_term->field != null) {
return $this;
} else {
require_once PHP_LIBRARY_PATH . 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->setBoost($this->getBoost());
require_once PHP_LIBRARY_PATH . 'Zend/Search/Lucene/Index/Term.php';
foreach ($index->getFieldNames(true) as $fieldName) {
$term = new Zend_Search_Lucene_Index_Term($this->_term->text, $fieldName);
$query->addTerm($term);
}
return $query->rewrite($index);
}
}
开发者ID:netixx,项目名称:Stock,代码行数:22,代码来源:Term.php
示例5: indexAction
/**
* The main workshop page. It has the list of all the workshops that are
* available in the system.
*
*/
public function indexAction()
{
$this->view->acl = array('workshopList' => $this->_helper->hasAccess('workshop-list'));
$get = Zend_Registry::get('getFilter');
$form = new Zend_Form();
$form->setAttrib('id', 'workshopForm')->setMethod(Zend_Form::METHOD_GET)->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'filterForm')), 'Form'));
$searchField = $form->createElement('text', 'search', array('label' => 'workshop-index-index:searchWorkshops'));
$searchField->setRequired(false)->addFilter('StringTrim')->addFilter('StripTags')->setValue(isset($get->search) ? $get->search : '');
$category = new Category();
$categoryList = $category->fetchAll(null, 'name');
$categories = $form->createElement('select', 'categoryId');
$categories->addMultiOption('', '-- Search By Category -- ');
foreach ($categoryList as $c) {
$categories->addMultiOption($c['categoryId'], $c['name']);
}
$categories->setValue(isset($get->categoryId) ? $get->categoryId : '');
$submit = $form->createElement('submit', 'submitButton', array('label' => 'workshop-index-index:search'));
$submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit'))));
$form->addElements(array($searchField, $categories));
$form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit));
$this->view->form = $form;
$searchTerm = new Search_Term();
$workshops = array();
if ($get->search != '' || $get->categoryId != 0) {
$workshop = new Workshop();
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
if ($get->search != '') {
$query->addTerm(new Zend_Search_Lucene_Index_Term($get->search), true);
}
if ($get->categoryId != 0) {
$query->addTerm(new Zend_Search_Lucene_Index_Term($get->categoryId, 'categoryId'), true);
}
$workshops = $workshop->search($query);
$searchTerm->increment($get->search);
$this->view->searchTerm = $get->search;
}
$this->view->workshops = $workshops;
$this->view->topTerms = $searchTerm->getTopSearchTerms(10);
$this->view->layout()->setLayout('search');
$this->view->layout()->rightContent = $this->view->render('index/top-terms.phtml');
$this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jquery.autocomplete.js');
$this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/jquery.autocomplete.css');
$this->_helper->pageTitle("workshop-index-index:title");
}
开发者ID:ncsuwebdev,项目名称:classmate,代码行数:49,代码来源:IndexController.php
示例6: 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
示例7: getQuery
/**
* Transform entry to a subquery
*
* @param string $encoding
* @return Zend_Search_Lucene_Search_Query
* @throws Zend_Search_Lucene_Search_QueryParserException
*/
public function getQuery($encoding)
{
if ($this->_fuzzyQuery) {
throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search is not supported yet.');
}
if (strpos($this->_term, '?') !== false || strpos($this->_term, '*') !== false) {
throw new Zend_Search_Lucene_Search_QueryParserException('Wildcard queries are not supported yet.');
}
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_term, $encoding);
if (count($tokens) == 0) {
return new Zend_Search_Lucene_Search_Query_Insignificant();
}
if (count($tokens) == 1) {
$term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
$query = new Zend_Search_Lucene_Search_Query_Term($term);
$query->setBoost($this->_boost);
return $query;
}
//It's not empty or one term query
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
/**
* @todo Process $token->getPositionIncrement() to support stemming, synonyms and other
* analizer design features
*/
foreach ($tokens as $token) {
$term = new Zend_Search_Lucene_Index_Term($token->getTermText(), $this->_field);
$query->addTerm($term, true);
// all subterms are required
}
$query->setBoost($this->_boost);
return $query;
}
开发者ID:ookwudili,项目名称:chisimba,代码行数:39,代码来源:Term.php
示例8: 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)
{
$this->_matches = array();
if ($this->_pattern->field === null) {
// Search through all fields
$fields = $index->getFieldNames(true);
} else {
$fields = array($this->_pattern->field);
}
$prefix = self::_getPrefix($this->_pattern->text);
$prefixLength = strlen($prefix);
$matchExpression = '/^' . str_replace(array('\\?', '\\*'), array('.', '.*'), preg_quote($this->_pattern->text, '/')) . '$/';
/** @todo check for PCRE unicode support may be performed through Zend_Environment in some future */
if (@preg_match('/\\pL/u', 'a') == 1) {
// PCRE unicode support is turned on
// add Unicode modifier to the match expression
$matchExpression .= 'u';
}
foreach ($fields as $field) {
$index->resetTermsStream();
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, $prefixLength) == $prefix) {
if (preg_match($matchExpression, $index->currentTerm()->text) === 1) {
$this->_matches[] = $index->currentTerm();
}
$index->nextTerm();
}
} else {
$index->skipTo(new Zend_Search_Lucene_Index_Term('', $field));
while ($index->currentTerm() !== null && $index->currentTerm()->field == $field) {
if (preg_match($matchExpression, $index->currentTerm()->text) === 1) {
$this->_matches[] = $index->currentTerm();
}
$index->nextTerm();
}
}
$index->closeTermsStream();
}
if (count($this->_matches) == 0) {
return new Zend_Search_Lucene_Search_Query_Empty();
} else {
if (count($this->_matches) == 1) {
return new Zend_Search_Lucene_Search_Query_Term(reset($this->_matches));
} else {
$rewrittenQuery = new Zend_Search_Lucene_Search_Query_MultiTerm();
foreach ($this->_matches as $matchedTerm) {
$rewrittenQuery->addTerm($matchedTerm);
}
return $rewrittenQuery;
}
}
}
开发者ID:ookwudili,项目名称:chisimba,代码行数:59,代码来源:Wildcard.php
示例9: get_similar_posts
/**
* 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;
}
开发者ID:habari-extras,项目名称:multisearch,代码行数:37,代码来源:zendsearchlucene.php
示例10: deleteByIdLanguage
/**
* Delete an existing document from the index
*
* @param integer $id object identifier
* @param string $language ISO-639-1 code
* @return void
*/
public static function deleteByIdLanguage($id, $language)
{
// have to use another search object to perform the querying
$querier = new QubitSearch();
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->addTerm(new Zend_Search_Lucene_Index_Term($id, 'id'), true);
$query->addTerm(new Zend_Search_Lucene_Index_Term($language, 'culture'), true);
foreach ($querier->getEngine()->getIndex()->find($query) as $hit) {
self::getInstance()->getEngine()->getIndex()->delete($hit->id);
}
}
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:18,代码来源:QubitSearch.class.php
示例11: query
/**
* Create a lucene search from search terms
*
* @param string $searchTerm Search terms
* @return \Zend_Search_Lucene_Search_Query Lucene search query
*/
public function query($searchTerm)
{
// If there are meaningful search terms
if (strlen(trim($searchTerm))) {
$query = new \Zend_Search_Lucene_Search_Query_Boolean();
$termQuery = \Zend_Search_Lucene_Search_QueryParser::parse($searchTerm);
// Include term based restriction
$query->addSubquery($termQuery, true);
// If applicable: Apply language based restriction
if (\Tollwerk\TwLucenesearch\Utility\Indexer::indexConfig($GLOBALS['TSFE'], 'search.restrictByLanguage')) {
require_once 'Zend/Search/Lucene/Search/Query/Term.php';
require_once 'Zend/Search/Lucene/Index/Term.php';
$query->addSubquery(new \Zend_Search_Lucene_Search_Query_Term(new \Zend_Search_Lucene_Index_Term($GLOBALS['TSFE']->lang, 'language')), true);
}
// If applicable: Apply rootline based restriction
$rootlinePids = \Tollwerk\TwLucenesearch\Utility\Indexer::indexConfig($GLOBALS['TSFE'], 'search.restrictByRootlinePids');
if (is_array($rootlinePids) && count($rootlinePids)) {
require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
require_once 'Zend/Search/Lucene/Index/Term.php';
$rootlineQuery = new \Zend_Search_Lucene_Search_Query_MultiTerm();
foreach ($rootlinePids as $rootlinePid) {
$rootlineQuery->addTerm(new \Zend_Search_Lucene_Index_Term($rootlinePid, 'rootline'), null);
}
$query->addSubquery($rootlineQuery, true);
}
return $query;
}
return null;
}
开发者ID:GerDner,项目名称:TYPO3-ext-tw_lucenesearch,代码行数:35,代码来源:Lucene.php
示例12: optimize
/**
* Optimize query in the context of specified index
*
* @param Zend_Search_Lucene_Interface $index
* @return Zend_Search_Lucene_Search_Query
*/
public function optimize(Zend_Search_Lucene_Interface $index)
{
$subqueries = array();
$signs = array();
// Optimize all subqueries
foreach ($this->_subqueries as $id => $subquery) {
$subqueries[] = $subquery->optimize($index);
$signs[] = $this->_signs === null ? true : $this->_signs[$id];
}
// Remove insignificant subqueries
foreach ($subqueries as $id => $subquery) {
if ($subquery instanceof Zend_Search_Lucene_Search_Query_Insignificant) {
// Insignificant subquery has to be removed anyway
unset($subqueries[$id]);
unset($signs[$id]);
}
}
if (count($subqueries) == 0) {
// Boolean query doesn't has non-insignificant subqueries
return new Zend_Search_Lucene_Search_Query_Insignificant();
}
// Check if all non-insignificant subqueries are prohibited
$allProhibited = true;
foreach ($signs as $sign) {
if ($sign !== false) {
$allProhibited = false;
break;
}
}
if ($allProhibited) {
return new Zend_Search_Lucene_Search_Query_Insignificant();
}
// Check for empty subqueries
foreach ($subqueries as $id => $subquery) {
if ($subquery instanceof Zend_Search_Lucene_Search_Query_Empty) {
if ($signs[$id] === true) {
// Matching is required, but is actually empty
return new Zend_Search_Lucene_Search_Query_Empty();
} else {
// Matching is optional or prohibited, but is empty
// Remove it from subqueries and signs list
unset($subqueries[$id]);
unset($signs[$id]);
}
}
}
// Check, if reduced subqueries list is empty
if (count($subqueries) == 0) {
return new Zend_Search_Lucene_Search_Query_Empty();
}
// Check if all non-empty subqueries are prohibited
$allProhibited = true;
foreach ($signs as $sign) {
if ($sign !== false) {
$allProhibited = false;
break;
}
}
if ($allProhibited) {
return new Zend_Search_Lucene_Search_Query_Empty();
}
// Check, if reduced subqueries list has only one entry
if (count($subqueries) == 1) {
// It's a query with only one required or optional clause
// (it's already checked, that it's not a prohibited clause)
if ($this->getBoost() == 1) {
return reset($subqueries);
}
$optimizedQuery = clone reset($subqueries);
$optimizedQuery->setBoost($optimizedQuery->getBoost() * $this->getBoost());
return $optimizedQuery;
}
// Prepare first candidate for optimized query
$optimizedQuery = new Zend_Search_Lucene_Search_Query_Boolean($subqueries, $signs);
$optimizedQuery->setBoost($this->getBoost());
$terms = array();
$tsigns = array();
$boostFactors = array();
// Try to decompose term and multi-term subqueries
foreach ($subqueries as $id => $subquery) {
if ($subquery instanceof Zend_Search_Lucene_Search_Query_Term) {
$terms[] = $subquery->getTerm();
$tsigns[] = $signs[$id];
$boostFactors[] = $subquery->getBoost();
// remove subquery from a subqueries list
unset($subqueries[$id]);
unset($signs[$id]);
} else {
if ($subquery instanceof Zend_Search_Lucene_Search_Query_MultiTerm) {
$subTerms = $subquery->getTerms();
$subSigns = $subquery->getSigns();
if ($signs[$id] === true) {
// It's a required multi-term subquery.
// Something like '... +(+term1 -term2 term3 ...) ...'
//.........这里部分代码省略.........
开发者ID:sraj4,项目名称:EthicsPublicHtmlProd,代码行数:101,代码来源:Boolean.php
示例13: 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)
{
$this->_matches = array();
if ($this->_field === null) {
// Search through all fields
$fields = $index->getFieldNames(true);
} else {
$fields = array($this->_field);
}
// require_once 'Zend/Search/Lucene.php';
$maxTerms = Zend_Search_Lucene::getTermsPerQueryLimit();
foreach ($fields as $field) {
$index->resetTermsStream();
// require_once 'Zend/Search/Lucene/Index/Term.php';
if ($this->_lowerTerm !== null) {
$lowerTerm = new Zend_Search_Lucene_Index_Term($this->_lowerTerm->text, $field);
$index->skipTo($lowerTerm);
if (!$this->_inclusive && $index->currentTerm() == $lowerTerm) {
// Skip lower term
$index->nextTerm();
}
} else {
$index->skipTo(new Zend_Search_Lucene_Index_Term('', $field));
}
if ($this->_upperTerm !== null) {
// Walk up to the upper term
$upperTerm = new Zend_Search_Lucene_Index_Term($this->_upperTerm->text, $field);
while ($index->currentTerm() !== null && $index->currentTerm()->field == $field && strcmp($index->currentTerm()->text, $upperTerm->text) < 0) {
$this->_matches[] = $index->currentTerm();
if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
// require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Terms per query limit is reached.');
}
$index->nextTerm();
}
if ($this->_inclusive && $index->currentTerm() == $upperTerm) {
// Include upper term into result
$this->_matches[] = $upperTerm;
}
} else {
// Walk up to the end of field data
while ($index->currentTerm() !== null && $index->currentTerm()->field == $field) {
$this->_matches[] = $index->currentTerm();
if ($maxTerms != 0 && count($this->_matches) > $maxTerms) {
// require_once '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) {
// require_once 'Zend/Search/Lucene/Search/Query/Empty.php';
return new Zend_Search_Lucene_Search_Query_Empty();
} else {
if (count($this->_matches) == 1) {
// require_once 'Zend/Search/Lucene/Search/Query/Term.php';
return new Zend_Search_Lucene_Search_Query_Term(reset($this->_matches));
} else {
// require_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
$rewrittenQuery = new Zend_Search_Lucene_Search_Query_MultiTerm();
foreach ($this->_matches as $matchedTerm) {
$rewrittenQuery->addTerm($matchedTerm);
}
return $rewrittenQuery;
}
}
}
开发者ID:alefernie,项目名称:intranet,代码行数:75,代码来源:Range.php
示例14: add_to_index
/**
* add_to_index function
*
* deletes any exising index entries, and adds a document to the index
*
* @TODO Is this working properly
* @param mixed $Model
* @param mixed $id
* @access public
* @return void
*/
function add_to_index(&$Model, $id)
{
if (!empty($this->settings[$Model->alias])) {
if (!$this->open_index($Model)) {
return false;
}
try {
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->addTerm(new Zend_Search_Lucene_Index_Term($id, 'cake_id'), true);
$query->addTerm(new Zend_Search_Lucene_Index_Term($Model->alias, 'cake_model'), true);
$Hits = $this->Index->find($query);
// TODO there are never any hits - why
if (count($Hits)) {
$this->delete_from_index($Model, $id);
}
if (method_exists($Model, 'find_index')) {
$result = $Model->find_index('first', array('conditions' => array($Model->alias . '.id' => $id)));
} else {
$result = $Model->find('first', array('conditions' => array($Model->alias . '.id' => $id)));
}
if (!empty($result)) {
$doc = new Zend_Search_Lucene_Document();
// add the model field
$doc->addField(Zend_Search_Lucene_Field::Keyword('cake_model', $Model->alias, 'utf-8'));
foreach ($this->settings[$Model->alias]['fields'] as $field_name => $options) {
if (!empty($options['prepare']) && function_exists($options['prepare'])) {
$result[$Model->alias][$field_name] = call_user_func($options['prepare'], $result[$Model->alias][$field_name]);
}
$alias = !empty($options['alias']) ? $options['alias'] : $field_name;
$doc->addField(Zend_Search_Lucene_Field::$options['type']($alias, $result[$Model->alias][$field_name], 'utf-8'));
}
$this->Index->addDocument($doc);
$this->Index->commit();
if (Configure::read()) {
$Hits = $this->Index->find($query);
if (!count($Hits)) {
// TODO why isn't it possible to find what was just added
$this->log('Tried to add to the search index, no errors but couldnt find what was just added!', 'searchable');
}
$this->log('added to index id:' . $id, 'searchable');
}
}
} catch (Zend_Search_Lucene_Exception $e) {
$this->log('Lucene exception:' . $e->getMessage(), 'searchable');
}
}
}
开发者ID:sdoney,项目名称:cookbook,代码行数:58,代码来源:searchable.php
示例15: addLanguageQuery
private function addLanguageQuery($query)
{
if (!empty($this->searchLanguage)) {
$languageQuery = new \Zend_Search_Lucene_Search_Query_MultiTerm();
$languageQuery->addTerm(new Zend_Search_Lucene_Index_Term('all', 'lang'));
if (is_object($this->searchLanguage)) {
$lang = $this->searchLanguage->toString();
} else {
$lang = $this->searchLanguage;
}
$lang = str_replace(array('_', '-'), '', $lang);
$languageQuery->addTerm(new Zend_Search_Lucene_Index_Term($lang, 'lang'));
$query->addSubquery($languageQuery, TRUE);
}
return $query;
}
开发者ID:dachcom-digital,项目名称:pimcore-lucene-search,代码行数:16,代码来源:FrontendController.php
示例16: Foo
try {
$criteria->addField(new Foo());
$t->fail('->addField() rejects invalid values');
} catch (Exception $e) {
$t->pass('->addField() rejects invalid values');
}
$t->diag('testing addMultiTerm()');
$s = inst()->addMultiTerm(range(1, 10), 'foo')->getQuery()->getSubqueries();
$q = new Zend_Search_Lucene_Search_Query_MultiTerm();
foreach (range(1, 10) as $value) {
$q->addTerm(new Zend_Search_Lucene_Index_Term($value, 'foo'));
}
$t->ok($s[0] == $q, '->addMultiTerm() registers the correct query');
try {
$s = inst()->addMultiTerm('bar', 'foo')->getQuery()->getSubqueries();
$q = new Zend_Search_Lucene_Search_Query_MultiTerm();
$q->addTerm(new Zend_Search_Lucene_Index_Term('bar', 'foo'));
$t->ok($s[0] == $q, '->addMultiTerm() registers and accepts a string value');
} catch (Exception $e) {
$t->fail('->addMultiTerm() registers and accepts a string value');
}
$t->diag('testing addWildcard()');
$s = inst()->addWildcard('foo*', 'bar')->getQuery()->getSubqueries();
$q = new Zend_Search_Lucene_Search_Query_Wildcard(new Zend_Search_Lucene_Index_Term('foo*', 'bar'));
$t->ok($s[0] == $q, '->addWildcard() registers the correct query with mutlitple character wildcards');
$s = inst()->addWildcard('f?o', 'bar')->getQuery()->getSubqueries();
$q = new Zend_Search_Lucene_Search_Query_Wildcard(new Zend_Search_Lucene_Index_Term('f?o', 'bar'));
$t->ok($s[0] == $q, '->addWildcard() registers the correct query with single character wildcards');
$s = inst()->addWildcard('foo* baz?', 'bar')->getQuery()->getSubqueries();
$q = new Zend_Search_Lucene_Search_Query_Wildcard(new Zend_Search_Lucene_Index_Term('foo* baz?', 'bar'));
$t->ok($s[0] == $q, '->addWildcard() registers the correct query with mixing character wildcards');
开发者ID:palcoprincipal,项目名称:sfLucenePlugin,代码行数:31,代码来源:sfLuceneCriteriaTest.php
示例17: addMultiTerm
/**
* Adds a multiterm query.
*
* @return sfLuceneCriteria
*/
public function addMultiTerm($values, $field = null, $matchType = null, $type = true)
{
if (!is_array($values)) {
$values = array($values);
}
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
foreach ($values as $value) {
$query->addTerm(new Zend_Search_Lucene_Index_Term($value, $field), $matchType);
}
return $this->add($query, $type);
}
开发者ID:palcoprincipal,项目名称:sfLucenePlugin,代码行数:16,代码来源:sfLuceneCriteria.class.php
示例18: getQuery
/**
* Transform entry to a subquery
*
* @param string $encoding
* @return Zend_Search_Lucene_Search_Query
* @throws Zend_Search_Lucene_Search_QueryParserException
*/
public function getQuery($encoding)
{
if (strpos($this->_term, '?') !== false || strpos($this->_term, '*') !== false) {
if ($this->_fuzzyQuery) {
// require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search is not supported for terms with wildcards.');
}
$pattern = '';
$subPatterns = explode('*', $this->_term);
$astericFirstPass = true;
foreach ($subPatterns as $subPattern) {
if (!$astericFirstPass) {
$pattern .= '*';
} else {
$astericFirstPass = false;
}
$subPatternsL2 = explode('?', $subPattern);
$qMarkFirstPass = true;
foreach ($subPatternsL2 as $subPatternL2) {
if (!$qMarkFirstPass) {
$pattern .= '?';
} else {
$qMarkFirstPass = false;
}
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($subPatternL2, $encoding);
if (count($tokens) > 1) {
// require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Wildcard search is supported only for non-multiple word terms');
}
foreach ($tokens as $token) {
$pattern .= $token->getTermText();
}
}
}
$term = new Zend_Search_Lucene_Index_Term($pattern, $this->_field);
$query = new Zend_Search_Lucene_Search_Query_Wildcard($term);
$query->setBoost($this->_boost);
return $query;
}
$tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($this->_term, $encoding);
if (count($tokens) == 0) {
return new Zend_Search_Lucene_Search_Query_Insignificant();
}
if (count($tokens) == 1 && !$this->_fuzzyQuery) {
$term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
$query = new Zend_Search_Lucene_Search_Query_Term($term);
$query->setBoost($this->_boost);
return $query;
}
if (count($tokens) == 1 && $this->_fuzzyQuery) {
$term = new Zend_Search_Lucene_Index_Term($tokens[0]->getTermText(), $this->_field);
$query = new Zend_Search_Lucene_Search_Query_Fuzzy($term, $this->_similarity);
$query->setBoost($this->_boost);
return $query;
}
if ($this->_fuzzyQuery) {
// require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
throw new Zend_Search_Lucene_Search_QueryParserException('Fuzzy search is supported only for non-multiple word terms');
}
//It's not empty or one term query
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
/**
* @todo Process $token->getPositionIncrement() to support stemming, synonyms and other
* analizer design features
*/
foreach ($tokens as $token) {
$term = new Zend_Search_Lucene_Index_Term($token->getTermText(), $this->_field);
$query->addTerm($term, true);
// all subterms are required
}
$query->setBoost($this->_boost);
return $query;
}
开发者ID:sraj4,项目名称:EthicsPublicHtmlProd,代码行数:80,代码来源:Term.php
示例19: 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)
{
$this->_matches = array();
if ($this->_field === null) {
// Search through all fields
$fields = $index->getFieldNames(true);
} else {
$fields = array($this->_field);
}
foreach ($fields as $field) {
$index->resetTermsStream();
if ($this->_lowerTerm !== null) {
$lowerTerm = new Zend_Search_Lucene_Index_Term($this->_lowerTerm->text, $field);
$index->skipTo($lowerTerm);
if (!$this->_inclusive && $index->currentTerm() == $lowerTerm) {
// Skip lower term
$index->nextTerm();
}
} else {
$index->skipTo(new Zend_Search_Lucene_Index_Term('', $field));
}
if ($this->_upperTerm !== null) {
// Walk up to the upper term
$upperTerm = new Zend_Search_Lucene_Index_Term($this->_upperTerm->text, $field);
while ($index->currentTerm() !== null && $index->currentTerm()->field == $field && $index->currentTerm()->text < $upperTerm->text) {
$this->_matches[] = $index->currentTerm();
$index->nextTerm();
}
if ($this->_inclusive && $index->currentTerm() == $upperTerm) {
// Include upper term into result
$this->_matches[] = $upperTerm;
}
} else {
// Walk up to the end of field data
while ($index->currentTerm() !== null && $index->currentTerm()->field == $field) {
$this->_matches[] = $index->currentTerm();
$index->nextTerm();
}
}
$index->closeTermsStream();
}
if (count($this->_matches) == 0) {
return new Zend_Search_Lucene_Search_Query_Empty();
} else {
if (count($this->_matches) == 1) {
return new Zend_Search_Lucene_Search_Query_Term(reset($this->_matches));
} else {
$rewrittenQuery = new Zend_Search_Lucene_Search_Query_MultiTerm();
foreach ($this->_matches as $matchedTerm) {
$rewrittenQuery->addTerm($matchedTerm);
}
return $rewrittenQuery;
}
}
}
开发者ID:ookwudili,项目名称:chisimba,代码行数:61,代码来源:Range.php
示例20: parse
/**
* Parses a query string
*
* @param string $strQuery
* @param string $encoding
* @return Zend_Search_Lucene_Search_Query
* @throws Zend_Search_Lucene_Search_QueryParserException
*/
public static function parse($strQuery, $encoding = null)
{
self::_getInstance();
// Reset FSM if previous parse operation didn't return it into a correct state
self::$_instance->reset();
require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
try {
require_once 'Zend/Search/Lucene/Search/QueryParserContext.php';
self::$_instance->_encoding = $encoding !== null ? $encoding : self::$_instance->_defaultEncoding;
self::$_instance->_lastToken = null;
self::$_instance->_context = new Zend_Search_Lucene_Search_QueryParserContext(self::$_instance->_encoding);
self::$_instance->_contextStack = array();
self::$_instance->_tokens = self::$_instance->_lexer->tokenize($strQuery, self::$_instance->_encoding);
// Empty query
if (count(self::$_instance->_tokens) == 0) {
require_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
return new Zend_Search_Lucene_Search_Query_Insignificant();
}
foreach (self::$_instance->_tokens as $token) {
try {
self::$_instance->_currentToken = $token;
self::$_instance->process($token->type);
self::$_instance->_lastToken = $token;
} catch (Exception $e) {
if (strpos($e->getMessage(), 'There is no any rule for') !== false) {
|
请发表评论