Hi Michael,
as an alternative you can also restrict the type of a node with an expression on
jcr:primaryType.
select * from nt:base where jcr:primaryType = 'mynt:content'
please note that the above query does not respect the node type hierarchy. that
is, it is not equivalent to:
select * from mynt:content
that latter will also return nodes with a type that inherits from mynt:content.
using jcr:primaryType you are free to select any number of nodes of a specific
type.
e.g. you can write:
select * from nt:base where (jcr:primaryType = 'mynt:content' or jcr:primaryType
= 'mynt:attachments') and contains('find this') order by jcr:score desc
regards
marcel
Michael MacFadden wrote:
Hi,
I have a question regarding searching. In my repository, I have two
different node types. One for regular typed in content and one for
attachments. Each of these node types has a node type definition loaded
and they each have different properties. What I want to do is allow the
user to enter a search term and have the content nodes and attachments
searched an provide a single list ordered by the results score. I have
the full text (text extractor) search already working and am using the
ScoreNodeIterator.
The issue I have is that since the nodes I am trying to search have two
different types it seems like I need two separate queries:
Content:
"SELECT * FROM mynt:content WHERE CONTAINS(* , '" +
queryString.toLowerCase().trim() + "') order by jcr:score DESC"
Attachments:
"SELECT * FROM mynt:attachments WHERE CONTAINS(* , '" +
queryString.toLowerCase().trim() + "') order by jcr:score DESC"
I could execute both of these queries and try to merge the results and
then sort them. The issue is that I also need to page the results,
because there could be thousands. I would either use the skip function
in the NodeIterator class or I would use the limit and offset functions
in the jackrabbit specific api. However to really do this I would need
to have a single merged result list. If I don't then I wouldn't know
where to page when making the two different queries since I would not
know how many results were coming in the other query. I would
essentially have to get all results, merge them, sort them, and then
select a subset.
This seems like the performance would be impacted for large result
sets. Is there a way to query multiple node types, my understanding is
that you can only do so if the nodes share some inherited node type, but
when you do that you can only search the properties that are in the
parent node type. This wouldn't work either since the child node types
have differing properties that need to be searched. So far the only way
I can see to do this would be to merge the definitions of my nodes into
one type and then just not use certain properties depending on which
type of node I really want. However this doesn't really seem like a
clean approach.
Any ideas would be welcome. Thanks.
~Mike