Forums / Developer / How-to display "Most related contents" ?

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?

eZ debug

Timing: Jan 29 2025 23:45:14
Script start
Timing: Jan 29 2025 23:45:14
Module start 'content'
Timing: Jan 29 2025 23:45:14
Module end 'content'
Timing: Jan 29 2025 23:45:14
Script end

Main resources:

Total runtime0.2017 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 587.9531180.8281
Module start 'content' 0.00480.0072 768.781398.0391
Module end 'content' 0.01200.1896 866.8203531.8750
Script end 0.2016  1,398.6953 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00311.5235200.0002
Check MTime0.00130.6314200.0001
Mysql Total
Database connection0.00060.282110.0006
Mysqli_queries0.138268.50031410.0010
Looping result0.00110.52531390.0000
Template Total0.189393.910.1893
Template load0.00070.334610.0007
Template processing0.188693.522810.1886
Override
Cache load0.00050.240910.0005
Sytem overhead
Fetch class attribute can translate value0.00080.414510.0008
XML
Image XML parsing0.00050.246810.0005
General
dbfile0.026112.9364200.0013
String conversion0.00000.001930.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs