eZ Community » Forums » Developer » ezfind challenges
expandshrink

ezfind challenges

ezfind challenges

Friday 09 March 2012 2:53:24 pm - 6 replies

Hi,

I've been playing around with ezfind, and I'm having trouble with the facets for an object relation(s) attribute.

While I seemingly fixed the object relation (ezobjectrelation) faceting/indexing by modifying ezfind/classes/ezsolrdocumentfieldobjectrelation.php, I'm still having issues with multiple relations (ezobjectrelationlist).

Some of the facets returned look something like this: "55-56 Name of object1 57-58 Name of object2", while some of them look fine ("Name of object1"blunk.gif Emoticon.

Why is this happening?

Friday 09 March 2012 3:50:32 pm

Quote from Helge Silset :

Hi,

I've been playing around with ezfind, and I'm having trouble with the facets for an object relation(s) attribute.

While I seemingly fixed the object relation (ezobjectrelation) faceting/indexing by modifying ezfind/classes/ezsolrdocumentfieldobjectrelation.php, I'm still having issues with multiple relations (ezobjectrelationlist).

Some of the facets returned look something like this: "55-56 Name of object1 57-58 Name of object2", while some of them look fine ("Name of object1"blunk.gif Emoticon.

Why is this happening?

Hi

what are you modifing.?

the class you are modifying is the one that handle 'object relation' and 'object relations'  (throught CustomMap in SolrFieldMapSettings of ezfind.ini)

I think you could do that in other way instead of modifying source Code:

you may change FieldMapSettings and create a new Class to handle ezobjectrelation as it should for you blunk.gif Emoticon

As I know, you may declare customMap class for 'ezobjectrelation' datatype and make your changes in your own created class. doing that you will not have to change source Code:

ie ezfind.ini

[SolrFieldMapSettings]

CustomMap[ezobjectrelation]=YourNewModifiedClass

#default ezclass

CustomMap[ezobjectrelationlist]=ezfSolrDocumentFieldObjectRelation

this may avoid the kind of problem your are having

Modified on Friday 09 March 2012 3:51:46 pm by Ousmane KANTE

Monday 12 March 2012 3:43:14 pm

Hi,

When i indexed the installation with a default ezfind setup, all of my relations (ezobjectrelation AND ezobjectrelationlist) were split into, seemingly, keywords, so "My related object" displayed as "My", "related" and "object" in the facets. So the use of ezfSolrDocumentFieldObjectRelation for relations attributes aren't working as I'd expect "out of the box".

Then I set the following in classes/ezfsolrdocumentfieldobjectrelation.php:

 public static $subattributesDefinition = array( self::DEFAULT_SUBATTRIBUTE => 'string' );

and

 const DEFAULT_SUBATTRIBUTE = 'name';

I also added two lines in settings/ezfind.ini:

DatatypeMap[ezobjectrelation]=string
 DatatypeMap[ezobjectrelationlist]=string

This made the indexing of ezobjectrelation work just fine, and ezobjectrelationlist ended up like described in the OP.

I know I probably should have made a custom class for this, but for this testcase I didn't find it necessary to write a class from scratch.

Helge

Saturday 23 June 2012 6:36:40 pm

I'm having exactly the same problem with ezobjectrelationlist. Has anyone ever solved the problem for multiple object relations? Following what Helge did above (whether with the original classes/ezfsolrdocumentfieldobjectrelation.php or my own version specified in ezfind.ini makes no difference) solves the problem of object relation facets displayed as "My", "Object", "1", "2", "3", but with ezobjectrelationlist I get "My Object 1 My Object 2 My Object 3" rather than the "My Object 1",  "My Object 2", "My Object 3" I'd expect.

Help!

Thursday 26 July 2012 2:44:52 pm

I had exactly the same problem, I modified the ezfsolrdocumentfieldobjectrelation class as well, and created a new fieldtype in schema.xml to handle objectrelations. This way I managed to get the facets working while preserving the whole relations with their whitespaces like "My Object 1", "My Object 2", "My Object 3"...

But now I noticed that my facets aren't being translated which renders the whole object relations ezfind/facets stuff pretty much useless to me.

@andy, if you don't need multilanguage support i could send you my changes, so maybe at least you could use facets with object relations.

I would be grateful for any advice regarding this issue.

Thanks

Modified on Thursday 26 July 2012 3:11:05 pm by Yves Thommes

Friday 27 July 2012 8:32:54 am

Hi Yves

We resolved this in the same way as you, modifying the ezfsolrdocumentfieldobjectrelation class and schema.xml. We also found that eZ Find 2.5 / solr 3.1 was not working well. Things worked much better after we upgraded to eZ Find 2.7 / solr 3.5.

We don't need multilanguage support for this project although we do a lot of multilingual websites so it's possible we'll need it in the future. Is eZ Find correctly translating the search results generally?

Andy

Tuesday 21 August 2012 11:09:24 am

With newer ezfind versions (not sure if versions before 2.7 will work) there is a simple and clean way to do this.

Just register a custom index-plugin in ezfind.ini, and add new custom fields to the solr docs while indexing.

By choosing the right suffix for the field name, you can make sure the field is multivalued and the content is a string.

The following code of the index plugin is just an example, it will create an multivalued string field for each ezobjectrelation-attribute found in a given contentobject and use the Name-Attribute of the related objects as content.

 <?php
 /**
 * This index-plugin looks for ezobjectrelationlist attributes in given contentObject and
 * adds special multi-valued fields of type string to the given solrDoc
 *
 * With the help of these fields you can do faceting on ezobjectrelationlist attributes
 *
 */
class okapiEzfIndexObjectRelations implements ezfIndexPlugin
{
    /**
     * The modify method gets the current content object AND the list of
     * Solr Docs (for each available language version).
     *
     * @param eZContentObject $contentObect
     * @param array $docList
     */
    public function modify( eZContentObject $contentObject, &$docList )
    {
        //$logger = OkapiLog::getInstance();
        $currentVersion = $contentObject->currentVersion();
        $dataMap = $contentObject->DataMap();

        // Look for ezobjectrelationlist attributes
        foreach( $dataMap as $attributeIdentifier => $attribute )
        {
            // proceed only for ezobjectrelationlist attributes
            $type = $attribute->DataTypeString;
            if( $type != 'ezobjectrelationlist')
                continue;

            // Collect The contentObjectIDs for all relatedObjects
            $content = $attribute->Content();
            $relatedObjectIds = array();
            foreach( $content['relation_list'] as $relation )
            {
                $relatedObjectIds[] = $relation['contentobject_id'];
            }

            // proceed only if we have at least one relation
            if( !count( $relatedObjectIds ))
                continue;

            // fetch relatedObjects and collect their "Name"
            $relatedObjects = eZContentObject::fetchIDArray($relatedObjectIds);
            $relatedObjectNames = array();
            foreach( $relatedObjects as $relatedObject)
            {
                $relatedObjectNames[] = $relatedObject->Name();
            }

            // Add custom field in solr doc for every language
            $solrFieldName = "extra_ezobjectrelationlist_{$attributeIdentifier}_names____ms";
            $availableLanguages = $currentVersion->translationList( false, false );
            foreach ( $availableLanguages as $languageCode )
            {
                $docList[$languageCode]->addField($solrFieldName, $relatedObjectNames );
            }
        }
    }
}

?>

Hope this helps someone to save some time..

Modified on Tuesday 21 August 2012 11:11:28 am by Patrick Kaiser

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu