本文整理汇总了PHP中Zend_Search_Lucene类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene类的具体用法?PHP Zend_Search_Lucene怎么用?PHP Zend_Search_Lucene使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Search_Lucene类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: getDocument
/**
* Return the document object for this hit
*
* @return Zend_Search_Lucene_Document
*/
public function getDocument()
{
if (!$this->_document instanceof Zend_Search_Lucene_Document) {
$this->_document = $this->_index->getDocument($this->id);
}
return $this->_document;
}
示例3: onSearchLucene
function onSearchLucene($text, $phrase = '', $ordering = '', $areas = null)
{
if (is_array($areas) && count($areas) > 0) {
if (!array_intersect($areas, array_keys($this->areas))) {
return array();
}
} else {
if (count($areas) == 0) {
$areas = array();
foreach ($this->areas as $k => $v) {
$areas[] = $k;
}
}
}
$results = array();
$params = JComponentHelper::getParams('com_search_lucene');
$indexpath = $params->get('indexpath');
$pluginindex = $indexpath . DS . $this->pluginName;
$index = new Zend_Search_Lucene($pluginindex);
$search = '(';
foreach ($areas as $area) {
if (array_key_exists($area, $this->areas)) {
$search .= ' type:' . $area;
}
}
$search .= ')';
if ($index && strlen($text) > 3) {
$rows = $index->find($text . ' AND ' . $search);
} else {
$rows = array();
}
return $rows;
}
示例4: __construct
public function __construct($path = SEARCH_INDEX_PATH)
{
global $CFG, $db;
$this->path = $path;
//test to see if there is a valid index on disk, at the specified path
try {
$test_index = new Zend_Search_Lucene($this->path, false);
$validindex = true;
} catch (Exception $e) {
$validindex = false;
}
//retrieve file system info about the index if it is valid
if ($validindex) {
$this->size = display_size(get_directory_size($this->path));
$index_dir = get_directory_list($this->path, '', false, false);
$this->filecount = count($index_dir);
$this->indexcount = $test_index->count();
} else {
$this->size = 0;
$this->filecount = 0;
$this->indexcount = 0;
}
$db_exists = false;
//for now
//get all the current tables in moodle
$admin_tables = $db->MetaTables();
//TODO: use new IndexDBControl class for database checks?
//check if our search table exists
if (in_array($CFG->prefix . SEARCH_DATABASE_TABLE, $admin_tables)) {
//retrieve database information if it does
$db_exists = true;
//total documents
$this->dbcount = count_records(SEARCH_DATABASE_TABLE);
//individual document types
// $types = search_get_document_types();
$types = search_collect_searchables(true, false);
sort($types);
foreach ($types as $type) {
$c = count_records(SEARCH_DATABASE_TABLE, 'doctype', $type);
$this->types[$type] = (int) $c;
}
} else {
$this->dbcount = 0;
$this->types = array();
}
//check if the busy flag is set
if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
$this->complete = false;
} else {
$this->complete = true;
}
//get the last run date for the indexer
if ($this->valid() && $CFG->search_indexer_run_date) {
$this->time = $CFG->search_indexer_run_date;
} else {
$this->time = 0;
}
}
示例5: 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;
}
示例6: 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');
}
}
示例7: actionSearch
public function actionSearch()
{
//working.
$this->layout = 'column2';
if (($term = Yii::app()->getRequest()->getParam('q', null)) !== null) {
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
$results = $index->find($term);
$query = Zend_Search_Lucene_Search_QueryParser::parse($term);
$this->render('search', compact('results', 'term', 'query'));
}
}
示例8: actionSearch
public function actionSearch()
{
$indexFiles = Yii::app()->getModule('zendsearch')->indexFiles;
SetLocale(LC_ALL, 'ru_RU.UTF-8');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
if (($term = Yii::app()->getRequest()->getQuery('q', null)) !== null) {
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $indexFiles));
$results = $index->find($term);
$query = Zend_Search_Lucene_Search_QueryParser::parse($term);
$this->render('search', compact('results', 'term', 'query'));
}
}
示例9: fill_index
function fill_index()
{
for ($i = 0; $i < 10; $i++) {
$index = new Zend_Search_Lucene('./data/index', true);
$index->find("test");
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text("test", getword()));
$doc->addField(Zend_Search_Lucene_Field::UnStored("contents", getword()));
$index->addDocument($doc);
$index->commit();
$index->getDirectory()->close();
//comment this to see another bug :-|
}
}
示例10: compact
$results = $index->find($term);
$query = Zend_Search_Lucene_Search_QueryParser::parse($term);
$this->render('/sParameter/search', compact('results', 'term', 'query'));
}
}
/**
* Search index creation
*/
public function actionCreate()
{
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles), true);
$posts = tAccount::model()->findAll();
foreach ($posts as $post) {
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('account_no', CHtml::encode($post->account_no), 'utf-8'));
示例11: search
function search($query)
{
$this->load->library('zend', 'Zend/Search/Lucene');
$this->load->library('zend');
$this->zend->load('Zend/Search/Lucene');
$index = new Zend_Search_Lucene('C:\\xampp\\xampp\\htdocs\\controle_frota\\lucene\\feeds_index');
$hits = $index->find($query);
echo 'Index contains ' . $index->count() . ' documents.<br /><br />';
echo 'Search for "' . $query . '" returned ' . count($hits) . ' hits<br /><br />';
foreach ($hits as $hit) {
echo $hit->title . '<br />';
echo 'Score: ' . sprintf('%.2f', $hit->score) . '<br />';
echo $hit->link . '<br /><br />';
}
}
示例12: getLucene
private function getLucene()
{
if ($this->lucene) {
return $this->lucene;
}
try {
$this->lucene = Zend_Search_Lucene::open($this->directory);
} catch (Zend_Search_Lucene_Exception $e) {
$this->lucene = Zend_Search_Lucene::create($this->directory);
}
global $prefs;
if (!empty($prefs['unified_lucene_max_buffered_docs'])) {
// these break indexing if set empty
$this->lucene->setMaxBufferedDocs($prefs['unified_lucene_max_buffered_docs']);
// default is 10
}
if (!empty($prefs['unified_lucene_max_merge_docs'])) {
$this->lucene->setMaxMergeDocs($prefs['unified_lucene_max_merge_docs']);
// default is PHP_INT_MAX (effectively "infinite")
}
if (!empty($prefs['unified_lucene_merge_factor'])) {
$this->lucene->setMergeFactor($prefs['unified_lucene_merge_factor']);
// default is 10
}
$this->lucene->setResultSetLimit($this->resultSetLimit);
return $this->lucene;
}
示例13: query
/**
* Enter description here...
*
* @param string $query
* @return array
*/
public function query($query)
{
$results = array();
$queryDiscussion = stripos($query, 'discussion') !== false;
$queryContent = stripos($query, 'content') !== false;
$query = Zend_Search_Lucene_Search_QueryParser::parse($query);
$hits = $this->lucene->find($query);
foreach ($hits as $hit) {
$document = $hit->getDocument();
$document_id = PHPLuceneIndexer::stringToLong($document->DocumentID);
$coreText = '';
if ($queryContent) {
$coreText .= $document->Content;
}
if ($queryDiscussion) {
$coreText .= $document->Discussion;
}
$content = $query->highlightMatches($coreText);
$title = $document->Title;
$score = $hit->score;
// avoid adding duplicates. If it is in already, it has higher priority.
if (!array_key_exists($document_id, $results) || $score > $results[$document_id]->Score) {
$item = new QueryResultItem($document_id, $score, $title, $content);
if ($item->CanBeReadByUser) {
$results[$document_id] = $item;
}
}
}
return $results;
}
示例14: initLuceneEngine
protected function initLuceneEngine()
{
$this->load->library('zend', 'Zend/Search/Lucene');
$this->load->library('zend');
$this->zend->load('Zend/Search/Lucene');
Zend_Search_Lucene::setDefaultSearchField('content');
}
示例15: luceneSearchAction
public function luceneSearchAction()
{
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$path = PUBLIC_PATH . '/tmp/lucene';
$index = Zend_Search_Lucene::open($path);
// $term = new Zend_Search_Lucene_Index_Term('ritesh','title');
// $subquery1 = new Zend_Search_Lucene_Search_Query_Term($term);
//
// $from = new Zend_Search_Lucene_Index_Term('0', 'empcode');
// $to = new Zend_Search_Lucene_Index_Term('53', 'empcode');
// $subquery2 = new Zend_Search_Lucene_Search_Query_Range($from, $to, true);
//
// $query = new Zend_Search_Lucene_Search_Query_Boolean();
// $query->addSubquery($subquery1, true );
// $query->addSubquery($subquery2, null );
// Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
// $hits = $index->find($query);
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(1);
$hits = $index->find("empcode:[000 TO 200]");
foreach ($hits as $h) {
echo "Title:" . $h->title;
echo "-------EmpCode:" . $h->empcode;
echo "<br>";
}
}