Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Get name of matching property from QueryResult?

Avatar

Level 5

I'm wondering if it's possible at all to determine which property a Query's match was found on, not just which Node?

Looked around for an answer first and only found this link[1] from kalyanar in this thread[2].

Following that, the following code will run a fulltext query for the word "break":

// make SQL query QueryManager queryManager = workspace.getQueryManager(); // we want find 'document1' String xpathStatement = "//element(*,mix:title)[jcr:contains(.,'break')]"; // create query Query query = queryManager.createQuery(xpathStatement, Query.XPATH); // execute query and fetch result QueryResult result = query.execute(); // Nodes NodeIterator it = result.getNodes(); while(it.hasNext()) { Node findedNode = it.nextNode(); // can get all properties from here, but not sure which one matched the query... } // Table String[] columnNames = result.getColumnNames(); RowIterator rit = result.getRows(); while (rit.hasNext()) { Row row = rit.nextRow(); // get values of the row Value[] values = row.getValues(); // can check each value here, but again, not sure which one matched the query... }

... but as you can see in each result iterator above, don't know if it's possible to determine which property name a match was found on.

[1] https://docs.jboss.org/exojcr/1.12.13-GA/developer/en-US/html/ch-jcr-query-usecases.html
[2] http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

1 Accepted Solution

Avatar

Correct answer by
Level 10

What about iterating through each node prop and reading the value and looking for a match.  This seems to be the only way i can see.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

What about iterating through each node prop and reading the value and looking for a match.  This seems to be the only way i can see.

Avatar

Level 5

Thinking I'll just make the fields to search through a configurable array and then use that instead. I was really hoping that the QueryResult object would at least have retained a reference to which property the query was matched on. That sort of thing could be rather useful (at least in my particular case) when programmatically handling these results.

Thanks anyways, Scott!