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');
     }
 }
 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;
 }
 /**
  * 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;
 }
Ejemplo n.º 4
0
 public static function indexationSearch($searchParams)
 {
     Zend_Search_Lucene::setDefaultSearchField('contents');
     $directory = Zend_Registry::get('lucene_index');
     $index = new Zend_Search_Lucene($directory);
     $words = strtolower(Cible_FunctionsGeneral::removeAccents(Cible_FunctionsGeneral::html2text(utf8_decode($searchParams['words']))));
     $wordsArray = explode(' ', $words);
     if (count($wordsArray) > 1) {
         $query = new Zend_Search_Lucene_Search_Query_Phrase($wordsArray);
     } else {
         if (strlen($words) >= 3) {
             $pattern = new Zend_Search_Lucene_Index_Term("{$words}*");
             $query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
         } else {
             $term = new Zend_Search_Lucene_Index_Term($words);
             $query = new Zend_Search_Lucene_Search_Query_Term($term);
         }
     }
     $hits = $index->find($query);
     //echo($query);
     $i = 0;
     $result = array();
     foreach ($hits as $hit) {
         $result[$i]['moduleID'] = $hit->moduleID;
         $result[$i]['pageID'] = $hit->pageID;
         $result[$i]['contentID'] = $hit->contentID;
         $result[$i]['languageID'] = $hit->languageID;
         $result[$i]['title'] = $hit->title;
         $result[$i]['text'] = $hit->text;
         $result[$i]['link'] = $hit->link;
         $i++;
     }
     return $result;
 }
Ejemplo n.º 5
0
 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));
     }
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 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;
 }
 //    public function init(){
 //       Yii::import('application.vendors.*');
 //       require_once('Zend/Search/Lucene.php');
 //       parent::init();
 //   }
 public function actionSearch()
 {
     $this->layout = 'column2';
     if (($term = Yii::app()->getRequest()->getParam('q', null)) !== null) {
         $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
Ejemplo n.º 9
0
 /**
  *
  * @return array
  * @param string | Zend_Search_Lucene_Search_Query_Boolean $fuzzyQuery
  */
 public function findFuzzy($fuzzyQuery)
 {
     if (!is_string($fuzzyQuery)) {
         $fuzzyQuery = $fuzzyQuery->__toString();
     }
     $result = array();
     foreach ($this->_index->find($fuzzyQuery) as $hit) {
         $result[] = $hit->id;
     }
     return $result;
 }
 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'));
     }
 }
Ejemplo n.º 11
0
 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'));
     }
 }
Ejemplo n.º 12
0
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 :-|
    }
}
Ejemplo n.º 13
0
 public function indexAction()
 {
     if ($this->hasParam('text')) {
         $userQuery = Zend_Search_Lucene_Search_QueryParser::parse($this->getParam('text'));
         $hits = $this->_indexHandle->find($userQuery);
         $result = array();
         foreach ($hits as $hit) {
             if (mb_strlen($hit->content) > 200) {
                 $firstWord = current(explode(' ', $this->getParam('text')));
                 $posWord = mb_strpos($hit->content, $firstWord);
                 $before = mb_substr($hit->content, $posWord - 100, 100);
                 // 20 символов до слова
                 $after = mb_substr($hit->content, $posWord, 100);
                 // 100 символов после слова
                 $text = '...' . $before . $after . '...';
             } else {
                 $text = $hit->content;
             }
             array_push($result, array('title' => $hit->title, 'url' => $hit->url, 'content' => $userQuery->htmlFragmentHighlightMatches($text)));
         }
         $this->view->result = $result;
     }
     $this->view->text = $this->getParam('text');
 }
Ejemplo n.º 14
0
 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 />';
     }
 }
 function onSearchLucene($text, $phrase = '', $ordering = '', $areas = null)
 {
     if (is_array($areas) && count($areas) > 0) {
         if (!array_intersect($areas, array_keys($this->areas))) {
             return array();
         }
     }
     $params = JComponentHelper::getParams('com_search_lucene');
     $indexpath = $params->get('indexpath');
     $pluginindex = $indexpath . DS . $this->pluginName;
     $index = new Zend_Search_Lucene($pluginindex);
     if ($index) {
         $rows = $index->find($text);
     } else {
         $rows = array();
     }
     return $rows;
 }
 /**
  * removeFromIndex
  * @param string $strIndexPath
  * @param string $strKey
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 protected final function removeFromIndex($strIndexPath, $strKey)
 {
     try {
         if (count(scandir($strIndexPath)) > 2) {
             $this->objIndex = Zend_Search_Lucene::open($strIndexPath);
             $objTerm = new Zend_Search_Lucene_Index_Term($strKey, 'key');
             $objQuery = new Zend_Search_Lucene_Search_Query_Term($objTerm);
             $objHits = $this->objIndex->find($objQuery);
             foreach ($objHits as $objHit) {
                 $this->objIndex->delete($objHit->id);
             }
             $this->objIndex->commit();
             $this->objIndex->optimize();
         }
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
 /**
  * removeFromIndex
  * @param string $strIndexPath
  * @param string $strKey
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 protected final function removeFromIndex($strIndexPath, $strKey)
 {
     try {
         $this->core->logger->debug('massiveart->generic->data->types->GenericDataTypeAbstract->removeFromIndex(' . $strIndexPath . ', ' . $strKey . ')');
         if (count(scandir($strIndexPath)) > 2) {
             $this->objIndex = Zend_Search_Lucene::open($strIndexPath);
             $objTerm = new Zend_Search_Lucene_Index_Term($strKey, 'key');
             $objQuery = strpos($strKey, '*') !== false ? new Zend_Search_Lucene_Search_Query_Wildcard($objTerm) : new Zend_Search_Lucene_Search_Query_Term($objTerm);
             $objHits = $this->objIndex->find($objQuery);
             foreach ($objHits as $objHit) {
                 $this->objIndex->delete($objHit->id);
             }
             $this->objIndex->commit();
             $this->objIndex->optimize();
         }
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
 public function actionResult()
 {
     if (isset($_GET)) {
         $term = $_GET['keyword'];
         $index = new Zend_Search_Lucene(Yii::getPathOfAlias($this->_indexFilesPath));
         $results = $index->find($term);
         //print_r($results);
         //exit();
         if (isset($_GET['type'])) {
             $dataProvider = new CPagination(count($results));
             $currentPage = Yii::app()->getRequest()->getQuery('page', 1);
             $dataProvider->pageSize = 10;
             $pager = OFunction::getDataProviderPager($dataProvider, false);
             $get = array_merge($_GET, array($pager['pageVar'] => $pager['nextPage']));
             $nextPager = $pager['nextPage'] != 0 ? OFunction::validHostURL(Yii::app()->controller->createUrl('result', $get)) : '-';
             //print_r($pager);
             $data = '';
             if (!empty($results)) {
                 $i = $currentPage * $dataProvider->pageSize - $dataProvider->pageSize;
                 $end = $currentPage * $dataProvider->pageSize;
                 //foreach($results as $key => $item) {
                 for ($i = $i; $i < $end; $i++) {
                     $data[] = array('id' => CHtml::encode($results[$i]->id), 'category' => CHtml::encode($results[$i]->category), 'media' => CHtml::encode($results[$i]->media), 'title' => CHtml::encode($results[$i]->title), 'body' => CHtml::encode($results[$i]->body), 'date' => CHtml::encode($results[$i]->date), 'view' => CHtml::encode($results[$i]->view));
                 }
             } else {
                 $data = array();
             }
             $return = array('data' => $data, 'pager' => $pager, 'nextPager' => $nextPager);
             echo CJSON::encode($return);
         } else {
             $query = Zend_Search_Lucene_Search_QueryParser::parse($term);
             $this->pageTitleShow = true;
             $this->pageTitle = 'Hasil Pencarian: ' . $_GET['keyword'];
             $this->pageDescription = '';
             $this->pageMeta = '';
             $this->render('application.webs.search.front_result', compact('results', 'term', 'query'));
         }
     } else {
         $this->redirect(Yii::app()->createUrl('site/index'));
     }
 }
Ejemplo n.º 19
0
 * This file is part of the allocPSA application <*****@*****.**>.
 * 
 * allocPSA is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * allocPSA is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with allocPSA. If not, see <http://www.gnu.org/licenses/>.
*/
define("NO_REDIRECT", 1);
require_once "../alloc.php";
$index = new Zend_Search_Lucene(ATTACHMENTS_DIR . 'search/task');
$index->setResultSetLimit(10);
$needle = 'name:(' . $_GET["taskName"] . ') AND pid:' . $_GET["projectID"];
$query = Zend_Search_Lucene_Search_QueryParser::parse($needle);
$hits = $index->find($needle);
foreach ($hits as $hit) {
    $d = $hit->getDocument();
    $str .= "<div style='padding-bottom:3px'>";
    $str .= "<a href=\"" . $TPL["url_alloc_task"] . "taskID=" . $d->getFieldValue('id') . "\">" . $d->getFieldValue('id') . " " . $d->getFieldValue('name') . "</a>";
    $str .= "</div>";
}
if ($str) {
    echo $str;
}
Ejemplo n.º 20
0
 public function searchAction()
 {
     Zend_Registry::set('theaction', 'content');
     $this->toTpl('theInclude', 'list');
     Zend_Registry::set('module', 'Search Results');
     //error_reporting(E_ALL);
     $data = $this->_request->getParams();
     if (trim($data['q'])) {
         $dirs = $this->dirs;
         $word = strtolower($data['q']);
         $index = new Zend_Search_Lucene(APPL_PATH . $dirs['structure']['indexes'] . DIR_SEP . "objects");
         $exp = explode(" ", $word);
         $query = new Zend_Search_Lucene_Search_Query_Phrase($exp);
         $query->setSlop(2);
         //get all available indexed
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
         Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
         Zend_Search_Lucene::setResultSetLimit(10);
         $result = $index->find($query);
         foreach ($result as $hit) {
             $obj = $this->getAllBySlug($hit->slug);
             $type = $this->getContentType($obj['type_id']);
             $content = $this->getContent($type['title'], $obj['id']);
             $resu[] = $content;
         }
         $resu = $this->doQoolHook('front_pre_assign_search_results', $resu);
         $this->toTpl('content', $resu);
     } else {
         $params = array("message" => $this->t("Please fill in a search term"), "msgtype" => 'error');
         $this->addMessage($params);
         $this->_helper->redirector('index', 'index', 'default');
     }
 }
Ejemplo n.º 21
0
 /**
  * Searches using the search index for applicable topics, and returns topics as an array
  * Note that this will return ALL topics for the search.  No limit / pagination can be applied.
  * @param string $strSearchQuery
  * @return Topic[]
  */
 public static function LoadArrayBySearch($strSearchQuery)
 {
     // open the index
     $objIndex = new Zend_Search_Lucene(__SEARCH_INDEXES__ . '/topics');
     $intIdArray = array();
     $objHits = $objIndex->find($strSearchQuery);
     if (!count($objHits)) {
         return array();
     }
     foreach ($objHits as $objHit) {
         $intIdArray[] = $objHit->db_id;
         // note: do we want to do anything with $objHit->score (?)
     }
     $objResult = Topic::GetDatabase()->Query('SELECT * FROM topic WHERE id IN(' . implode(',', $intIdArray) . ');');
     while ($objRow = $objResult->GetNextRow()) {
         $objTopic = Topic::InstantiateDbRow($objRow);
         $objTopicArrayById[$objTopic->Id] = $objTopic;
     }
     $objTopicArray = array();
     foreach ($objHits as $objHit) {
         $objTopicArray[] = $objTopicArrayById[intval($objHit->db_id)];
     }
     return $objTopicArray;
 }
Ejemplo n.º 22
0
 public static function saveSearchIndex()
 {
     $index = new Zend_Search_Lucene(sfConfig::get('sf_lib_dir') . '/modules/search/tmp/lucene.user.index', true);
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $this->pageDocument->getId()));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('pageid', $this->pageDocument->getId()));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('title', $this->pageDocument->getNavigationTitle()));
     $blobData = $this->pageDocument->getContent();
     // $blockContents = $blobData->__toString();
     $blockContents = $blobData;
     $doc->addField(Zend_Search_Lucene_Field::Unstored('contents', $blockContents . ' ' . $this->pageDocument->getNavigationTitle()));
     $index->addDocument($doc);
     $index->commit();
     $hits = $index->find(strtolower('maquette'));
     foreach ($hits as $hit) {
         //			echo $hit->score.'<br/>';
         //			echo $hit->id;
         //			echo $hit->contents.'<br/>';
         echo $hit->pageid;
     }
 }
Ejemplo n.º 23
0
<?php

require 'includes/application_top.php';
require 'zend.php';
Zend::loadClass('Zend_Search_Lucene');
$index = new Zend_Search_Lucene('/Inetpub/wwwroot/aa', true);
$doc = new Zend_Search_Lucene_Document();
// Store document URL to identify it in search result.
$q = $db->query("select * from products");
while ($r = $db->fetch($q)) {
    $doc->addField(Zend_Search_Lucene_Field::Text('products_name', strtolower($r['products_name'])));
    $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', strtolower($r['products_description'])));
    $index->addDocument($doc);
}
$index->commit();
$index = new Zend_Search_Lucene('/Inetpub/wwwroot/aa');
$hits = $index->find('punch');
foreach ($hits as $hit) {
    echo $hit->score;
    echo '<br>';
    echo $hit->products_name;
    echo '<br>';
}
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Search_Lucene
 * @subpackage Demos
 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
/**
 * @see Zend_Search_Lucene
 */
require_once 'Zend/Search/Lucene.php';
$index = new Zend_Search_Lucene('/tmp/feeds_index');
echo "Index contains {$index->count()} documents.\n";
$search = 'php';
$hits = $index->find(strtolower($search));
echo "Search for \"{$search}\" returned " . count($hits) . " hits.\n\n";
foreach ($hits as $hit) {
    echo str_repeat('-', 80) . "\n";
    echo 'ID:    ' . $hit->id . "\n";
    echo 'Score: ' . sprintf('%.2f', $hit->score) . "\n\n";
    foreach ($hit->getDocument()->getFieldNames() as $field) {
        echo "{$field}: \n";
        echo '    ' . trim(substr($hit->{$field}, 0, 76)) . "\n";
    }
}
Ejemplo n.º 25
0
	public static function search( $query, $subqueries = array()) {
		
		$query = strtolower($query);
		
		Loader::library('3rdparty/Zend/Search/Lucene');
		Loader::library('3rdparty/StandardAnalyzer/Analyzer/Standard/English');
		
		$index = new Zend_Search_Lucene(DIR_FILES_CACHE_PAGES);
		$index->setResultSetLimit(200);
		
		//Zend_Search_Lucene_Analysis_Analyzer::setDefault(new StandardAnalyzer_Analyzer_Standard_English());
		Zend_Search_Lucene_Analysis_Analyzer::setDefault(new StandardAnalyzer_Analyzer_Standard_English());
		
		$queryModifiers=array();

		$mainQuery = Zend_Search_Lucene_Search_QueryParser::parse($query, APP_CHARSET);

		$query = new Zend_Search_Lucene_Search_Query_Boolean();
		$query->addSubquery($mainQuery, true);
		
		foreach($subqueries as $subQ) {
			if( !is_array($subQ) || !isset( $subQ['query'] ) )
				 $subQuery = $subQ;				 
			else $subQuery = $subQ['query']; 			
						
			if( !is_array($subQ) || !isset($subQ['required']) )
				 $required=true;
			else $required=$subQ['required'];
			
			$query->addSubquery( $subQuery, $required );	
		}
		$query = utf8_encode($query);
		$resultsTmp = $index->find($query);

		$results = array();
		foreach($resultsTmp as $r)
			$results[] = new IndexedSearchResult($r->cID, $r->cName, $r->cDescription, $r->score, $r->cPath, $r->cBody);
		
		return $results;
	}
Ejemplo n.º 26
0
 public function searchAction()
 {
     Zend_Registry::set('theaction', 'content');
     $this->toTpl('theInclude', 'search');
     Zend_Registry::set('module', 'Search Results');
     //error_reporting(E_ALL);
     $data = $this->_request->getParams();
     $dirs = $this->dirs;
     $word = strtolower($data['q']);
     $index = new Zend_Search_Lucene(APPL_PATH . $dirs['structure']['indexes'] . DIR_SEP . "objects");
     $exp = explode(" ", $word);
     $query = new Zend_Search_Lucene_Search_Query_Phrase($exp);
     $query->setSlop(2);
     //get all available indexed
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     Zend_Search_Lucene::setResultSetLimit(10);
     $result = $index->find($query);
     foreach ($result as $hit) {
         $cid = $this->getIdBySlug($hit->slug);
         $content = $this->getContent($hit->type_id, $cid);
         $content['id'] = $cid;
         $content['type_id'] = $hit->type_id;
         $content['type'] = $this->getContentType($hit->type_id);
         $resu[] = $content;
     }
     $this->toTpl('theList', $resu);
 }
Ejemplo n.º 27
0
 private function updateEntryInSearch($url, array $content = null)
 {
     $options = $this->getInvokeArg('bootstrap')->getOption('lucene');
     $index = new Zend_Search_Lucene($options['dir']);
     $hits = $index->find('url:' . $url);
     foreach ($hits as $hit) {
         $index->delete($hit->id);
     }
     if (!$content) {
         return;
     } else {
         $this->addEntryToSearchIndex($url, $content);
     }
 }
Ejemplo n.º 28
0
//get the indexers.
include 'quickstart_index.php';
include 'api_index.php';
if (isset($argv[1])) {
    if (strtolower($argv[1]) == "quickstart") {
        $quickstart = new quickstart_index($quickstart_target, $quickstart_base, $quickstart_source);
        $quickstart->create_index();
    } else {
        if (strtolower($argv[1]) == "api") {
            $api = new api_index($api_target, $api_source);
            $api->create_index();
        } else {
            $q = new Zend_Search_Lucene($quickstart_target);
            $query = $argv[1];
            $hits = $q->find(strtolower($query));
            echo "Found " . count($hits) . " for " . $query . " in quick start\n";
            foreach ($hits as $hit) {
                echo "   " . $hit->title . "\n";
            }
            $a = new Zend_Search_Lucene($api_target);
            $query = $argv[1];
            $hits = $a->find(strtolower($query));
            echo "\nFound " . count($hits) . " for " . $query . " in API\n";
            foreach ($hits as $hit) {
                echo "   " . $hit->link . "\n";
            }
        }
    }
} else {
    echo "Usage: 'php build.php quickstart' or 'php build.php api'\n";
}
Ejemplo n.º 29
0
     $table = SEARCH_DATABASE_TABLE;
     $query = "\n                                SELECT \n                                    docid,\n                                    itemtype\n                                FROM \n                                    {$CFG->prefix}{$table}\n                                WHERE\n                                    doctype = '{$values[1]}'\n                                    {$itemtypes}\n                            ";
     $docIds = get_records_sql_menu($query, array($mod->name));
     $docIdList = $docIds ? implode("','", array_keys($docIds)) : '';
     $query = "\n                                SELECT \n                                    id, \n                                    {$values[0]} as docid\n                                FROM \n                                    {$CFG->prefix}{$values[1]} \n                                WHERE \n                                    {$values[3]} > {$indexdate} AND \n                                    id IN ('{$docIdList}')\n                                    {$where}\n                            ";
     $records = get_records_sql($query);
     if (is_array($records)) {
         foreach ($records as $record) {
             $updates[] = $delete_function($record->docid, $docIds[$record->docid]);
         }
     }
 }
 foreach ($updates as $update) {
     ++$update_count;
     //delete old document
     $doc = $index->find("+docid:{$update->id} +doctype:{$mod->name} +itemtype:{$update->itemtype}");
     //get the record, should only be one
     foreach ($doc as $thisdoc) {
         mtrace("  Delete: {$thisdoc->title} (database id = {$thisdoc->dbid}, index id = {$thisdoc->id}, moodle instance id = {$thisdoc->docid})");
         $dbcontrol->delDocument($thisdoc);
         $index->delete($thisdoc->id);
     }
     //add new modified document back into index
     if (!($add = $get_document_function($update->id, $update->itemtype))) {
         // ignore on errors
         continue;
     }
     //object to insert into db
     $dbid = $dbcontrol->addDocument($add);
     //synchronise db with index
     $add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
Ejemplo n.º 30
0
 /**
  *
  * Perform a lucene query directly
  *
  * @param String $query
  * @return
  */
 public function query($query)
 {
     $hits = $this->index->find(strtolower($query));
     return $hits;
 }