Get more content like this

Understanding JCR Query search results

Jcr query search

When you query the JCR repository using SQL2/Query Builder/XPath query, lucene handles the query in the backend. It orders the query based on a score it calculates. You can print the score using this code snippet


QueryManager qm = jcrSession.getWorkspace().getQueryManager();

String queryString = "SELECT * FROM [cq:PageContent] WHERE " …..” ;

Query query = qm.createQuery(queryString, Query.JCR_SQL2);

// execute query

QueryResult result = query.execute();

// get column names

String[] columnNames = result.getColumnNames();

// get column rows

RowIterator rowIterator = result.getRows();


// get next row

Row row = rowIterator.nextRow();

// get all values of row

Value[] values = row.getValues();

//print the values. One of the values is jcr_score


The Score is calculated using pretty complex mathematical formula. You can read more about it at

Some more explanation is provided at

Here are some main points:

  • The length of document is number of terms not number of characters
  • The relationship between frequency and length is not linear. It is sqrt(frequency/total terms in document)
  • If your search has more than one term and one of the terms is a common term in the repository, then that common word gets less weightage. For e.g. if your content is for the company Polycom, then term like ‘conference might be a common term. So, when you search for ‘VOIP Conference’, then ‘conference’ would get lower weightage.

If you would like more help optimizing or managing your JCR Query, Contact Us Today.

Learn more about how TechAspect can help you propel your digital transformation

Get In Touch