Ignacio Renuncio <[EMAIL PROTECTED]> wrote:
> I was reading a ton of docs, including the "SearchQuery introduction"
> document but it seems to be a bit outdated.
I do not think that the 'SearchQuery introducation' is outdated, it is
merely targeted at core-programmers.
You are using the bridge interfaces, for which the Query-part was created
only recently and no good tutorial is present already for that.
> Could anybody take a quick look to it?
> Does it follow the "best practices" for MMBase?
At first sight it looks ok, but there are a few oddities.
> // Create the query to retrieve elements from the CMS repository
> NodeQuery query = cloud.createNodeQuery();
>
> // Define the object types involved in the query
> NodeManager url = cloud.getNodeManager("url");
> NodeManager tema = cloud.getNodeManager("tema");
>
> // Create the steps for the query, normal steps (Step) for the usual
> object types,
> // special steps (RelationStep.getNext) to add related object types
> through insrel.
> Step source1 = query.addStep(url);
> Step source2 = query.addRelationStep(tema).getNext();
>
> // We add the desired fields from any of the sources
> StepField campo_number = query.addField(source1,
> url.getField("number"));
> query.addField(source1, url.getField("nombre"));
> query.addField(source1, url.getField("url"));
> query.addField(source2, tema.getField("descripcion"));
Because you chose to use a NodeQuery you probably don't need to add any
fields. A NodeQuery can optionally have more steps, even with fields, but
the goal of it is to query all fields on one certain step (namely all fields
of the NodeManager which would return nodeQuery.getNodeManager()).
>
> I started creating the NodeQuery this way: NodeQuery query =
> cloud.getNodeManager("url").createNodeQuery();
>
> But soon I saw the query was tied to a given NodeManager.
Yes, even more tied then when you dou cloud.createNodeQuery(), becaue it
wraps the core's NodeSearchQuery then.
> After that, I changed it to: NodeQuery query = cloud.createNodeQuery();
Perhaps you would have prefered Query query = cloud.createQuery();
> And added different fields from different sources. At first sight I thought
> it couldn't work because I was not using ClusterNodes at all, so I printed
> each 'element.getNodeManager()' to see which NodeManager was assigned to
> that mix of fields from different sources.
>
> What I got was: 'virtualnodes_1091717316612', a really clever answer!!
That is a bit odd indeed. I am a little supried that you came this far since
I did not see any nodeQuery.setNodeStep().
> ---
>
> So, if I'm already getting multilevel info, should I use ClusterNodes?
Perhaps yes, you would simply use cloud.createQuery() and do more or less
the same as you did. Or you can use cloud.createNodeQuery, but NodeQuery are
really more for use with NodeManager#getList.
I will ellaborate a bit in the javadoc.
Michiel
--
Michiel Meeuwissen
Mediacentrum 140 H'sum
+31 (0)35 6772979
nl_NL eo_XX en_US
mihxil'
[] ()