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

Ezp 24326 ezfind full location support #195

Open
wants to merge 3 commits 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
6 changes: 6 additions & 0 deletions classes/ezfezpsolrquerybuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
implode( ' ', $docTransformerFields) . ' ' .
implode( ' ', $extraFieldsToReturn );

// WIP locations as child docs of main content
// first add a "parent" filter to the main query
$filterQuery[]='meta_doctype_ms:content';
// add the child doctransformer
$fieldsToReturnString .= ' ' . '[child parentFilter="meta_doctype_ms:content" childFilter="meta_doctype_ms:location"]';

if ( ! $asObjects )
{
if ( empty( $fieldsToReturn ))
Expand Down
22 changes: 13 additions & 9 deletions classes/ezfindresultnode.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ function eZFindResultNode( $rows = array() )
$this->ContentObjectID = $rows['id'];
}
$this->LocalAttributeValueList = array();
$this->LocalAttributeNameList = array( 'is_local_installation',
'name',
'global_url_alias',
'published',
'language_code',
'highlight',
'score_percent',
'elevated'
);
$this->LocalAttributeNameList = array(
'is_local_installation',
'name',
'global_url_alias',
'published',
'language_code',
'highlight',
'score_percent',
'elevated',
//WIP: for now contains raw dump of child docs returned ... ie all nodes that satisfy
// upstream child filter conditions
'children',
);
}

/*!
Expand Down
55 changes: 42 additions & 13 deletions classes/ezsolrdoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class eZSolrDoc
*/
public $Doc = array();

/**
*
* @var array of child documents as eZSolrDoc objects!
*/
public $Children = array();

/**
*
* @var numeric
Expand Down Expand Up @@ -105,23 +111,25 @@ public function setFieldBoost ($name, $boost)
}
}


/**
* Convert current object to XML string
*
* @return string XML string.
* @param DOMDocument $domDoc The (usually) empty DOM master document
* @param mixed $inputArray containing the fields, field values and field boosts
* @param Booleam $boost the Lucene overall document boost to apply if any
* @return DOMElement The doc and field structure
*/
function docToXML()
public static function createDocElementFromArray( DOMDocument $domDoc, $inputArray = array(), $boost = NULL )
{
$this->DomDoc = new DOMDocument( '1.0', 'utf-8' );
$this->DomRootElement = $this->DomDoc->createElement( 'doc' );
$this->DomDoc->appendChild( $this->DomRootElement );
$docRootElement = $domDoc->createElement( 'doc' );

if ($this->DocBoost !== null && is_numeric( $this->DocBoost ) )
if ( $boost !== null && is_numeric( $boost ) )
{
$this->DomRootElement->setAttribute( 'boost', $this->DocBoost );
$docRootElement->setAttribute( 'boost', $boost );
}

foreach ($this->Doc as $name => $field) {
foreach ( $inputArray as $name => $field )
{
foreach( $field['content'] as $value )
{
// $value should never be array. Log the value and the stack trace.
Expand All @@ -133,19 +141,40 @@ function docToXML()
"\nStack trace: " . var_export( $dump, 1 ) );
continue;
}
$fieldElement = $this->DomDoc->createElement( 'field' );
$fieldElement->appendChild( $this->DomDoc->createTextNode( $value ) );
$fieldElement = $domDoc->createElement( 'field' );
$fieldElement->appendChild( $domDoc->createTextNode( $value ) );
$fieldElement->setAttribute( 'name', $name );

if ( $field['boost'] !== null && is_numeric( $field['boost'] ) )
if ( isset( $field['boost'] ) && is_numeric( $field['boost'] ) )
{
$fieldElement->setAttribute( 'boost', $field['boost'] );
}

$this->DomRootElement->appendChild( $fieldElement );
$docRootElement->appendChild( $fieldElement );
}
}
return $docRootElement;
}

/**
* Convert current object to XML string
*
* @return string XML string.
*/
function docToXML()
{
$this->DomDoc = new DOMDocument( '1.0', 'utf-8' );
$this->DomRootElement = self::createDocElementFromArray( $this->DomDoc, $this->Doc, $this->DocBoost );

foreach ( $this->Children as $child )
{
if ( $child instanceof eZSolrDoc )
{
$this->DomRootElement->appendChild( self::createDocElementFromArray( $this->DomDoc, $child->Doc ) );
}
}

$this->DomDoc->appendChild( $this->DomRootElement );

$rawXML = $this->DomDoc->saveXML( $this->DomRootElement );
//make sure there are no control characters left that could currupt the XML string
Expand Down
1 change: 1 addition & 0 deletions java/solr/ezp-default/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@
&customfields;

<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="_root_" type="string" indexed="true" stored="false"/>

<field name="meta_guid_ms" type="mstring" indexed="true" stored="true" /> <!-- Global unique ID ( per installation per object per language ) -->

Expand Down
83 changes: 72 additions & 11 deletions search/plugins/ezsolr/ezsolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@ static function nodeAttributes()
'view_count' => 'sint' );
}


/**
*
* @return array additional node attributes which are stored in the nested location child docs
*/
static function additionalNodeAttributes()
{
return array( 'parent_node_id' => 'mstring',
'main_node_id' => 'mstring',
'parent_node_id' => 'mstring',
'contentobject_id' => 'mstring',
'path_identification_string' => 'mstring',
'remote_id' => 'mstring',
'name' => 'mstring',
'children_count' => 'sint',
'is_main' => 'boolean',
'url' => 'mstring',
'class_identifier' => 'mstring',
'class_name' => 'mstring',
'is_container' => 'boolean',);
}


/**
* Get meta attribute Solr document field type
*
Expand Down Expand Up @@ -130,7 +153,8 @@ static function getMetaAttributeType( $name, $context = 'search' )
'visible_path_string' => 'mstring',
'hidden_path_string' => 'mstring' ),
self::metaAttributes(),
self::nodeAttributes() ),
self::nodeAttributes(),
self::additionalNodeattributes() ),
'facet' => array(
'owner_name' => 'string' ),
'filter' => array(),
Expand Down Expand Up @@ -489,9 +513,18 @@ function addObject( $contentObject, $commit = true, $commitWithin = 0, $softComm
$nodeID = $contentNode->attribute( 'node_id' );
foreach ( eZSolr::nodeAttributes() as $attributeName => $fieldType )
{
$nodeAttributeValues[$nodeID][] = array( 'name' => $attributeName,
'value' => $contentNode->attribute( $attributeName ),
'fieldType' => $fieldType );
$nodeAttributeValues[$nodeID][$attributeName] = array(
'value' => $contentNode->attribute($attributeName),
'fieldType' => $fieldType);
}

//WIP additional meta info for locations/nodes
foreach (eZSolr::additionalNodeAttributes() as $attributeName => $fieldType)
{
$additionalAttributeValues[$nodeID][$attributeName] = array (
'value' => $contentNode->attribute($attributeName),
'fieldType' => $fieldType);

}
$nodePathArray[] = $contentNode->attribute( 'path_array' );
if ( $contentNode->attribute( 'is_hidden' ) || $contentNode->attribute( 'is_invisible' ) )
Expand Down Expand Up @@ -561,6 +594,8 @@ function addObject( $contentObject, $commit = true, $commitWithin = 0, $softComm
$doc = new eZSolrDoc( $docBoost );
// Set global unique object ID
$doc->addField( ezfSolrDocumentFieldBase::generateMetaFieldName( 'guid' ), $this->guid( $contentObject, $languageCode ) );
// WIP: hardcoded fieldname for now
$doc->addField('meta_doctype_ms','content');

// Set installation identifier
$doc->addField( ezfSolrDocumentFieldBase::generateMetaFieldName( 'installation_id' ), self::installationID() );
Expand Down Expand Up @@ -604,19 +639,43 @@ function addObject( $contentObject, $commit = true, $commitWithin = 0, $softComm
}

// Set content node meta attribute values.
// WIP: initial hack, add children docs here as well
foreach ( $nodeAttributeValues as $nodeID => $metaInfoArray )
{
foreach( $metaInfoArray as $metaInfo)
$doc->Children[$nodeID] = new eZSolrDoc();
$doc->Children[$nodeID]->addField( ezfSolrDocumentFieldBase::generateMetaFieldName( 'guid' ), $this->guid( $contentObject, $languageCode, $nodeID ) );
// hardcoded field name for now
$doc->Children[$nodeID]->addField('meta_doctype_ms','location');

foreach( $metaInfoArray as $metaInfoName => $metaInfo)
{
$doc->addField( ezfSolrDocumentFieldBase::generateMetaFieldName( $metaInfo['name'] ),
ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] ) );
$locFieldName = ezfSolrDocumentFieldBase::generateMetaFieldName( $metaInfoName );
$locFieldValue = ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] );
$doc->addField( $locFieldName, $locFieldValue );
$doc->Children[$nodeID]->addField('loc_' . $locFieldName, $locFieldValue);
}
// WIP: add sorting by priority values as a field in the content doc for the respective parent
// location (aka node) ids
}

//WIP additional meta data to add to the location child docs
foreach ( $additionalAttributeValues as $nodeID => $metaInfoArray )
{
foreach( $metaInfoArray as $metaInfoName => $metaInfo)
{
$locFieldName = ezfSolrDocumentFieldBase::generateMetaFieldName( $metaInfoName );
$locFieldValue = ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'], $metaInfo['fieldType'] );
$doc->Children[$nodeID]->addField('loc_' . $locFieldName, $locFieldValue);
}
// provide data for sorting according to the the fetch content list way, 1 level deep
$doc->addField('loc_priority_for_parent_' . $additionalAttributeValues[$nodeID]['parent_node_id']['value'] . '_i', $nodeAttributeValues[$nodeID]['priority']['value']);

}

// Main node gets single valued fields for sorting, using a dedicated prefix
foreach ( $nodeAttributeValues[$mainNodeID] as $metaInfo )
foreach ( $nodeAttributeValues[$mainNodeID] as $metaInfoName => $metaInfo )
{
$fieldName = 'main_node_' . ezfSolrDocumentFieldBase::generateMetaFieldName( $metaInfo['name'] );
$fieldName = 'main_node_' . ezfSolrDocumentFieldBase::generateMetaFieldName( $metaInfoName );
$doc->addField( $fieldName,
ezfSolrDocumentFieldBase::preProcessValue( $metaInfo['value'],
$metaInfo['fieldType'] ) );
Expand Down Expand Up @@ -1220,12 +1279,12 @@ static function installationID()
* @param string $languageCode
* @return string guid
*/
function guid( $contentObject, $languageCode = '' )
function guid( $contentObject, $languageCode = '', $locationID = '' )
{
if ( !$contentObject instanceof eZContentObject )
return md5( self::installationID() . '-' . $contentObject . '-' . $languageCode );

return md5( self::installationID() . '-' . $contentObject->attribute( 'id' ) . '-' . $languageCode );
return md5( self::installationID() . '-' . $contentObject->attribute( 'id' ) . '-' . $languageCode . '-' . $locationID );
}

/**
Expand Down Expand Up @@ -1696,6 +1755,7 @@ protected function buildResultObjects( $resultArray, &$searchCount, $asObjects =
$emit['highlight'] = isset( $highLights[$doc[ezfSolrDocumentFieldBase::generateMetaFieldName( 'guid' )]] ) ?
$highLights[$doc[ezfSolrDocumentFieldBase::generateMetaFieldName( 'guid' )]] : null;
$emit['elevated'] = ( isset($doc['[elevated]']) ? $doc['[elevated]'] === true : false );
$emit['children'] = ( isset( $doc['_childDouments_'] ) ) ? $doc['_childDocuments_'] : NULL;
$objectRes[] = $emit;
unset( $emit );
continue;
Expand Down Expand Up @@ -1780,6 +1840,7 @@ protected function buildResultObjects( $resultArray, &$searchCount, $asObjects =
$maxScore != 0 ? $resultTree->setAttribute( 'score_percent', (int) ( ( $doc['score'] / $maxScore ) * 100 ) ) : $resultTree->setAttribute( 'score_percent', 100 );
$resultTree->setAttribute( 'language_code', $doc[ezfSolrDocumentFieldBase::generateMetaFieldName( 'language_code' )] );
$resultTree->setAttribute( 'elevated', ( isset($doc['[elevated]']) ? $doc['[elevated]'] === true : false ) );
$resultTree->setAttribute( 'children', ( isset($doc['_childDocuments_']) ? $doc['_childDocuments_'] : NULL ) );
$objectRes[] = $resultTree;
}
}
Expand Down