本文整理汇总了PHP中eZSolr::getMetaAttributesForObject方法的典型用法代码示例。如果您正苦于以下问题:PHP eZSolr::getMetaAttributesForObject方法的具体用法?PHP eZSolr::getMetaAttributesForObject怎么用?PHP eZSolr::getMetaAttributesForObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZSolr
的用法示例。
在下文中一共展示了eZSolr::getMetaAttributesForObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getData
/**
* @see ezfSolrDocumentFieldBase::getData()
*/
public function getData()
{
$contentClassAttribute = $this->ContentObjectAttribute->attribute( 'contentclass_attribute' );
switch ( $contentClassAttribute->attribute( 'data_type_string' ) )
{
case 'ezobjectrelation' :
$returnArray = array();
$defaultFieldName = parent::generateAttributeFieldName( $contentClassAttribute,
self::$subattributesDefinition[self::DEFAULT_SUBATTRIBUTE] );
$returnArray[$defaultFieldName] = $this->getPlainTextRepresentation();
$relatedObject = $this->ContentObjectAttribute->content();
if ( $relatedObject && $relatedObject->attribute( 'status' ) == eZContentObject::STATUS_PUBLISHED )
{
// 1st, add content fields of the related object.
$baseList = $this->getBaseList( $relatedObject->attribute( 'current' ) );
foreach ( $baseList as $field )
{
$tmpClassAttribute = $field->ContentObjectAttribute->attribute( 'contentclass_attribute' );
$fieldName = $field->ContentObjectAttribute->attribute( 'contentclass_attribute_identifier' );
$fieldName = parent::generateSubattributeFieldName( $contentClassAttribute,
$fieldName,
self::getClassAttributeType( $tmpClassAttribute ) );
$finalValue = '';
if ( $tmpClassAttribute->attribute( 'data_type_string' ) == 'ezobjectrelation' or
$tmpClassAttribute->attribute( 'data_type_string' ) == 'ezobjectrelationlist' )
{
// The subattribute is in turn an object relation. Stop recursion and get full text representation.
$finalValue = $field->getPlainTextRepresentation();
}
else
{
$values = array_values( $field->getData() );
foreach ( $values as $value )
{
if ( is_array( $value ) )
{
$finalValue .= implode( ' ', $value );
}
else
{
$finalValue .= ' ' . $value;
}
}
}
$returnArray[$fieldName] = trim( $finalValue, "\t\r\n " );
}
// 2ndly, add meta fields of the related object.
$metaAttributeValues = eZSolr::getMetaAttributesForObject( $relatedObject );
foreach ( $metaAttributeValues as $metaInfo )
{
$returnArray[ezfSolrDocumentFieldBase::generateSubmetaFieldName( $metaInfo['name'], $contentClassAttribute )] = ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] );
}
return $returnArray;
}
break;
case 'ezobjectrelationlist' :
{
$returnArray = array();
$content = $this->ContentObjectAttribute->content();
foreach ( $content['relation_list'] as $relationItem )
{
$subObjectID = $relationItem['contentobject_id'];
if ( !$subObjectID )
continue;
$subObject = eZContentObjectVersion::fetchVersion( $relationItem['contentobject_version'], $subObjectID );
if ( !$subObject || $relationItem['in_trash'] )
continue;
// 1st create aggregated metadata fields
$metaAttributeValues = eZSolr::getMetaAttributesForObject( $subObject->attribute( 'contentobject' ) );
foreach ( $metaAttributeValues as $metaInfo )
{
$submetaFieldName = ezfSolrDocumentFieldBase::generateSubmetaFieldName( $metaInfo['name'], $contentClassAttribute );
if ( isset( $returnArray[$submetaFieldName] ) )
{
$returnArray[$submetaFieldName] = array_merge( $returnArray[$submetaFieldName], array( ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] ) ) );
}
else
{
$returnArray[$submetaFieldName] = array( ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] ) );
}
}
}
$defaultFieldName = parent::generateAttributeFieldName( $contentClassAttribute,
self::$subattributesDefinition[self::DEFAULT_SUBATTRIBUTE] );
$returnArray[$defaultFieldName] = $this->getPlainTextRepresentation();
return $returnArray;
//.........这里部分代码省略.........
示例2: testGetMetaAttributesForObject
/**
* @dataProvider providerTestGetMetaAttributesForObject
**/
public function testGetMetaAttributesForObject($expected, $contentObject)
{
self::assertEquals($expected, eZSolr::getMetaAttributesForObject($contentObject));
}
示例3: fakeAddObject
function fakeAddObject($contentObject)
{
$eZSolr = new eZSolr();
// Add all translations to the document list
$docList = array();
// Check if we need to index this object after all
// Exclude if class identifier is in the exclude list for classes
$excludeClasses = $eZSolr->FindINI->variable('IndexExclude', 'ClassIdentifierList');
if ($excludeClasses && in_array($contentObject->attribute('class_identifier'), $excludeClasses)) {
return false;
}
// Get global object values
$mainNode = $contentObject->attribute('main_node');
if (!$mainNode) {
eZDebug::writeError('Unable to fetch main node for object: ' . $contentObject->attribute('id'), __METHOD__);
return false;
}
$mainNodePathArray = $mainNode->attribute('path_array');
// initialize array of parent node path ids, needed for multivalued path field and subtree filters
$nodePathArray = array();
//included in $nodePathArray
//$pathArray = $mainNode->attribute( 'path_array' );
$currentVersion = $contentObject->currentVersion();
// Get object meta attributes.
$metaAttributeValues = eZSolr::getMetaAttributesForObject($contentObject);
// Get node attributes.
$nodeAttributeValues = array();
foreach ($contentObject->attribute('assigned_nodes') as $contentNode) {
foreach (eZSolr::nodeAttributes() as $attributeName => $fieldType) {
$nodeAttributeValues[] = array('name' => $attributeName, 'value' => $contentNode->attribute($attributeName), 'fieldType' => $fieldType);
}
$nodePathArray[] = $contentNode->attribute('path_array');
}
// Check anonymous user access.
if ($eZSolr->FindINI->variable('SiteSettings', 'IndexPubliclyAvailable') == 'enabled') {
$anonymousUserID = $eZSolr->SiteINI->variable('UserSettings', 'AnonymousUserID');
$currentUserID = eZUser::currentUserID();
$user = eZUser::instance($anonymousUserID);
eZUser::setCurrentlyLoggedInUser($user, $anonymousUserID);
$anonymousAccess = $contentObject->attribute('can_read');
$user = eZUser::instance($currentUserID);
eZUser::setCurrentlyLoggedInUser($user, $currentUserID);
$anonymousAccess = $anonymousAccess ? 'true' : 'false';
} else {
$anonymousAccess = 'false';
}
// Load index time boost factors if any
//$boostMetaFields = $eZSolr->FindINI->variable( "IndexBoost", "MetaField" );
$boostClasses = $eZSolr->FindINI->variable('IndexBoost', 'Class');
$boostAttributes = $eZSolr->FindINI->variable('IndexBoost', 'Attribute');
$boostDatatypes = $eZSolr->FindINI->variable('IndexBoost', 'Datatype');
$reverseRelatedScale = $eZSolr->FindINI->variable('IndexBoost', 'ReverseRelatedScale');
// Initialise default doc boost
$docBoost = 1.0;
$contentClassIdentifier = $contentObject->attribute('class_identifier');
// Just test if the boost factor is defined by checking if it has a numeric value
if (isset($boostClasses[$contentClassIdentifier]) && is_numeric($boostClasses[$contentClassIdentifier])) {
$docBoost += $boostClasses[$contentClassIdentifier];
}
// Google like boosting, using eZ Publish reverseRelatedObjectCount
$reverseRelatedObjectCount = $contentObject->reverseRelatedObjectCount();
$docBoost += $reverseRelatedScale * $reverseRelatedObjectCount;
// Create the list of available languages for this version :
$availableLanguages = $currentVersion->translationList(false, false);
// Loop over each language version and create an eZSolrDoc for it
foreach ($availableLanguages as $languageCode) {
$doc = new eZSolrDoc($docBoost);
// Set global unique object ID
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('guid'), $eZSolr->guid($contentObject, $languageCode));
// Set installation identifier
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('installation_id'), eZSolr::installationID());
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('installation_url'), $eZSolr->FindINI->variable('SiteSettings', 'URLProtocol') . $eZSolr->SiteINI->variable('SiteSettings', 'SiteURL') . '/');
// Set Object attributes
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('name'), $contentObject->name(false, $languageCode));
// Also add value to the "sort_name" field as "name" is unsortable, due to Solr limitation (tokenized field)
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('sort_name'), $contentObject->name(false, $languageCode));
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('anon_access'), $anonymousAccess);
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('language_code'), $languageCode);
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('available_language_codes'), $availableLanguages);
if ($owner = $contentObject->attribute('owner')) {
// Set owner name
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('owner_name'), $owner->name(false, $languageCode));
// Set owner group ID
foreach ($owner->attribute('parent_nodes') as $groupID) {
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('owner_group_id'), $groupID);
}
}
// from eZ Publish 4.1 only: object states
// so let's check if the content object has it
if (method_exists($contentObject, 'stateIDArray')) {
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName('object_states'), $contentObject->stateIDArray());
}
// Set content object meta attribute values.
foreach ($metaAttributeValues as $metaInfo) {
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName($metaInfo['name']), ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType']));
}
// Set content node meta attribute values.
foreach ($nodeAttributeValues as $metaInfo) {
$doc->addField(ezfSolrDocumentFieldBase::generateMetaFieldName($metaInfo['name']), ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType']));
}
//.........这里部分代码省略.........
示例4: getData
/**
* @see ezfSolrDocumentFieldBase::getData()
*/
public function getData()
{
/** @var eZContentClassAttribute $contentClassAttribute */
$contentClassAttribute = $this->ContentObjectAttribute->attribute('contentclass_attribute');
switch ($contentClassAttribute->attribute('data_type_string')) {
case 'ezobjectrelation':
$returnArray = array();
/** @var eZContentObject $relatedObject */
$relatedObject = $this->ContentObjectAttribute->content();
if ($relatedObject) {
$returnArray = $this->getArrayRelatedObject($relatedObject, $contentClassAttribute);
eZContentObject::clearCache(array($relatedObject->attribute('id')));
}
return $returnArray;
break;
case 'ezobjectrelationlist':
$returnArray = array();
$returnArrayRelatedObject = array();
$content = $this->ContentObjectAttribute->content();
$relationCount = count($content['relation_list']);
foreach ($content['relation_list'] as $relationItem) {
$subObjectID = $relationItem['contentobject_id'];
if (!$subObjectID) {
continue;
}
/** @var eZContentObjectVersion $subObject */
$subObject = eZContentObjectVersion::fetchVersion($relationItem['contentobject_version'], $subObjectID);
if (!$subObject instanceof eZContentObjectVersion) {
$subObjectWrapper = eZContentObject::fetch($subObjectID);
if ($subObjectWrapper instanceof eZContentObject) {
$subObject = $subObjectWrapper->currentVersion();
} else {
continue;
}
}
/** @var eZContentObject $subContentObject */
$subContentObject = $subObject->attribute('contentobject');
if (intval($subContentObject->attribute('main_node_id')) == 0) {
continue;
}
$metaAttributeValues = eZSolr::getMetaAttributesForObject($subContentObject);
foreach ($metaAttributeValues as $metaInfo) {
$submetaFieldName = ezfSolrDocumentFieldBase::generateSubmetaFieldName($metaInfo['name'], $contentClassAttribute);
if (isset($returnArray[$submetaFieldName])) {
$returnArray[$submetaFieldName] = array_merge($returnArray[$submetaFieldName], array(ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType'])));
} else {
$returnArray[$submetaFieldName] = array(ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType']));
}
}
$nodeAttributeValues = array();
$nodePathArray = array();
/** @var eZContentObjectTreeNode $contentNode */
foreach ($subContentObject->attribute('assigned_nodes') as $contentNode) {
foreach (eZSolr::nodeAttributes() as $attributeName => $fieldType) {
$nodeAttributeValues[] = array('name' => $attributeName, 'value' => $contentNode->attribute($attributeName), 'fieldType' => $fieldType);
}
$nodePathArray[] = $contentNode->attribute('path_array');
}
//@todo questo non va... occorre correggere schema.xml?
//foreach ( $nodeAttributeValues as $metaInfo )
//{
// $submetaFieldName = ezfSolrDocumentFieldBase::generateSubmetaFieldName( $metaInfo['name'], $contentClassAttribute );
// if ( isset( $returnArray[$submetaFieldName] ) )
// {
// $returnArray[$submetaFieldName] = array_merge( $returnArray[$submetaFieldName],
// array( ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] ) ) );
// }
// else
// {
// $returnArray[$submetaFieldName] = array( ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] ) );
// }
//}
foreach ($nodePathArray as $pathArray) {
$submetaFieldName = ezfSolrDocumentFieldBase::generateSubmetaFieldName('path', $contentClassAttribute);
foreach ($pathArray as $pathNodeID) {
if (isset($returnArray[$submetaFieldName])) {
$returnArray[$submetaFieldName] = array_merge($returnArray[$submetaFieldName], array($pathNodeID));
} else {
$returnArray[$submetaFieldName] = array($pathNodeID);
}
}
}
if ($relationCount < 200) {
$returnArrayRelatedObject = $this->getArrayRelatedObject($subContentObject, $contentClassAttribute, $returnArrayRelatedObject);
} else {
$objectName = $subContentObject->name(false, $this->ContentObjectAttribute->attribute('language_code'));
$fieldName = parent::generateSubattributeFieldName($contentClassAttribute, 'name', self::DEFAULT_SUBATTRIBUTE_TYPE);
if (isset($returnArrayRelatedObject[$fieldName])) {
$returnArrayRelatedObject[$fieldName][] = $objectName;
} else {
$returnArrayRelatedObject[$fieldName] = array($objectName);
}
}
$returnArray = array_merge_recursive($returnArray, $returnArrayRelatedObject);
eZContentObject::clearCache(array($subContentObject->attribute('id')));
}
$defaultFieldName = parent::generateAttributeFieldName($contentClassAttribute, self::$subattributesDefinition[self::DEFAULT_SUBATTRIBUTE]);
//.........这里部分代码省略.........
示例5: testGetData
/**
* test for getData()
*/
public function testGetData()
{
$providerArray = array();
#start 1 : the simplest attribute
$content1 = "Hello world";
$ezcca1 = new eZContentClassAttribute(array('identifier' => 'title', 'data_type_string' => 'ezstring'));
$ezcoa1 = new eZContentObjectAttributeTester(array("data_type_string" => 'ezstring', "id" => 100123, "data_text" => $content1, "contentclass_attribute" => $ezcca1));
$fieldName1 = ezfSolrDocumentFieldBase::getFieldName($ezcca1);
$expectedData1 = array($fieldName1 => $content1);
$providerArray[] = array($expectedData1, $ezcoa1);
#end 1
#start 2 : attribute with subattributes
$ezcca2 = new eZContentClassAttribute(array('identifier' => 'dummy', 'data_type_string' => 'dummy_example'));
$ezcoa2 = new eZContentObjectAttributeTester(array("data_type_string" => 'dummy_example', "id" => 100124, "contentclass_attribute" => $ezcca2));
$fieldList2 = ezfSolrDocumentFieldBase::getFieldNameList($ezcca2);
$expectedData2 = array();
foreach ($fieldList2 as $fieldName) {
$expectedData2[$fieldName] = 'DATA_FOR_' . $fieldName;
}
$fieldName2 = ezfSolrDocumentFieldBase::getFieldName($ezcca2);
$providerArray[] = array($expectedData2, $ezcoa2);
#end 2
#start 3 : object relations
$expectedData3 = array();
$tester3 = new ezfSolrDocumentFieldObjectRelationTester(new eZContentObjectAttribute(array()));
$time3 = time();
$image3 = new ezpObject("image", 2);
$image3->name = __METHOD__ . $time3;
$image3->caption = __METHOD__ . $time3;
$imageId3 = $image3->publish();
// $image3->object->clearCache();
$dataMapImage3 = $image3->dataMap;
// eZContentObjectAttribute objects, attributes of the related Image
$imageName3 = $dataMapImage3['name'];
$imageCaption3 = $dataMapImage3['caption'];
$article3 = new ezpObject("article", 2);
$articleId3 = $article3->publish();
// Create object relation
$article3->object->addContentObjectRelation($imageId3, $article3->current_version, 154, eZContentObject::RELATION_ATTRIBUTE);
$dataMapArticle3 = $article3->attribute('data_map');
$ezcoa3 = $dataMapArticle3['image'];
$ezcoa3->setAttribute('data_int', $imageId3);
$ezcoa3->store();
$ezcca3 = $ezcoa3->attribute('contentclass_attribute');
$defaultFieldName3 = ezfSolrDocumentFieldBase::generateAttributeFieldName($ezcca3, ezfSolrDocumentFieldObjectRelation::$subattributesDefinition[ezfSolrDocumentFieldObjectRelation::DEFAULT_SUBATTRIBUTE]);
$expectedData3[$defaultFieldName3] = $tester3->getPlainTextRepresentation($ezcoa3);
// required to allow another call to metaData()
// on $ezcoa3 in getPlainTextRepresentation, called from the getData() method :
eZContentObject::recursionProtectionEnd();
$fieldNameImageName3 = ezfSolrDocumentFieldBase::generateSubattributeFieldName($ezcca3, $imageName3->attribute('contentclass_attribute_identifier'), ezfSolrDocumentFieldObjectRelation::getClassAttributeType($imageName3->attribute('contentclass_attribute')));
$expectedData3[$fieldNameImageName3] = trim(implode(' ', array_values(ezfSolrDocumentFieldBase::getInstance($imageName3)->getData())), "\t\r\n ");
$fieldNameImageCaption3 = ezfSolrDocumentFieldBase::generateSubattributeFieldName($ezcca3, $imageCaption3->attribute('contentclass_attribute_identifier'), ezfSolrDocumentFieldObjectRelation::getClassAttributeType($imageCaption3->attribute('contentclass_attribute')));
$expectedData3[$fieldNameImageCaption3] = trim(implode(' ', array_values(ezfSolrDocumentFieldBase::getInstance($imageCaption3)->getData())), "\t\r\n ");
$image3 = eZContentObject::fetch($imageId3);
$metaAttributeValues = eZSolr::getMetaAttributesForObject($image3);
foreach ($metaAttributeValues as $metaInfo) {
$expectedData3[ezfSolrDocumentFieldBase::generateSubmetaFieldName($metaInfo['name'], $ezcca3)] = ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType']);
}
$providerArray[] = array($expectedData3, $ezcoa3);
#end 3
// Let's perform the actual testing :
foreach ($providerArray as $input) {
$expected = $input[0];
$contentObjectAttribute = $input[1];
$instance = ezfSolrDocumentFieldBase::getInstance($contentObjectAttribute);
self::assertEquals($expected, $instance->getData());
}
}