eZ Community » Forums » Extensions » eZ Find » Facets and ezselection
expandshrink

Facets and ezselection

Facets and ezselection

Monday 08 March 2010 5:59:54 pm - 13 replies

Hello,

I have a search on a unique content type (user) and facets on attributes of a related object of the content type (the related object is a profile so the facets are each attributes of the profile).

I have a problem with a facet that is always empty (it's a ezselection), whereas I have other facet of type ezselection that works on the same search !

The ezselection is unique and I checked the metaData() method of the datatype and it returns the value so it's okay.

I don't know what else to check to debug this problem ? Any clue ?

Thank you !

PS : facets on related object is awesome ! (except for ezselection happy.gif Emoticon )

Wednesday 10 March 2010 3:43:20 pm

What are the available options for the ezselection that is always empty? Is it in the same class as the other ezselection?

Wednesday 10 March 2010 4:10:00 pm

on a first selection (the one not working) I have :

  • Salarie dune structure
  • Liberal

On the other one :

  • Bovin
  • Ovin
  • Caprin
  • Porc

It is all using the native ezselection datatype

Wednesday 10 March 2010 4:16:53 pm

Have you tried with only 'Salarie' instead of 'Salarie dune structure'? The spaces in the option seem to be the only difference between both selections. And both selections are in the same class?

Wednesday 10 March 2010 5:38:33 pm

yes and it makes not differences ...

Tuesday 14 June 2011 8:20:42 pm

How did you manage to fix this? I have a similar problem where characters are missing.

Tuesday 14 June 2011 8:47:58 pm

How did you manage to fix this? I have a similar problem where characters are missing.

You should configure ez find so that ezselection is indexed as string for facet, it should do it 

Wednesday 15 June 2011 4:10:22 pm

You want the code? There you are:

 <?php
/**
 * Helper class to index multiple-choice-selection attributes
 * We want to
 * - allow the end users to be able to search using the names of selection items
 * - have a working faceting schema even if selection items contains spaces (eg: english spoken)
 *
 * @author
 * @version $Id$
 * @copyright (C) 2011
 */
 
class ezfSolrDocumentFieldSelection extends ezfSolrDocumentFieldBase
{
    /**
    * Use a specific field name to allow faceting: a string that does not tokenize
    */
    public static function getFieldName( eZContentClassAttribute $classAttribute, $subAttribute = null, $context = 'search' )
    {
        if ( $context == 'facet' )
        {
            return self::ATTR_FIELD_PREFIX . $classAttribute->attribute( 'identifier' ) . '____ms';
        }
        return self::ATTR_FIELD_PREFIX . $classAttribute->attribute( 'identifier' ) . '_s';
 
    }
 
    /**
    * Index data twice: once in a facetable filed, one in a searchable field
    */
    public function getData()
    {
        //logic taken from eZSelectionType::toString
        $contentClassAttribute = $this->ContentObjectAttribute->attribute( 'contentclass_attribute' );
        $field = self::getFieldName( $contentClassAttribute );
        $ffield = self::getFieldName( $contentClassAttribute, 'null', 'facet' );
 
        $selected = ezSelectiontype::objectAttributeContent( $this->ContentObjectAttribute );
        if ( count( $selected ) )
        {
            $returnData = array();
            $classContent = ezSelectiontype::classAttributeContent( $this->ContentObjectAttribute->attribute( 'contentclass_attribute' ) );
            $optionArray = $classContent['options'];
            foreach ( $selected as $id )
            {
                foreach ( $optionArray as $option )
                {
                    $optionID = $option['id'];
                    if ( $optionID == $id )
                    {
                        $returnData[] = $option['name'];
                        break;
                    }
                }
                /// @todo add warning if any unknown ids left
            }
            return array( $ffield => $returnData, $field => implode( $returnData, ' ' ) );
        }
        return array( $field => '', $ffield => array() );
    }
}
 
?>

Thursday 16 June 2011 9:50:23 am

Thanks alot Gaetano, you just saved me a lot of time!

Monday 04 July 2011 10:47:49 am

Hello guys,

I've try the Gaetano's class.Facets works fine.

But filter doesn't work for me. What is the syntax ?

I try

 filter, array('my_class/my_attr:massage' ),

or

 filter, array('my_class/my_attr/massage' ),

Thanks

Monday 04 July 2011 6:22:44 pm

@fabien when you use custom names for your indexed fields (such as the case here, the name ends in __ms to get the proper non-split-non-stemmed string type in solr), you pass to the fetch filter the name of the field directly as it is in solr

Monday 10 October 2011 1:34:35 pm

For people whom don't know how to implement Gaetano's classes :

1)  Place this file in extension/[your_extension]/classes/
2)  Add the following to your ezfind.ini override:
[SolrFieldMapSettings]
CustomMap[ezselection]=ezfSolrDocumentFieldSelection
3)  Update solr index with "ezfind/bin/php/updatesearchindexsolr.php"
4) Then your website facets should display mutiple ezselection values one by one 

For information if you copy paste the code from this post clean up spaces at start of each line or it'll crash.

Modified on Monday 10 October 2011 2:22:59 pm by H-Works Agency

Tuesday 31 January 2012 6:48:37 pm

Hello everyone,

I first thought i got it but i Gaetano class doesn't work for me : Once activated facets don't appear anymore.

Does anyone really used the unmodified class and made it work or do we need to adapt it ?

In the class there is a part "implode( $returnData, ' ')" i think arguments are inverted.

Thank you in advance.

Modified on Wednesday 01 February 2012 12:06:04 pm by H-Works Agency

Tuesday 31 January 2012 6:54:35 pm

Finally got it, here is what works for me if someone is interested :

replace this line in getData function : return array( $ffield => $returnData, $field => implode(' ', $returnData ) );

By this line : return array($field => $returnData);

Modified on Wednesday 01 February 2012 2:17:53 pm by H-Works Agency

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from