本文整理汇总了PHP中Apache_Solr_Document类的典型用法代码示例。如果您正苦于以下问题:PHP Apache_Solr_Document类的具体用法?PHP Apache_Solr_Document怎么用?PHP Apache_Solr_Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Apache_Solr_Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: getMockDocument
protected function getMockDocument($id)
{
$document = new Apache_Solr_Document();
$document->setField('id', $id);
$document->setField('title', "Item {$id}");
return $document;
}
示例3: addDocument
public function addDocument($data)
{
$document = new Apache_Solr_Document();
foreach ($data as $key => $value) {
if (is_array($value)) {
foreach ($value as $datum) {
if (is_numeric($datum)) {
number_format($datum);
}
$document->setMultiValue($key, $datum);
}
} else {
if (is_numeric($value)) {
number_format($value);
}
$document->{$key} = $value;
}
}
try {
$rs = $this->_solrService->addDocument($document);
// asynchronous commit
// $this->_solrService->commit(true);
return $rs;
} catch (Exception $e) {
return $e->getMessage();
}
}
示例4: 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;
}
示例5: addDocuments
public function addDocuments($datas)
{
$documents = array();
foreach ($datas as $item => $fields) {
$part = new Apache_Solr_Document();
foreach ($fields as $key => $value) {
if (is_array($value)) {
foreach ($value as $datum) {
$part->setMultiValue($key, $datum);
}
} else {
$part->{$key} = $value;
}
}
$documents[] = $part;
}
try {
$rs = $this->_solrService->addDocuments($documents);
// asynchronous commit
//$this->_solrService->commit(true);
return $rs;
} catch (Exception $e) {
return $e->getMessage();
}
}
示例6: 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);
}
}
}
示例7: createEntryDocument
public function createEntryDocument(entry $entry)
{
$document = new Apache_Solr_Document();
$document->plugins_data = '';
foreach (self::$solrFields as $solrField) {
$fieldType = $solrField['type'];
$func_name = "get" . $solrField['phpName'];
if ($fieldType == "date") {
$value = call_user_func(array($entry, $func_name), "%Y-%m-%dT%H:%M:%SZ");
} else {
$value = call_user_func(array($entry, $func_name));
}
//$value = $entry->getByName($solrField['phpName']);
$solrName = $solrField['solrName'];
switch ($solrField['type']) {
case "array":
if ($value != '') {
$values = explode(",", $value);
foreach ($vals as $value) {
$document->addField($solrName, $value);
}
}
break;
default:
$document->addField($solrName, $value);
}
}
return $document;
}
示例8: addDocument
/**
* add a document
* @param array
*/
public function addDocument($doc)
{
$document = new Apache_Solr_Document();
foreach ($doc as $key => $val) {
if (is_array($val)) {
foreach ($val as $_val) {
$document->addField($key, $_val);
}
} else {
$document->addField($key, $val);
}
}
$this->service->addDocument($document);
}
示例9: 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);
// extend $doc to to include and items public / private status
$doc->setField('public', $item->public);
// 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;
}
示例10: 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;
}
示例11: cromSolar
public function cromSolar($id, $caso = null)
{
$adapter = $this->tableGateway->getAdapter();
$sql = new Sql($adapter);
$selecttot = $sql->select()->from('ta_plato')->join(array('c' => 'ta_comentario'), 'c.ta_plato_in_id=ta_plato.in_id', array('cantidad' => new \Zend\Db\Sql\Expression('COUNT(c.in_id)')), 'left')->join('ta_tipo_plato', 'ta_plato.ta_tipo_plato_in_id=ta_tipo_plato.in_id ', array('tipo_plato_nombre' => 'va_nombre'), 'left')->join(array('pl' => 'ta_plato_has_ta_local'), 'pl.Ta_plato_in_id = ta_plato.in_id', array(), 'left')->join(array('tl' => 'ta_local'), 'tl.in_id = pl.Ta_local_in_id', array('latitud' => 'de_latitud', 'longitud' => 'de_longitud', 'direccion' => 'va_direccion', 'telefono' => 'va_telefono'), 'left')->join(array('tr' => 'ta_restaurante'), 'tr.in_id = tl.ta_restaurante_in_id', array('restaurant_nombre' => 'va_nombre', 'restaurant_estado' => 'en_estado'), 'left')->join(array('tc' => 'ta_tipo_comida'), 'tc.in_id = tr.Ta_tipo_comida_in_id', array('nombre_tipo_comida' => 'va_nombre_tipo'), 'left')->join(array('tu' => 'ta_ubigeo'), 'tu.in_id = tl.ta_ubigeo_in_id', array('distrito' => 'ch_distrito', 'departamento' => 'ch_departamento'), 'left')->where(array('ta_plato.in_id' => $id));
$selecttot->group('ta_plato.in_id');
$selectString = $sql->getSqlStringForSqlObject($selecttot);
$results = $adapter->query($selectString, $adapter::QUERY_MODE_EXECUTE);
$plato = $results->toArray();
$selectto = $sql->select()->from('ta_plato')->join(array('tpt' => 'ta_plato_has_ta_tag'), 'tpt.Ta_plato_in_id = ta_plato.in_id', array('tag_id' => 'ta_tag_in_id'), 'left')->join(array('tt' => 'ta_tag'), 'tt.in_id =tpt.ta_tag_in_id', array('tag' => 'va_nombre'), 'left')->where(array('ta_plato.in_id' => $id));
$selectStrin = $sql->getSqlStringForSqlObject($selectto);
$result = $adapter->query($selectStrin, $adapter::QUERY_MODE_EXECUTE);
$tag = $result->toArray();
$solr = \Classes\Solr::getInstance()->getSolr();
if ($solr->ping()) {
if ($caso !== 1) {
$solr->deleteByQuery('id:' . $id);
}
$document = new \Apache_Solr_Document();
$document->id = $id;
$document->name = $plato[0]['va_nombre'];
$document->tx_descripcion = $plato[0]['tx_descripcion'];
$document->va_precio = $plato[0]['va_precio'];
$document->en_estado = $plato[0]['en_estado'];
$document->plato_tipo = $plato[0]['tipo_plato_nombre'];
$document->va_direccion = $plato[0]['direccion'];
$document->restaurante = $plato[0]['restaurant_nombre'];
$document->tipo_comida = $plato[0]['nombre_tipo_comida'];
$document->en_destaque = $plato[0]['en_destaque'];
$document->va_telefono = $plato[0]['telefono'];
$document->latitud = $plato[0]['latitud'];
$document->longitud = $plato[0]['longitud'];
$document->departamento = $plato[0]['departamento'];
foreach ($tag as $resultado) {
$document->setMultiValue('tag', $resultado['tag']);
}
$document->distrito = $plato[0]['distrito'];
$document->va_imagen = $plato[0]['va_imagen'];
$document->comentarios = $plato[0]['cantidad'];
$document->restaurant_estado = $plato[0]['restaurant_estado'];
$document->puntuacion = $plato[0]['Ta_puntaje_in_id'];
$solr->addDocument($document);
$solr->commit();
}
}
示例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 = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_FieldProcessor_TimestampToUtcIsoDate');
$fieldValue = $processor->process($fieldValue);
break;
case 'timestampToIsoDate':
$processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_FieldProcessor_TimestampToIsoDate');
$fieldValue = $processor->process($fieldValue);
break;
case 'pathToHierarchy':
$processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_FieldProcessor_PathToHierarchy');
$fieldValue = $processor->process($fieldValue);
break;
case 'pageUidToHierarchy':
$processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_FieldProcessor_PageUidToHierarchy');
$fieldValue = $processor->process($fieldValue);
break;
case 'categoryUidToHierarchy':
$processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_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: 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);
}
}
}
示例14: 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;
}
示例15: _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