Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom class-attributes indexing #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion classes/ezfsolrdocumentfieldbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,23 @@ public static function getFieldNameList( eZContentClassAttribute $classAttribute
}
}

$customAttributeMap = $eZFindIni->variable('SolrFieldMapSettings', 'CustomAttributeMap');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style is a bit off.

if ($customAttributeMap) {
$identifier = $classAttribute->attribute('identifier');
$contentClass = eZContentClass::fetch($classAttribute->attribute('contentclass_id'));
$identifierComposite = sprintf(
'%s/%s',
$contentClass->attribute('identifier'),
$identifier
);
if (array_key_exists($identifierComposite, $customAttributeMap)) {
$returnValue = call_user_func_array([$customAttributeMap[$identifierComposite], 'getFieldNameList'], [$classAttribute, $exclusiveTypeFilter]);
if ($returnValue) {
return $returnValue;
}
}
}

// fallback behaviour :
if ( empty( $exclusiveTypeFilter ) or !in_array( self::getClassAttributeType( $classAttribute ), $exclusiveTypeFilter ) )
return array( self::getFieldName( $classAttribute ) );
Expand Down Expand Up @@ -303,7 +320,22 @@ public static function getFieldName( eZContentClassAttribute $classAttribute, $s
static function getInstance( eZContentObjectAttribute $objectAttribute )
{
$eZFindIni = eZINI::instance( 'ezfind.ini' );


$attributeMapList = $eZFindIni->variable('SolrFieldMapSettings', 'CustomAttributeMap');
if (!empty($attributeMapList)) {
$contentClassId = $objectAttribute->attribute('contentclass_attribute')->attribute('contentclass_id');
$contentClass = eZContentClass::fetch($contentClassId);
$identifierComposite = sprintf(
'%s/%s',
$contentClass->attribute('identifier'),
$objectAttribute->attribute('contentclass_attribute_identifier')
);
if (array_key_exists($identifierComposite, $attributeMapList)) {
return self::$singletons[$objectAttribute->attribute('id')] = new $attributeMapList[$identifierComposite]($objectAttribute);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check if the class really exists. Not sure but trying to get an instance of a non-existing class is probably throwing a fatal error?
Is that self::$singletons used anywhere?

}
unset($identifierComposite, $contentClass);
}

$datatypeString = $objectAttribute->attribute( 'data_type_string' );

// Check if using custom handler.
Expand Down
13 changes: 8 additions & 5 deletions search/plugins/ezsolr/ezsolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -1654,11 +1654,14 @@ protected function buildResultObjects( $resultArray, &$searchCount, $asObjects =
{
$tmpNodeRowList = array( $tmpNodeRowList );
}
if ( $tmpNodeRowList )
{
foreach ( $tmpNodeRowList as $nodeRow )
{
$nodeRowList[$nodeRow['node_id']] = $nodeRow;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it that code required? Also, it has nothing to do with what the pull request describes, right?

if ($tmpNodeRowList) {
if (isset($tmpNodeRowList[0])) {
foreach ($tmpNodeRowList as $nodeRow) {
$nodeRowList[$nodeRow['node_id']] = $nodeRow;
}
} else {
$nodeRowList[$tmpNodeRowList['node_id']] = $tmpNodeRowList;
}
}
unset( $tmpNodeRowList );
Expand Down
8 changes: 4 additions & 4 deletions settings/ezfind.ini
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ DatatypeMapFilter[ezselection]=string
Default=text


#Allows to have specific handlers for atributes instead of generalizing it for datatypes
#This makes it easier for example to store structured content inside eztext attributes
# Allows to have specific handlers for atributes instead of generalizing it for datatypes
# This makes it easier for example to store structured content inside eztext attributes
# YourCustomMapperClass should extend ezfSolrDocumentFieldBase and overwrite the getFieldNameList and getData methods
CustomAttributeMap[]
#
#CustomAttributeMap[class_identifier/attribute_identifier]=ezfSolrDocumentFieldMetaData
#CustomAttributeMap[class_identifier/attribute_identifier]=YourCustomMapperClass


[IndexOptions]
Expand Down