本文整理汇总了PHP中Apache_Solr_Document::setField方法的典型用法代码示例。如果您正苦于以下问题:PHP Apache_Solr_Document::setField方法的具体用法?PHP Apache_Solr_Document::setField怎么用?PHP Apache_Solr_Document::setField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Apache_Solr_Document
的用法示例。
在下文中一共展示了Apache_Solr_Document::setField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: itemToDocument
/**
* This takes an Omeka_Record instance and returns a populated
* Apache_Solr_Document.
*
* @param Omeka_Record $item The record to index.
*
* @return Apache_Solr_Document
* @author Eric Rochester <erochest@virginia.edu>
**/
public static function itemToDocument($item)
{
$fields = get_db()->getTable('SolrSearchField');
$doc = new Apache_Solr_Document();
$doc->setField('id', "Item_{$item->id}");
$doc->setField('resulttype', 'Item');
$doc->setField('model', 'Item');
$doc->setField('modelid', $item->id);
// Title:
$title = metadata($item, array('Dublin Core', 'Title'));
$doc->setField('title', $title);
// Elements:
self::indexItem($fields, $item, $doc);
// Tags:
foreach ($item->getTags() as $tag) {
$doc->setMultiValue('tag', $tag->name);
}
// Collection:
if ($collection = $item->getCollection()) {
$doc->collection = metadata($collection, array('Dublin Core', 'Title'));
}
// Item type:
if ($itemType = $item->getItemType()) {
$doc->itemtype = $itemType->name;
}
$doc->featured = (bool) $item->featured;
// File metadata
foreach ($item->getFiles() as $file) {
self::indexItem($fields, $file, $doc);
}
return $doc;
}
示例2: getMockDocument
protected function getMockDocument($id)
{
$document = new Apache_Solr_Document();
$document->setField('id', $id);
$document->setField('title', "Item {$id}");
return $document;
}
示例3: _addAs
/**
* Method for adding an object from the database into the index.
*
* @param DataObject
* @param string
* @param array
*/
protected function _addAs($object, $base, $options)
{
$includeSubs = $options['include_children'];
$doc = new Apache_Solr_Document();
// Always present fields
$doc->setField('_documentid', $this->getDocumentID($object, $base, $includeSubs));
$doc->setField('ID', $object->ID);
$doc->setField('ClassName', $object->ClassName);
foreach (SearchIntrospection::hierarchy(get_class($object), false) as $class) {
$doc->addField('ClassHierarchy', $class);
}
// Add the user-specified fields
foreach ($this->getFieldsIterator() as $name => $field) {
if ($field['base'] == $base) {
$this->_addField($doc, $object, $field);
}
}
// CUSTOM Duplicate index combined fields ("Title" rather than
// "SiteTree_Title").
//
// This allows us to sort on these fields without deeper architectural
// changes to the fulltextsearch module. Note: We can't use <copyField>
// for this purpose because it only writes into multiValue=true
// fields, and those can't be (reliably) sorted on.
$this->_addField($doc, $object, $this->getCustomPropertyFieldData('Title', $object));
$this->_addField($doc, $object, $this->getCustomPropertyFieldData('LastEdited', $object, 'SSDatetime'));
$this->getService()->addDocument($doc);
return $doc;
}
开发者ID:helpfulrobot,项目名称:dnadesign-silverstripe-fulltextsearchdefault,代码行数:36,代码来源:FulltextSearchDefaultIndex.php
示例4: transformsUnixTimestampToIsoDateOnSingleValuedField
/**
* @test
*/
public function transformsUnixTimestampToIsoDateOnSingleValuedField()
{
$this->documentMock->setField('dateField', '1262343600');
// 2010-01-01 12:00
$configuration = array('dateField' => 'timestampToIsoDate');
$this->service->processDocument($this->documentMock, $configuration);
$value = $this->documentMock->getField('dateField');
$this->assertEquals($value['value'], '2010-01-01T12:00:00Z', 'field was not processed with timestampToIsoDate');
}
示例5: processDocument
/**
* modifies a document according to the given configuration
*
* @param Apache_Solr_Document $document
* @param array $processingConfiguration
*/
public function processDocument(Apache_Solr_Document $document, array $processingConfiguration)
{
foreach ($processingConfiguration as $fieldName => $instruction) {
$fieldInformation = $document->getField($fieldName);
$isSingleValueField = FALSE;
if ($fieldInformation !== FALSE) {
$fieldValue = $fieldInformation['value'];
if (!is_array($fieldValue)) {
// turn single value field into multi value field
$fieldValue = array($fieldValue);
$isSingleValueField = TRUE;
}
switch ($instruction) {
case 'timestampToIsoDate':
$processor = t3lib_div::makeInstance('tx_solr_fieldprocessor_TimestampToIsoDate');
$fieldValue = $processor->process($fieldValue);
break;
case 'uppercase':
$fieldValue = array_map('strtoupper', $fieldValue);
break;
}
if ($isSingleValueField) {
// turn multi value field back into single value field
$fieldValue = $fieldValue[0];
}
$document->setField($fieldName, $fieldValue);
}
}
}
示例6: addDocumentFieldsFromTyposcript
/**
* Adds fields to the document as defined in $indexingConfiguration
*
* @param \Apache_Solr_Document $document base document to add fields to
* @param array $indexingConfiguration Indexing configuration / mapping
* @param array $data Record data
* @return \Apache_Solr_Document Modified document with added fields
*/
protected function addDocumentFieldsFromTyposcript(\Apache_Solr_Document $document, array $indexingConfiguration, array $data)
{
// mapping of record fields => solr document fields, resolving cObj
foreach ($indexingConfiguration as $solrFieldName => $recordFieldName) {
if (is_array($recordFieldName)) {
// configuration for a content object, skipping
continue;
}
if (!self::isAllowedToOverrideField($solrFieldName)) {
throw new InvalidFieldNameException('Must not overwrite field .' . $solrFieldName, 1435441863);
}
$fieldValue = $this->resolveFieldValue($indexingConfiguration, $solrFieldName, $data);
if (is_array($fieldValue)) {
// multi value
foreach ($fieldValue as $multiValue) {
$document->addField($solrFieldName, $multiValue);
}
} else {
if ($fieldValue !== '' && $fieldValue !== null) {
$document->setField($solrFieldName, $fieldValue);
}
}
}
return $document;
}
示例7: buildDocument
/**
* Builds an Apache_Solr_Document to pass to Apache_Solr_Service
**/
public function buildDocument(array $document)
{
$doc = new Apache_Solr_Document();
foreach ($document as $fieldName => $field) {
$value = $field['value'];
// Apache_Solr_Document always expect arrays
if (!is_array($value)) {
$value = array($value);
}
if (isset($field['boost'])) {
$doc->setField($fieldName, $value, $field['boost']);
} else {
$doc->setField($fieldName, $value);
}
}
return $doc;
}
示例8: testAddFieldWithBoostMultipliesWithAPreexistingBoost
public function testAddFieldWithBoostMultipliesWithAPreexistingBoost()
{
$field = 'field';
$boost = 0.5;
// set a field with a boost
$this->_fixture->setField($field, 'value1', $boost);
// now add another value with the same boost
$this->_fixture->addField($field, 'value2', $boost);
// new boost should be $boost * $boost
$this->assertEquals($boost * $boost, $this->_fixture->getFieldBoost($field));
}
示例9: buildFileDocument
/**
* Build a Solr document for a specific file
*
* @param integer $storeId Store ID the file belongs to/where it is linked on a page
* @param Asm_Solr_Model_Indexqueue_File $file The file to index
* @return Apache_Solr_Document
*/
protected function buildFileDocument($storeId, Asm_Solr_Model_Indexqueue_File $file)
{
$helper = Mage::helper('solr');
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$host = parse_url($baseUrl, PHP_URL_HOST);
$document = new Apache_Solr_Document();
$document->setField('appKey', 'Asm_Solr');
$document->setField('type', 'solr/indexqueue_file');
$document->setField('id', $helper->getFileDocumentId($file->getId()));
$document->setField('site', $host);
$document->setField('siteHash', $helper->getSiteHashForDomain($host));
$document->setField('storeId', $storeId);
$document->setField('changed', $helper->dateToIso($file->getFileLastChangedTime()));
$document->setField('productId', 0);
$document->setField('sku', 'solr/indexqueue_file');
$document->setField('title', $file->getName());
$document->setField('content', $file->getContent());
$document->setField('url', $file->getUrl());
return $document;
}
示例10: addDocumentFieldsFromTyposcript
/**
* Adds fields to the document as defined in $indexingConfiguration
*
* @param Apache_Solr_Document $document base document to add fields to
* @param array $indexingConfiguration Indexing configuration / mapping
* @param array $data Record data
* @return Apache_Solr_Document Modified document with added fields
*/
protected function addDocumentFieldsFromTyposcript(Apache_Solr_Document $document, array $indexingConfiguration, array $data)
{
// mapping of record fields => solr document fields, resolving cObj
foreach ($indexingConfiguration as $solrFieldName => $recordFieldName) {
if (is_array($recordFieldName)) {
// configuration for a content object, skipping
continue;
}
$fieldValue = $this->resolveFieldValue($indexingConfiguration, $solrFieldName, $data);
if (is_array($fieldValue)) {
// multi value
foreach ($fieldValue as $multiValue) {
$document->addField($solrFieldName, $multiValue);
}
} else {
$document->setField($solrFieldName, $fieldValue);
}
}
return $document;
}
示例11: solrStore
public function solrStore($contact) {
$doc = new Apache_Solr_Document();
$doc->setField('id', $contact->id);
$doc->setField('timecreate', $contact->timecreate->format('Y-m-d\TH:i:s\Z'));
$doc->setField('timeupdate', $contact->timeupdate->format('Y-m-d\TH:i:s\Z'));
$doc->setField('usercreate', $contact->usercreate);
$doc->setField('userupdate', $contact->userupdate);
$doc->setField('datasource', $contact->datasource_id);
$doc->setField('domain', $GLOBALS['obm']['domain_id']);
$doc->setField('in', $contact->addressbook);
$doc->setField('addressbookId', $contact->addressbook_id);
$doc->setField('company', $contact->company);
$doc->setField('companyId', $contact->company_id);
$doc->setField('commonname', $contact->commonname);
$doc->setField('lastname', $contact->lastname);
$doc->setField('firstname', $contact->firstname);
$doc->setField('middlename', $contact->mname);
$doc->setField('sortable', $contact->lastname." ".$contact->firstname);
$doc->setField('suffix', $contact->suffix);
$doc->setField('aka', $contact->aka);
$doc->setField('kind', $contact->kind);
//$doc->setField('kind', $db->f('kind_header'));
$doc->setField('manager', $contact->manager);
$doc->setField('assistant', $contact->assistant);
$doc->setField('spouse', $contact->spouse);
$doc->setField('birthdayId', $contact->birthday_event);
$doc->setField('anniversaryId', $contact->anniversary_event);
if($contact->birthday) $doc->setField('birthday', $contact->birthday->format('Y-m-d\TH:i:s\Z'));
if($contact->anniversary) $doc->setField('anniversary', $contact->anniversary->format('Y-m-d\TH:i:s\Z'));
$doc->setField('category', $contact->category);
foreach($contact->categories as $category) {
foreach($category as $c) {
$doc->setMultiValue('categoryId', $c['id']);
}
}
$doc->setField('service', $contact->service);
$doc->setField('function', $contact->function);
$doc->setField('title', $contact->title);
if ($contact->archive) {
$doc->setField('is', 'archive');
}
if ($contact->collected) {
$doc->setField('is', 'collected');
}
if ($contact->mailok) {
$doc->setField('is', 'mailing');
}
if ($contact->newsletter) {
$doc->setField('is', 'newsletter');
}
if($contact->date) $doc->setField('date', $contact->date->format('Y-m-d\TH:i:s\Z'));
$doc->setField('comment', $contact->comment);
$doc->setField('comment2', $contact->comment2);
$doc->setField('comment3', $contact->comment3);
$doc->setField('from', $contact->origin);
foreach($contact->email as $email) {
$doc->setMultiValue('email', $email['address']);
}
foreach($contact->phone as $phone) {
$doc->setMultiValue('phone', $phone['number']);
}
foreach($contact->im as $im) {
$doc->setMultiValue('jabber', $im['address']);
}
foreach($contact->address as $address) {
$doc->setMultiValue('street', $address['street']);
$doc->setMultiValue('zipcode', $address['zipcode']);
$doc->setMultiValue('expresspostal', $address['expresspostal']);
$doc->setMultiValue('town', $address['town']);
$doc->setMultiValue('country', $address['country']);
}
if($contact->hasACalendarUrl()){
$doc->setField('hasACalendar', "true");
}
else {
$doc->setField('hasACalendar', "false");
}
OBM_IndexingService::store('contact', array($doc));
}
示例12: processDocument
/**
* modifies a document according to the given configuration
*
* @param \Apache_Solr_Document $document
* @param array $processingConfiguration
*/
public function processDocument(\Apache_Solr_Document $document, array $processingConfiguration)
{
foreach ($processingConfiguration as $fieldName => $instruction) {
$fieldInformation = $document->getField($fieldName);
$isSingleValueField = false;
if ($fieldInformation !== false) {
$fieldValue = $fieldInformation['value'];
if (!is_array($fieldValue)) {
// turn single value field into multi value field
$fieldValue = array($fieldValue);
$isSingleValueField = true;
}
switch ($instruction) {
case 'timestampToUtcIsoDate':
$processor = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\FieldProcessor\\TimestampToUtcIsoDate');
$fieldValue = $processor->process($fieldValue);
break;
case 'timestampToIsoDate':
$processor = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\FieldProcessor\\TimestampToIsoDate');
$fieldValue = $processor->process($fieldValue);
break;
case 'pathToHierarchy':
$processor = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\FieldProcessor\\PathToHierarchy');
$fieldValue = $processor->process($fieldValue);
break;
case 'pageUidToHierarchy':
$processor = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\FieldProcessor\\PageUidToHierarchy');
$fieldValue = $processor->process($fieldValue);
break;
case 'categoryUidToHierarchy':
$processor = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\FieldProcessor\\CategoryUidToHierarchy');
$fieldValue = $processor->process($fieldValue);
break;
case 'uppercase':
$fieldValue = array_map('strtoupper', $fieldValue);
break;
}
if ($isSingleValueField) {
// turn multi value field back into single value field
$fieldValue = $fieldValue[0];
}
$document->setField($fieldName, $fieldValue);
}
}
}
示例13: buildPageDocument
/**
* Build a Solr document for a given page
*
* @param integer $storeId Store ID
* @param Mage_Cms_Model_Page $page Page instance
* @return Apache_Solr_Document
*/
protected function buildPageDocument($storeId, $page)
{
$helper = Mage::helper('solr');
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$host = parse_url($baseUrl, PHP_URL_HOST);
$document = new Apache_Solr_Document();
$document->setField('appKey', 'Asm_Solr');
$document->setField('type', 'cms/page');
$document->setField('id', $helper->getPageDocumentId($page->getId()));
$document->setField('site', $host);
$document->setField('siteHash', $helper->getSiteHashForDomain($host));
$document->setField('storeId', $storeId);
$document->setField('created', $helper->dateToIso($page->getCreationTime()));
$document->setField('changed', $helper->dateToIso($page->getUpdateTime()));
$document->setField('sku', 'cms/page');
$document->setField('productId', 0);
$document->setField('pageId', $page->getId());
$document->setField('title', $page->getTitle());
$document->setField('content', Mage::helper('solr/contentExtractor')->getIndexableContent($page->getContent()));
$document->setField('keywords', $helper->trimExplode(',', $page->getMetaKeywords(), true));
$document->setField('url', Mage::helper('cms/page')->getPageUrl($page->getId()));
return $document;
}
示例14: processPhysical
/**
* Processes a physical unit for the Solr index
*
* @access protected
*
* @param tx_dlf_document &$doc: The METS document
* @param integer $page: The page number
* @param array $physicalUnit: Array of the physical unit to process
*
* @return integer 0 on success or 1 on failure
*/
protected static function processPhysical(tx_dlf_document &$doc, $page, array $physicalUnit)
{
$errors = 0;
// Read extension configuration.
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::$extKey]);
if (!empty($physicalUnit['files'][$extConf['fileGrpFulltext']])) {
$file = $doc->getFileLocation($physicalUnit['files'][$extConf['fileGrpFulltext']]);
// Load XML file.
if (\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($file) || version_compare(phpversion(), '5.3.3', '<')) {
// Set user-agent to identify self when fetching XML data.
if (!empty($extConf['useragent'])) {
@ini_set('user_agent', $extConf['useragent']);
}
// Turn off libxml's error logging.
$libxmlErrors = libxml_use_internal_errors(TRUE);
// disable entity loading
$previousValueOfEntityLoader = libxml_disable_entity_loader(TRUE);
// Load XML from file.
$xml = simplexml_load_string(file_get_contents($file));
// reset entity loader setting
libxml_disable_entity_loader($previousValueOfEntityLoader);
// Reset libxml's error logging.
libxml_use_internal_errors($libxmlErrors);
if ($xml === FALSE) {
return 1;
}
} else {
return 1;
}
// Load class.
if (!class_exists('Apache_Solr_Document')) {
require_once \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:' . self::$extKey . '/lib/SolrPhpClient/Apache/Solr/Document.php');
}
// Create new Solr document.
$solrDoc = new Apache_Solr_Document();
// Create unique identifier from document's UID and unit's XML ID.
$solrDoc->setField('id', $doc->uid . $physicalUnit['id']);
$solrDoc->setField('uid', $doc->uid);
$solrDoc->setField('pid', $doc->pid);
$solrDoc->setField('page', $page);
if (!empty($physicalUnit['files'][$extConf['fileGrpThumbs']])) {
$solrDoc->setField('thumbnail', $doc->getFileLocation($physicalUnit['files'][$extConf['fileGrpThumbs']]));
}
$solrDoc->setField('partof', $doc->parentId);
$solrDoc->setField('root', $doc->rootId);
$solrDoc->setField('sid', $physicalUnit['id']);
$solrDoc->setField('toplevel', FALSE);
$solrDoc->setField('type', $physicalUnit['type'], self::$fields['fieldboost']['type']);
$solrDoc->setField('fulltext', tx_dlf_alto::getRawText($xml));
try {
self::$solr->service->addDocument($solrDoc);
} catch (Exception $e) {
if (!defined('TYPO3_cliMode')) {
$message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', tx_dlf_helper::getLL('flash.solrException', TRUE) . '<br />' . htmlspecialchars($e->getMessage()), tx_dlf_helper::getLL('flash.error', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, TRUE);
tx_dlf_helper::addMessage($message);
}
return 1;
}
}
return $errors;
}
示例15: pushDocuments
/**
*
* @param Apache_Solr_Document or Array $parts
*
* @return SP_Controller_Action_Helper_Solr
*/
public function pushDocuments($parts)
{
$this->_setSolrService();
if ($parts instanceof Apache_Solr_Document) {
$this->documents[] = $parts;
} else {
if (is_array($parts)) {
foreach ($parts as $item => $fields) {
if ($fields instanceof Apache_Solr_Document) {
$this->documents[] = $fields;
} else {
$part = new Apache_Solr_Document();
foreach ($fields as $key => $value) {
if (is_array($value)) {
foreach ($value as $datum) {
$part->setMultiValue($key, $datum);
}
} else {
$part->setField($key, $value);
}
}
$this->documents[] = $part;
}
}
} else {
trigger_error("the paramter \$part must be an object of Apache_Solr_Document or an array");
}
}
return $this;
}