本文整理汇总了PHP中Zend_Search_Lucene_Search_QueryParser类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Search_QueryParser类的具体用法?PHP Zend_Search_Lucene_Search_QueryParser怎么用?PHP Zend_Search_Lucene_Search_QueryParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Search_Lucene_Search_QueryParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: search
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;
}
开发者ID:BGCX262,项目名称:zyshop-svn-to-git,代码行数:7,代码来源:search_lucnene.php
示例2: searchLuceneWithValues
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;
}
开发者ID:quafzi,项目名称:timpany-prototype,代码行数:28,代码来源:aZendSearch.class.php
示例3: __construct
/**
* Creates a new ZendLucene handler connection
*
* @param string $location
*/
public function __construct($location)
{
/**
* We're using realpath here because Zend_Search_Lucene does not do
* that itself. It can cause issues because their destructor uses the
* same filename but the cwd could have been changed.
*/
$location = realpath($location);
/* If the $location doesn't exist, ZSL throws a *generic* exception. We
* don't care here though and just always assume it is because the
* index does not exist. If it doesn't exist, we create it.
*/
try {
$this->connection = Zend_Search_Lucene::open($location);
} catch (Zend_Search_Lucene_Exception $e) {
$this->connection = Zend_Search_Lucene::create($location);
}
$this->inTransaction = 0;
if (!$this->connection) {
throw new ezcSearchCanNotConnectException('zendlucene', $location);
}
// Set proper default encoding for query parser
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
}
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:30,代码来源:zend_lucene.php
示例4: search
/**
* 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);
}
开发者ID:ookwudili,项目名称:chisimba,代码行数:43,代码来源:searchresults_class_inc.php
示例5: 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 {
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) {
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) {
throw new Zend_Search_Lucene_Search_QueryParserException( 'Syntax error at char position ' . $token->position . '.' );
}
throw $e;
}
}
if (count(self::$_instance->_contextStack) != 0) {
throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing.' );
}
return self::$_instance->_context->getQuery();
} catch (Zend_Search_Lucene_Search_QueryParserException $e) {
if (self::$_instance->_suppressQueryParsingExceptions) {
$queryTokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($strQuery, self::$_instance->_encoding);
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$termsSign = (self::$_instance->_defaultOperator == self::B_AND) ? true /* required term */ :
null /* optional term */;
foreach ($queryTokens as $token) {
$query->addTerm(new Zend_Search_Lucene_Index_Term($token->getTermText()), $termsSign);
}
return $query;
} else {
throw $e;
}
}
}
开发者ID:realfluid,项目名称:umbaugh,代码行数:68,代码来源:QueryParser.php
示例6: __construct
public function __construct()
{
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
//set default encoding
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_CJK());
//set default Analyzer
}
开发者ID:uniqid,项目名称:lucene,代码行数:7,代码来源:Indexes.php
示例7: 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)
{
if (self::$_instance === null) {
self::$_instance = new Zend_Search_Lucene_Search_QueryParser();
}
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) {
return new Zend_Search_Lucene_Search_Query_Empty();
}
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) {
throw new Zend_Search_Lucene_Search_QueryParserException('Syntax error at char position ' . $token->position . '.');
}
throw $e;
}
}
if (count(self::$_instance->_contextStack) != 0) {
throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing.');
}
return self::$_instance->_context->getQuery();
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:39,代码来源:QueryParser.php
示例8: useSearchIndex
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;
}
}
}
开发者ID:jdart,项目名称:diem,代码行数:30,代码来源:dmPageNotFoundHandler.php
示例9: index
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);
}
开发者ID:ascseb,项目名称:kosearch,代码行数:29,代码来源:search_example.php
示例10: addString
/**
* 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;
}
开发者ID:palcoprincipal,项目名称:sfLucenePlugin,代码行数:14,代码来源:sfLuceneCriteria.class.php
示例11: actionIndex
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));
}
}
开发者ID:awecode,项目名称:awecms,代码行数:25,代码来源:SearchController.php
示例12: getInstance
/**
* Returns Zend_Search_Lucene instance for given subroot
*
* every subroot has it's own instance
*
* @param Kwf_Component_Data for this index
* @return Zend_Search_Lucene_Interface
*/
public static function getInstance(Kwf_Component_Data $subroot)
{
while ($subroot) {
if (Kwc_Abstract::getFlag($subroot->componentClass, 'subroot')) {
break;
}
$subroot = $subroot->parent;
}
if (!$subroot) {
$subroot = Kwf_Component_Data_Root::getInstance();
}
static $instance = array();
if (!isset($instance[$subroot->componentId])) {
$analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive();
$analyzer->addFilter(new Zend_Search_Lucene_Analysis_TokenFilter_ShortWords(2));
//$stopWords = explode(' ', 'der dir das einer eine ein und oder doch ist sind an in vor nicht wir ihr sie es ich');
//$analyzer->addFilter(new Zend_Search_Lucene_Analysis_TokenFilter_StopWords($stopWords));
Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzer);
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
Zend_Search_Lucene_Storage_Directory_Filesystem::setDefaultFilePermissions(0666);
$path = 'cache/fulltext';
$path .= '/' . $subroot->componentId;
try {
$instance[$subroot->componentId] = Zend_Search_Lucene::open($path);
} catch (Zend_Search_Lucene_Exception $e) {
$instance[$subroot->componentId] = Zend_Search_Lucene::create($path);
}
}
return $instance[$subroot->componentId];
}
开发者ID:xiaoguizhidao,项目名称:koala-framework,代码行数:38,代码来源:Lucene.php
示例13: ZendSearchLuceneResults
/**
* 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'));
}
开发者ID:helpfulrobot,项目名称:asecondwill-lucene,代码行数:18,代码来源:ZendSearchLuceneContentController.php
示例14: searchTag
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);
}
开发者ID:ntulip,项目名称:joobsbox-php,代码行数:9,代码来源:Search.php
示例15: search
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;
}
开发者ID:httvncoder,项目名称:tugastkilucene,代码行数:9,代码来源:SearchController.php
示例16: __construct
public function __construct()
{
try {
parent::__construct(new Zend_Search_Lucene(self::INDEX_DIR, false));
} catch (Zend_Search_Lucene_Exception $e) {
parent::__construct(new Zend_Search_Lucene(self::INDEX_DIR, true));
}
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding("UTF-8");
}
开发者ID:rickboyau,项目名称:magento-lucene,代码行数:9,代码来源:Index.php
示例17: __construct
public function __construct()
{
$this->_log()->info('Starting up');
if (@preg_match('/\\pL/u', 'a') != 1) {
$this->_log()->err("PCRE unicode support is turned off.\n");
}
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding($this->_encoding);
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
}
开发者ID:rommmka,项目名称:axiscommerce,代码行数:9,代码来源:Indexer.php
示例18: emptyNotOperatorAction
public function emptyNotOperatorAction()
{
if (Zend_Search_Lucene_Search_QueryParser::getDefaultOperator() == Zend_Search_Lucene_Search_QueryParser::B_AND) {
// Do nothing
} else {
$this->orOperatorAction();
}
// Process NOT operator
$this->notOperatorAction();
}
开发者ID:hackingman,项目名称:TubeX,代码行数:10,代码来源:BooleanExpressionRecognizer.php
示例19: searchAction
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;
}
}
开发者ID:ngukho,项目名称:ducbui-cms,代码行数:10,代码来源:PublicController.php
示例20: testQueryParser
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]);
}
}
开发者ID:jorgenils,项目名称:zend-framework,代码行数:11,代码来源:SearchTest.php
注:本文中的Zend_Search_Lucene_Search_QueryParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论