JCR Query Usecases
1 Intro
JCR supports two query languages - JCR and XPath. A query, whether XPath or SQL, specifies a subset of nodes within a workspace, called the result set. The result set constitutes all the nodes in the workspace that meet the constraints stated in the query.2 Query Lifecycle
2.1 Query Creation and Execution
SQL// get QueryManager
QueryManager queryManager = workspace.getQueryManager();
// make SQL query
Query query = queryManager.createQuery("SELECT * FROM nt:base ", Query.SQL);
// execute query
QueryResult result = query.execute();// get QueryManager
QueryManager queryManager = workspace.getQueryManager();
// make XPath query
Query query = queryManager.createQuery("//element(*,nt:base)", Query.XPATH);
// execute query
QueryResult result = query.execute();2.2 Query Result Processing
// fetch query result QueryResult result = query.execute();
NodeIterator it = result.getNodes();
// get column names String[] columnNames = result.getColumnNames(); // get column rows RowIterator rowIterator = result.getRows(); while(rowIterator.hasNext()){ // get next row Row row = rowIterator.nextRow(); // get all values of row Value[] values = row.getValues(); }
2.3 Scoring
The result returns a score for each row in the result set. The score contains a value that indicates a rating of how well the result node matches the query. A high value means a better matching than a low value. This score can be used for ordering the result. eXo JCR Scoring is a mapping of Lucene scoring. For a more in-depth understanding, please study Lucene documentation. jcr:score counted in next way - (lucene score)*1000f. Score may be increased for specified nodes, see Index Boost Value Also, see an example Order by Score3 Query Examples
3.1 Query result settings
3.2 Type Constraints
3.3 Property Constraints
- Property Comparison
- LIKE Constraint
- Escaping in LIKE Statements
- NOT Constraint
- AND Constraint
- OR Constraint
- Property Existence Constraint
- Upper and Lower Case Constraints
- Date Property Comparison
- Node Name Constraint
- Multivalue Property Comparison
3.4 Path Constraint
3.5 Ordering specifing
3.6 Fulltext Search
- Fulltext Search by Property
- Fulltext Search by All Properties
- Find nt:file document by content of child jcr:content node
- How to set new Analyzer. Accent symblos ignoring
3.7 Indexing rules and additional features
on 05/11/2009 at 10:59