I have a scenario where I have several thousand Component Presentations published that are classified with a specific category/keyword, but the components also have Custom Metadata fields pertaining to define the top n. that will be displayed. Essentially, I need to filter a set of components based on keywords, sort them based on custom metadata and only select the top N.
I understand how to list the items and create basic filters (from the list of filter items in the API) but I need to filter on a metadata field (e.g. the three items with the latest metadata "priorityDate").
From what I'm reading I'd be expected to grab all records from the taxonomy search (using TaxonomyKeywordCriteria) and then manually (SQL executed against QueryRunner) retrieve all the components' metadata to filter/sort.
I must have missed something surely (it doesn't feel right have 1/2 API call and then in page SQL script)... and if not would the QueryRunner query be cached alongside the results of the Taxonomy Query.executeQuery()
Example code:
ItemTypeCriteria isComponent = new ItemTypeCriteria(16);
TaxonomyKeywordCriteria taxonomyKeywordCriteria = new TaxonomyKeywordCriteria(taxURI, taxKeywordURI, true);
Criteria[] allCriteria = {isComponent, isTDIPublication, isArticle, taxonomyKeywordCriteria};
AndCriteria andCriteria = CriteriaFactory.And(allCriteria);
Query query = new Query();
query.setCriteria(andCriteria);