This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Extensions » eZ Find » Sorting on subattribute
expandshrink

Sorting on subattribute

Sorting on subattribute

Monday 16 January 2012 1:18:20 pm - 3 replies

Hi,

We have a structure where a product object always contains one, and only one, instance of a custom datatype. One instance of that datatype can be contained in zero or one product object.

We would like to sort search results by subattributes from the datatype when displaying search results - without altering schema.xml (we know that it is possible by defining special fields).

The problem is that the fieldnames of subattributes allways always is matched to a dynamic field defenition in solr with multiValued="true", and that generates a field which cannot be sorted.

Thanks!!

Monday 16 January 2012 10:06:02 pm

Hi Are,

does it have to be a subattribute? Just as you can create custom fields with "subattr_" prefix, you can also define custom fields with "attr_" prefix and those are not multivalued. To make sure the name doesn't possibly collide with other eZ Publish object attributes, you can use a prefix/suffix to ensure uniqueness, something like "attr_PREFIX_field_name_SUFFIX_si"

Infact, you don't even have to use attr_ in front of the field name. As long as the field name ends with "_SOLR_DATATYPE" suffix (where SOLR_DATATYPE is one of suffixes defined in schema.xml), you're good to go.

Tuesday 17 January 2012 8:30:56 am

Thank you for replying, Edi!

The fields themselves have to be subattributes, as they are fields in av custom datatype (loaded into custom database table by an external system).

If it is still possible to do as you suggest - to create a field name that will use a solr dynamic field without multi-valued=true, I hope you can give me a little more detail about how I can do it...

Wednesday 18 January 2012 10:32:25 am

Hi Are,

you will have to create your own indexing handler for your datatype by extending eZ Find class ezfSolrDocumentFieldBase.

You can find the examples of such classes in ezfind (for eaxample: extension/ezfind/classses/ezfsolrdocumentfieldgmaplocation.php). That class generates subattributes for Gmap Location datatype and for those subattributes calculates field names in getData method.

However, you don't have to calculate the names of the fields like this, you can just place hardcoded values into $data array, for example:

$data['my_field_for_sorting_si'] = $objectAttribute->attribute( 'some_data' );

The only thing that matters is that your custom field names end with suffixes as defined in schema.xml

<dynamicField name="*_d" type="double" indexed="true" stored="true"/>
<dynamicField name="*_si" type="sint" indexed="true" stored="true"/>
expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from