You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Christophe Lombart <ch...@gmail.com> on 2007/12/05 14:55:58 UTC

Searching resources

Hi all,

I'm wondering what is the best way to search resources with Sling (mainly
with MicroSling in the first time).
For example, in my current project, we have defined a resource structure
like this :

/multimedias
/multimedias/videos
/multimedias/videos/video1
/multimedias/videos/...
/multimedias/photos/ ...
/multimedias/photos/ ...
/articles
/articles/2007
/articles/2007/01
/articles/2007/01/article1
/articles/2007/01/article2
...

All multimedias and articles have a property "contributedBy".

Now I would like to search all resources which has been contributed by a
specific user.
Do I have to make a specific servlet and map it to a resource called
"/search" (which is not in the repo of course) ?
I think this kind of resolution is not yet supported. So, I'm wondering I'm
on the good way :-)  ?

br,
Christophe

Re: Searching resources

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Dec 5, 2007 6:34 PM, Felix Meschberger <fm...@gmail.com> wrote:

> ...Well, it is even simpler: use the findResources or queryResources method
> of the ResourceResolver to place your queries. You get back Resources
> for findResources and results as maps for queryResources...

Hmm...forgot about those, sorry ;-)

-Bertrand

Re: Searching resources

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

Am Mittwoch, den 05.12.2007, 18:28 +0100 schrieb Bertrand Delacretaz:
> On Dec 5, 2007 2:55 PM, Christophe Lombart <ch...@gmail.com> wrote:
> 
> > ...I'm wondering what is the best way to search resources with Sling (mainly
> > with MicroSling in the first time)....
> 
> > ...Do I have to make a specific servlet and map it to a resource called
> > "/search" (which is not in the repo of course) ?...
> 
> The easiest way is probably to create this /search node, and set its
> sling:resourceType to point to a specific script (or servlet).
> 
> Then, in the script, use
> node.getSession().getWorkspace().getQueryManager() to create your
> query, run it (based on request parameters) and get a NodeIterator.

Well, it is even simpler: use the findResources or queryResources method
of the ResourceResolver to place your queries. You get back Resources
for findResources and results as maps for queryResources. I think, this
is easier to use than going through the node and QueryManager ...

Regards
Felix



Re: Searching resources

Posted by Christophe Lombart <ch...@gmail.com>.
Sorry for the delay. I was very busy.
thanks a lot to added this.


On Dec 10, 2007 4:21 PM, Bertrand Delacretaz <bd...@apache.org> wrote:

> On Dec 5, 2007 10:45 PM, Christophe Lombart
> <ch...@gmail.com> wrote:
>
> > > Felix said:
> > > There is no SyntheticResource in microsling at the moment. But if you
> > > need it, you can simply copy it over from the Sling jcr/resource
> > > project. It is in fact rather a simple class.
> >
> > ...Ok. In the first time I will make a copy but you are right. this is
> > important to solve this issue....
>
> I needed SyntheticResource for a demo that I'm working on, so I have
> added it to microsling, see
> https://issues.apache.org/jira/browse/SLING-129
>
> Currently it's duplicated between sling/jcr and microsling, I've put
> TODOs to remind us from merging that at some point.
>
> -Bertrand
>

Re: Searching resources

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Dec 5, 2007 10:45 PM, Christophe Lombart
<ch...@gmail.com> wrote:

> > Felix said:
> > There is no SyntheticResource in microsling at the moment. But if you
> > need it, you can simply copy it over from the Sling jcr/resource
> > project. It is in fact rather a simple class.
>
> ...Ok. In the first time I will make a copy but you are right. this is
> important to solve this issue....

I needed SyntheticResource for a demo that I'm working on, so I have
added it to microsling, see
https://issues.apache.org/jira/browse/SLING-129

Currently it's duplicated between sling/jcr and microsling, I've put
TODOs to remind us from merging that at some point.

-Bertrand

Re: Searching resources

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

Am Mittwoch, den 05.12.2007, 22:45 +0100 schrieb Christophe Lombart:
> Ok. In the first time I will make a copy but you are right. this is
> important to solve this issue.
> Why not a common place to put those classes ?

Yes, this is also my thinking - but I fear this will just be a
collection of more or less unconnected classes :-) Maybe we should
really scan microsling and check for duplicates in Sling.

For example, I will certainly not copy the DefaultServlet and all there
is to it from microsling to Sling. Rather I envision this to be in its
own "DefaultServlet" project such that both microsling and Sling may
benefit from it one day.

Regards
Felix



Re: Searching resources

Posted by Christophe Lombart <ch...@gmail.com>.
On Dec 5, 2007 9:51 PM, Felix Meschberger <fm...@gmail.com> wrote:

> Hi Christophe,
>
> Am Mittwoch, den 05.12.2007, 21:37 +0100 schrieb Christophe Lombart:
> > Thanks for the info. I will make a try with those methods.
> > I would like to add a search example in the MicroSling application. What
> do
> > you think ?
>
> Sounds good. I would suggest you use the
> ResourceResolver.findResources/queryResources method to implement this.


yep !


>
>
> > > The easiest way is probably to create this /search node, and set its
> > > sling:resourceType to point to a specific script (or servlet).
> > >
> >
> > Is it possible to avoid the creation of this node in the repo ?  Is it
> not
> > possible to create a SyntheticResource in this case ? Not sure if
> > SyntheticResource is available in MicroSling.
>
> There is no SyntheticResource in microsling at the moment. But if you
> need it, you can simply copy it over from the Sling jcr/resource
> project. It is in fact rather a simple class.
>
> This gives raise to another unresolved issue: We have a series (not that
> many, though) of classes, which are shared by microsling and Sling, but
> currently these classes exist twice.
>

Ok. In the first time I will make a copy but you are right. this is
important to solve this issue.
Why not a common place to put those classes ?


> Regards
> Felix
>
>

Re: Searching resources

Posted by Felix Meschberger <fm...@gmail.com>.
Hi Christophe,

Am Mittwoch, den 05.12.2007, 21:37 +0100 schrieb Christophe Lombart:
> Thanks for the info. I will make a try with those methods.
> I would like to add a search example in the MicroSling application. What do
> you think ?

Sounds good. I would suggest you use the
ResourceResolver.findResources/queryResources method to implement this.

> > The easiest way is probably to create this /search node, and set its
> > sling:resourceType to point to a specific script (or servlet).
> >
> 
> Is it possible to avoid the creation of this node in the repo ?  Is it not
> possible to create a SyntheticResource in this case ? Not sure if
> SyntheticResource is available in MicroSling.

There is no SyntheticResource in microsling at the moment. But if you
need it, you can simply copy it over from the Sling jcr/resource
project. It is in fact rather a simple class.

This gives raise to another unresolved issue: We have a series (not that
many, though) of classes, which are shared by microsling and Sling, but
currently these classes exist twice.

Regards
Felix


Re: Searching resources

Posted by Christophe Lombart <ch...@gmail.com>.
Bertrand, Felix,

Thanks for the info. I will make a try with those methods.
I would like to add a search example in the MicroSling application. What do
you think ?


>
> The easiest way is probably to create this /search node, and set its
> sling:resourceType to point to a specific script (or servlet).
>

Is it possible to avoid the creation of this node in the repo ?  Is it not
possible to create a SyntheticResource in this case ? Not sure if
SyntheticResource is available in MicroSling.

br,
Christophe

Re: Searching resources

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Dec 5, 2007 2:55 PM, Christophe Lombart <ch...@gmail.com> wrote:

> ...I'm wondering what is the best way to search resources with Sling (mainly
> with MicroSling in the first time)....

> ...Do I have to make a specific servlet and map it to a resource called
> "/search" (which is not in the repo of course) ?...

The easiest way is probably to create this /search node, and set its
sling:resourceType to point to a specific script (or servlet).

Then, in the script, use
node.getSession().getWorkspace().getQueryManager() to create your
query, run it (based on request parameters) and get a NodeIterator.

While iterating over the results, you can use sling.include(path) to
use the (micro)sling request processing to render the nodes, or just
render them "locally" in the iteration if that's convenient.

Creating a /list/contributedBy node and requesting
/list/contributedBy/someone should also work in a similar way to
search for contributedBy="someone", by mapping /list/contributedBy to
a search script which gets the "someone" suffix from the
RequestPathInfo. That's an interesting use-case for the recent "go up
the path or not for GET requests" discussions, but I'm not sure if
that currently works.

-Bertrand