Understanding JCR Query search results

By Marketing Team 2 min read

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 http://lucene.apache.org/core/3_6_2/api…ilarity.html

Some more explanation is provided at http://www.lucenetutorial.com/advanced-t…oring.html

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.

Explore Additional Resources

Learn more on how to select the right CMS for your business and improve your customer’s Digital Experience.

Our Adobe Experience Cloud Consulting team specializes in helping you deliver a seamless, intelligent, and personalized customer experience.

About TA Digital

TA Digital is an innovative digital transformation agency, specializing in delivering the digital experience, commerce, and marketing solutions. For nearly two decades, we have been helping traditional businesses transform and create dynamic digital cultures through disruptive strategies and agile deployment of innovative solutions.

Marketing Team

Written By

Marketing Team

More Blogs by the author

Personalize Adobe CQ5 Welcome screen
Personalize Adobe CQ5 Welcome screen Marketing Team 3 min read