本文整理汇总了PHP中Zend_Search_Lucene_Field::keyword方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Field::keyword方法的具体用法?PHP Zend_Search_Lucene_Field::keyword怎么用?PHP Zend_Search_Lucene_Field::keyword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Search_Lucene_Field
的用法示例。
在下文中一共展示了Zend_Search_Lucene_Field::keyword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
public function add($needFields = array(), $data = array(), $charset = 'UTF-8')
{
$index = new Zend_Search_Lucene(ZY_ROOT . '/index', true);
$doc = new Zend_Search_Lucene_Document();
foreach ($needFields as $key => $field) {
switch ($field) {
case 'keywords':
$doc->addField(Zend_Search_Lucene_Field::keyword($key, $data[$key], $charset));
break;
case 'text':
$doc->addField(Zend_Search_Lucene_Field::text($key, $data[$key], $charset));
break;
case 'unindexed':
$doc->addField(Zend_Search_Lucene_Field::unindexed($key, $data[$key], $charset));
break;
default:
$doc->addField(Zend_Search_Lucene_Field::$field($key, $data[$key], $charset));
break;
}
}
$index->addDocument($doc);
$index->commit();
$index->optimize();
return TRUE;
}
示例2: luceneIndexAction
public function luceneIndexAction()
{
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$path = PUBLIC_PATH . '/tmp/lucene';
try {
$index = Zend_Search_Lucene::open($path);
} catch (Zend_Search_Lucene_Exception $e) {
try {
$index = Zend_Search_Lucene::create($path);
} catch (Zend_Search_Lucene_Exception $e) {
echo "Unable to open or create index : {$e->getMessage()}";
}
}
for ($i = 0; $i < $index->maxDoc(); $i++) {
$index->delete($i);
}
$users = new Application_Model_User();
$users = $users->fetchAll();
foreach ($users as $_user) {
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('title', $_user->getFirstName()));
$doc->addField(Zend_Search_Lucene_Field::keyword('empcode', $_user->getEmployeeCode()));
$index->addDocument($doc);
$index->commit();
$index->optimize();
}
}
示例3: addPageToIndex
public static function addPageToIndex($page, $toasterSearchIndex = false)
{
if (!self::initIndex()) {
return false;
}
if ($page instanceof Application_Model_Models_Page) {
$page = $page->toArray();
$containers = Application_Model_Mappers_ContainerMapper::getInstance()->findByPageId($page['id']);
$page['content'] = '';
if (!empty($containers)) {
foreach ($containers as $container) {
$page['content'] .= $container->getContent();
}
}
}
$document = new Zend_Search_Lucene_Document();
$document->addField(Zend_Search_Lucene_Field::keyword('pageId', $page['id']));
$document->addField(Zend_Search_Lucene_Field::unStored('metaKeyWords', $page['metaKeywords'], 'UTF-8'));
$document->addField(Zend_Search_Lucene_Field::unStored('metaDescription', $page['metaDescription'], 'UTF-8'));
$document->addField(Zend_Search_Lucene_Field::unStored('headerTitle', $page['headerTitle'], 'UTF-8'));
$document->addField(Zend_Search_Lucene_Field::unStored('content', $page['content'], 'UTF-8'));
$document->addField(Zend_Search_Lucene_Field::text('draft', $page['draft'], 'UTF-8'));
$document->addField(Zend_Search_Lucene_Field::text('teaserText', $page['teaserText'], 'UTF-8'));
$document->addField(Zend_Search_Lucene_Field::text('url', $page['url'], 'UTF-8'));
$document->addField(Zend_Search_Lucene_Field::text('navName', $page['navName'], 'UTF-8'));
$document->addField(Zend_Search_Lucene_Field::text('h1', $page['h1'], 'UTF-8'));
// $document->addField(Zend_Search_Lucene_Field::text('previewImage', $page['previewImage']));
self::$_index->addDocument($document);
}
示例4: buildplaces
public function buildplaces()
{
ini_set('memory_limit', '1000M');
set_time_limit(0);
$time = time();
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
/**
* Create index
*/
$index = Zend_Search_Lucene::create($this->_indexPath);
/**
* Get all users
*/
$sql = $this->_db->select()->from($this->_name, array('id', 'name', 'placepic'))->limit(7500);
$result = $this->_db->fetchAssoc($sql);
foreach ($result as $values) {
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::keyword('placeid', $values['id']));
$doc->addField(Zend_Search_Lucene_Field::text('placename', $values['name']));
$doc->addField(Zend_Search_Lucene_Field::unStored('placepic', $values['placepic']));
$index->addDocument($doc);
}
$index->commit();
$elapsed = time() - $time;
print_r($elapsed);
}
示例5: index
/**
* Index a file
*
* @param string $filePath The file path
*/
public function index($filePath)
{
$content = file_get_contents($filePath);
$modificationTime = filemtime($filePath);
$checksum = md5($content);
// Get the document
$hits = $this->_data->find('path:' . $filePath);
if (count($hits) > 0) {
$hit = $hits[0];
$document = $hit->getDocument();
// If the checksums are the same, no need to update
if ($checksum === $document->checksum) {
return;
}
// Delete the document
$this->_data->delete($hit);
}
// Create a new document
$document = new Zend_Search_Lucene_Document();
$document->addField(Zend_Search_Lucene_Field::keyword('path', $filePath));
$document->addField(Zend_Search_Lucene_Field::keyword('modificationTime', $modificationTime));
$document->addField(Zend_Search_Lucene_Field::keyword('checksum', $checksum));
$document->addField(Zend_Search_Lucene_Field::unStored('content', $content, 'utf-8'));
$this->_data->addDocument($document);
// Commit the changes
$this->_data->commit();
$this->_data->optimize();
}
示例6: __construct
public function __construct(Storefront_Resource_Product_Item_Interface $item, $category)
{
$this->addField(Zend_Search_Lucene_Field::keyword('productId', $item->productId, 'UTF-8'));
$this->addField(Zend_Search_Lucene_Field::text('categories', $category, 'UTF-8'));
$this->addField(Zend_Search_Lucene_Field::text('name', $item->name, 'UTF-8'));
$this->addField(Zend_Search_Lucene_Field::unStored('description', $item->description, 'UTF-8'));
$this->addField(Zend_Search_Lucene_Field::text('price', $this->_formatPrice($item->getPrice()), 'UTF-8'));
}
示例7: addPost
public function addPost(Post $post, $feed)
{
$index = Zend_Search_Lucene::open(Zend_Registry::getInstance()->config->search->post);
$feed = $post->findParentFeeds();
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('pid', $post->id));
$doc->addField(Zend_Search_Lucene_Field::Text('title', $post->title));
$doc->addField(Zend_Search_Lucene_Field::Text('siteUrl', $feed->siteUrl));
$doc->addField(Zend_Search_Lucene_Field::Text('link', $post->link));
$doc->addField(Zend_Search_Lucene_Field::Text('feedTitle', $feed->title));
$doc->addField(Zend_Search_Lucene_Field::Text('feedSlug', $feed->slug));
$doc->addField(Zend_Search_Lucene_Field::Text('feedDescription', $feed->description));
$doc->addField(Zend_Search_Lucene_Field::keyword('category', $feed->findParentCategories()->title));
$doc->addField(Zend_Search_Lucene_Field::Text('description', $post->description));
$doc->addField(Zend_Search_Lucene_Field::unIndexed('publishDate', $post->publishDate));
$doc->addField(Zend_Search_Lucene_Field::Keyword('type', 'post'));
$index->addDocument($doc);
}
示例8: actionCreate
public function actionCreate()
{
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles), true);
$items = Items::model()->findAll();
foreach ($items as $item) {
$doc = new Zend_Search_Lucene_Document();
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
$doc->addField(Zend_Search_Lucene_Field::keyword('part_number', CHtml::encode($item->part_number), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::Text('name', CHtml::encode($item->name), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::Text('description', CHtml::encode($item->description), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::Text('barcode', CHtml::encode($item->barcode), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::float('available_quantity', CHtml::encode($item->available_quantity), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::float('current_quantity', CHtml::encode($item->current_quantity), 'utf-8'));
$index->addDocument($doc);
}
$index->commit();
echo 'Lucene index created';
}
示例9: __construct
public function __construct($class, $key, $title, $contents, $summary, $createdBy, $dateCreated, $keywords = array())
{
$this->addField(Zend_Search_Lucene_Field::Keyword('docRef', "{$class}:{$key}"));
$this->addField(Zend_Search_Lucene_Field::UnIndexed('class', $class));
$this->addField(Zend_Search_Lucene_Field::UnIndexed('key', $key));
$this->addField(Zend_Search_Lucene_Field::Text('title', $title));
$this->addField(Zend_Search_Lucene_Field::UnStored('contents', $contents));
$this->addField(Zend_Search_Lucene_Field::UnIndexed('summary', $summary));
$this->addField(Zend_Search_Lucene_Field::Keyword('createdBy', $createdBy));
$this->addField(Zend_Search_Lucene_Field::Keyword('dateCreated', $dateCreated));
if (!is_array($keywords)) {
$keywords = explode('', $keywords);
}
foreach ($keywords as $name => $value) {
if (!empty($name) && !empty($value)) {
$this->addField(Zend_Search_Lucene_Field::keyword($name, $value));
}
}
}
示例10: index
/**
* php index.php db index
*
*/
public function index()
{
$query = "SELECT * FROM Products AS p JOIN Categories AS c ON p.CategoryID = c.CategoryId JOIN Suppliers AS s ON p.SupplierID = s.SupplierID";
$stmt = $this->db->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$indexDir = APP_PATH . '/' . self::INDEX_DIR;
is_dir($indexDir) || mkdir($indexDir, 0777, true);
$index = self::create($indexDir);
foreach ($rows as $row) {
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::keyword('ProductName', $row['ProductName']));
$doc->addField(Zend_Search_Lucene_Field::text('Quantity', $row['QuantityPerUnit']));
$doc->addField(Zend_Search_Lucene_Field::keyword('Category', $row['CategoryName']));
$doc->addField(Zend_Search_Lucene_Field::unIndexed('Description', $row['Description']));
$doc->addField(Zend_Search_Lucene_Field::unStored('City', $row['City']));
$doc->addField(Zend_Search_Lucene_Field::keyword('CompanyName', $row['CompanyName']));
$doc->addField(Zend_Search_Lucene_Field::binary('Picture', $row['Picture']));
$index->addDocument($doc);
}
}
示例11: updateLuceneIndex
/**
* @ORM\PostPersist
*/
public function updateLuceneIndex()
{
$index = self::getLuceneIndex();
//remove existing entries
foreach ($index->find('pk:' . $this->getId()) as $hit) {
$index->delete($hit->id);
}
if ($this->isExpired() || !$this->getIsActivated()) {
return;
}
$doc = new \Zend_Search_Lucene_Document();
$doc->addField(\Zend_Search_Lucene_Field::keyword('pk', $this->getId()));
//index job fields
$doc->addField(\Zend_Search_Lucene_Field::unStored('position', $this->getPosition(), 'utf-8'));
$doc->addField(\Zend_Search_Lucene_Field::unStored('company', $this->getCompany(), 'utf-8'));
$doc->addField(\Zend_Search_Lucene_Field::unStored('location', $this->getLocation(), 'utf-8'));
$doc->addField(\Zend_Search_Lucene_Field::unStored('description', $this->getDescription(), 'utf-8'));
$index->addDocument($doc);
$index->commit();
}
示例12: addToIndex
protected function addToIndex($data)
{
if (trim($this->z_indexate) == '') {
return;
}
if (!isset($data['id'])) {
return;
}
$fields = explode(';', trim($this->z_indexate));
$searchIndex = Z_Search::getInstance();
//создаем документ
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::keyword('_id', $data['id']));
$doc->addField(Zend_Search_Lucene_Field::unIndexed('_type', $this->z_model->info('name')));
foreach ($fields as $field) {
if (isset($data[$field])) {
$doc->addField(Zend_Search_Lucene_Field::text($field, $data[$field]));
}
}
//удаляем старый документ
$hits = $searchIndex->find('_id:' . $data['id']);
foreach ($hits as $hit) {
$searchIndex->delete($hit->id);
}
//добавляем документ
$searchIndex->addDocument($doc);
}
示例13: createLuceneDoc
/**
* создаёет LuceneDoc из SearchDoc
*
* @param Application_Model_SearchDoc $searchDoc
* @return Zend_Search_Lucene_Document
*/
public function createLuceneDoc(Application_Model_SearchDoc $searchDoc)
{
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('title', $searchDoc->title, 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::Text('content', $searchDoc->content, 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::UnIndexed('type', $searchDoc->type, 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::keyword('docid', $searchDoc->id));
return $doc;
}
示例14: buildPostSearch
/**
* Build the post search index
*
* @param boolean $isCount
* @return boolean
*/
protected function buildPostSearch($isCount = false)
{
$index = Zend_Search_Lucene::create(Zend_Registry::getInstance()->config->search->post);
require_once 'Ifphp/models/Posts.php';
require_once 'Ifphp/models/Feeds.php';
require_once 'Ifphp/models/Categories.php';
$posts = new Posts();
$allPosts = $posts->getRecent(1, 0);
if ($isCount) {
echo $allPosts->count() . ' posts would have been added to the post index';
exit;
}
foreach ($allPosts as $post) {
$feed = $post->findParentFeeds();
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('pid', $post->id));
$doc->addField(Zend_Search_Lucene_Field::Text('title', $post->title));
$doc->addField(Zend_Search_Lucene_Field::Text('siteUrl', $post->siteUrl));
$doc->addField(Zend_Search_Lucene_Field::Text('link', $post->link));
$doc->addField(Zend_Search_Lucene_Field::Text('feedTitle', $feed->title));
$doc->addField(Zend_Search_Lucene_Field::Text('feedSlug', $feed->slug));
$doc->addField(Zend_Search_Lucene_Field::Text('feedDescription', $feed->description));
$doc->addField(Zend_Search_Lucene_Field::keyword('category', $feed->findParentCategories()->title));
$doc->addField(Zend_Search_Lucene_Field::Text('description', $post->description));
$doc->addField(Zend_Search_Lucene_Field::unIndexed('publishDate', $post->publishDate));
$doc->addField(Zend_Search_Lucene_Field::Keyword('type', 'post'));
$index->addDocument($doc);
}
chown(Zend_Registry::getInstance()->search['post'], 'www-data');
return true;
}
示例15: run_index_documents
function run_index_documents($task, $args)
{
try {
define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
define('SF_APP', 'backend');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG', false);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
ini_set("memory_limit", "2048M");
ini_set("display_errors", 1);
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
$search_config_file = SF_ROOT_DIR . '/config/search.xml';
$documents = simplexml_load_file($search_config_file);
$all = 0;
$search_index_path = SF_ROOT_DIR . '/cache/search/';
if (is_dir($search_index_path)) {
$index_files = glob($search_index_path . '/*');
foreach ($index_files as $index_file) {
if (is_file($index_file)) {
unlink($index_file);
}
}
}
$search_index = Zend_Search_Lucene::create($search_index_path);
$search_index->setMaxBufferedDocs(20000);
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
$ndoc = 0;
foreach ($documents as $document) {
$document_name = $document->attributes();
if (array_key_exists(0, $args) && $document_name != $args[0]) {
continue;
}
echo "Indexing " . $document_name . "\n";
$classPeer = $document_name . 'Peer';
$c = new Criteria();
$document_instances = call_user_func(array($classPeer, 'doSelect'), $c);
foreach ($document_instances as $document_instance) {
$common_field_val = "";
$id = $document_instance->getId();
$search_doc = new Zend_Search_Lucene_Document();
$date = $document_instance->getCreatedAt();
$search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('did', $id, 'utf-8'));
$search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('ddate', $date, 'utf-8'));
$search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('dtype', $document_name, 'utf-8'));
$search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('dstatus', $document_instance->getPublicationStatus(), 'utf-8'));
foreach ($document as $field_name) {
$attr = get_object_vars($field_name);
$attributes = $attr['@attributes'];
$getFunction = 'get' . $attributes['name'];
$fieldContent = "";
$fieldContent = $document_instance->{$getFunction}();
if ($attributes['name'] == "Label" and substr($fieldContent, 0, 8) == "no label") {
$fieldContent = "";
}
if ($attributes['name'] == "ViennaClasses" || $attributes['name'] == "NiceClasses") {
$parts = explode(",", $fieldContent);
$nbr = count($parts);
//echo "============>".$nbr."\n";
$search_doc->addField(Zend_Search_Lucene_Field::UnIndexed($attributes['name'] . "_cnt", $nbr, 'utf-8'));
//$e = 1;
for ($e = 0; $e < 15; $e++) {
if (empty($parts[$e])) {
$parts[$e] = "---";
}
$search_doc->addField(Zend_Search_Lucene_Field::keyword($attributes['name'] . $e, trim($parts[$e]), 'utf-8'));
$e++;
}
} elseif ($attributes['name'] == "ApplicationNumber" || $attributes['name'] == "RegisterNumber") {
$search_doc->addField(Zend_Search_Lucene_Field::keyword($attributes['name'], $fieldContent, 'utf-8'));
} else {
$search_doc->addField(Zend_Search_Lucene_Field::text($attributes['name'], UtilsHelper::cyrillicConvert($fieldContent), 'utf-8'));
}
}
$search_index->addDocument($search_doc);
$ndoc++;
echo $ndoc . "\t\t\r";
}
}
echo echo_cms_line(" " . $ndoc . " documents indexed\n");
$search_index->commit();
$search_index->optimize();
} catch (Exception $e) {
echo_cms_error("ERROR ADD_DOCUMENT : " . $e->getMessage());
}
echo echo_cms_sep();
exit;
}