9

I want to do a search in the content repository using one or more of the values as an input parameter for a multivalue property Something like: find all nodes with the primary type 'nt:unstructured' whose property 'multiprop' (multivalue property) contains both values "one" and "two".

How would the queryString passed to queryManager.createQuery should loook like?

Thank you.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
silverb77
  • 279
  • 5
  • 16

1 Answers1

15

You can treat the criteria on multi-valued properties just like other criteria. For example, the following query will find all nodes that have a value of 'white dog' on the 'someProp' property:

SELECT * FROM [nt:unstructured] WHERE someProp = 'white dog'

If the 'someProp' property has multiple values, then a node with at least one value that satisfies the criteria will be included in the results.

To find nodes that have multiple values of a multi-valued property, simply AND together multiple criteria. For example, the following query will return all nodes that have both of the specified values:

SELECT * FROM [nt:unstructured] WHERE someProp = 'white dog' 
                                  AND someProp = 'black dog'

Any of the operators will work, including 'LIKE':

SELECT * FROM [nt:unstructured] WHERE someProp LIKE '%white%'  
                                  AND someProp LIKE '%black%'

Other combinations are possible, of course.

Randall Hauch
  • 7,069
  • 31
  • 28
  • 1
    Thank you. Questions, please : which is those two solution is more performant? Or they should be identical performance wise? – silverb77 Nov 02 '11 at 07:15
  • Now, before getting the answer I tried something like someProp LIKE '%black%' and it seems rather slow...Is this because I was using LIKE instead of = ? – silverb77 Nov 02 '11 at 07:17
  • Final question please : thinking about performance, would you rather a do a "manual" search using getNode and checking the values of each propery against the input parameter or you would do JCR SQL2 SELECT? Many thanks. – silverb77 Nov 02 '11 at 07:21
  • The details regarding how comparison is done are here: http://www.day.com/specs/jcr/2.0/6_Query.html#6.7.16%20Comparison – michid Nov 03 '11 at 09:23
  • Using LIKE operator will always be slower than using an '=' operator, because it has to do a lot more work. IIRC, the leading '%' is slower than if you only have a trailing '%'. – Randall Hauch Nov 07 '11 at 13:15
  • Thank you, Randall and michid for the useful info. – silverb77 Nov 08 '11 at 07:26