How-to display "Most related contents" ?

Author Message

Mickael Robin

Monday 23 March 2009 2:58:00 am

Hi all,

I can't find a way to fetch the "most related objects" of a given content_class.

Basically, my users are invited to create "selections" ("selection" content_class is based on a object_relations attribute) to select the articles they like.

To display the 5 most selected articles within a certain period, I found 2 ways which are much beyond my developing skills :

1st way :
- fetch all articles (tree fetch)
- foreach article : fetch with "reverse_related_objects_count"
=> how can I store the count for each article, and then sort articles by count?
=> how can I restrict to a certain timeframe?

2nd way :
- fetch all selections (tree fetch)
- foreach selection
- check if selection was created within the timeframe
- get related article node_id and append it to an array
=> how can I sort the node_ids by number of repetitions in this array?

Any help would be highly appreciated :-)

Thanks in advance
Mikrob

Jan Komárek

Tuesday 24 March 2009 9:19:17 am

You can create your own extended attribute filter and fetch waht you need. But its demand some study of database structure.

This is join which enables sorting by comments count. Where ezcontentobject.contentclass_id = '13' is comments classID.

NATURAL LEFT JOIN (SELECT DISTINCT
	parent.contentobject_id AS contentobject_id,
	Count(ezcontentobject.id) AS comments
	FROM
	ezcontentobject_tree AS childTree
	Inner Join ezcontentobject_tree AS parentTree ON rodicTree.node_id = childTree.parent_node_id
	Inner Join ezcontentobject_name AS parent ON rodic.contentobject_id = parentTree.contentobject_id AND parent.content_version = parentTree.contentobject_version
	Inner Join ezcontentobject ON ezcontentobject.id = childTree.contentobject_id AND childTree.contentobject_version = ezcontentobject.current_version
	WHERE
	ezcontentobject.contentclass_id =  '13'
	GROUP BY
	rodic.name,
	rodic.contentobject_id) as comments

If you add ,comments.comments as comm_count to the columns you can sort by count of comments. This is the way to fetch most commented object...

André R.

Wednesday 25 March 2009 2:41:10 am

The sql above will most likely be very slow, I think it would make more sense to do a completely separate sql call when doing advance stuff like this, and not hook into tree / list fetch witch can already be a bit heavy on it's own.

2 examples ( fetchNodeByRating() and getRatingWhere() ):
http://svn.projects.ez.no/ezcore/trunk/ezcore/autoloads/ezrating.php

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Piotrek Karaś

Thursday 26 March 2009 9:36:28 pm

Object-relations is a very complex and multi-level datatype, and so are queries to the eZ content model. I think you should aim at providing a dedicated datatype with its own one database table as a storage. You would simply keep references from an object to an object, with creation date, user ID and other useful information. Even if you have a million article selections, this should still be possible to maintain, query, etc. You can also provide template operator or a fetch for querying it from within templates.

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Mickael Robin

Monday 30 March 2009 3:02:36 am

Thanks to the three of you for your constructive answers.

I will definitely try to adapt ezrating to my needs, and come back here to share my code...or difficulties :-)

Besides, I need to implement "if node A and node B are related" :
=> do I have to proceed the same way as above to create a "are related" operator?

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 05:15:27
Script start
Timing: Jan 18 2025 05:15:27
Module start 'layout'
Timing: Jan 18 2025 05:15:27
Module start 'content'
Timing: Jan 18 2025 05:15:27
Module end 'content'
Timing: Jan 18 2025 05:15:27
Script end

Main resources:

Total runtime0.6776 sec
Peak memory usage4,096.0000 KB
Database Queries67

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0065 587.9375152.6250
Module start 'layout' 0.00650.0024 740.562539.4453
Module start 'content' 0.00900.6673 780.0078654.3438
Module end 'content' 0.67620.0014 1,434.351616.1406
Script end 0.6776  1,450.4922 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.5191160.0002
Check MTime0.00140.2021160.0001
Mysql Total
Database connection0.00110.160910.0011
Mysqli_queries0.618591.2805670.0092
Looping result0.00070.1068650.0000
Template Total0.647295.520.3236
Template load0.00210.305520.0010
Template processing0.645195.208120.3226
Template load and register function0.00020.026310.0002
states
state_id_array0.00140.201910.0014
state_identifier_array0.00080.112020.0004
Override
Cache load0.00180.2614400.0000
Sytem overhead
Fetch class attribute can translate value0.00090.134940.0002
Fetch class attribute name0.00100.143080.0001
XML
Image XML parsing0.00170.247640.0004
class_abstraction
Instantiating content class attribute0.00000.002180.0000
General
dbfile0.00110.1671290.0000
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 27
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs