[ https://issues.apache.org/jira/browse/LUCENE-9444?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17189618#comment-17189618 ]
Ankur edited comment on LUCENE-9444 at 9/2/20, 6:27 PM: -------------------------------------------------------- Here is a patch that adds a new utility class {code:java} {code} _TaxonomyFacetLabels_with a single method {code:java} getFacetLabelReader(LeafReaderContext){code} that returns an instance of nested class {code:java} FacetLabelReader{code} It uses an instance of {code:java} OrdinalsSegmentReader{code} to fetch and decode ordinals for the input docid into a reusable buffer and returns an {code:java} Iterator{code} that uses {code:java} TaxonomyReader{code} to lookup {code:java} FacetLabels{code} for each ordinal. The patch also adds a new test case {code:java} TestTaxonomyLabels{code} demonstrating the usage. was (Author: goankur): Here is a patch that adds a new utility class - `TaxonomyFacetLabels` with the method - `getFacetLabelReader(LeafReaderContext)` that returns an instance of nested class - `FacetLabelReader`. `FacetLabelReader` uses an instance of `OrdinalsSegmentReader` to fetch and decode ordinals for the input docid into a reusable buffer and returns an `Iterator` that uses `TaxonomyReader` instance to lookup `FacetLabels`. The patch also adds a new test case `TestTaxonomyLabels` demonstrating the usage. > Need an API to easily fetch facet labels for a field in a document > ------------------------------------------------------------------ > > Key: LUCENE-9444 > URL: https://issues.apache.org/jira/browse/LUCENE-9444 > Project: Lucene - Core > Issue Type: Improvement > Components: modules/facet > Affects Versions: 8.6 > Reporter: Ankur > Priority: Major > Labels: facet > Attachments: LUCENE-9444.patch > > > A facet field may be included in the list of fields whose values are to be > returned for each hit. > In order to get the facet labels for each hit we need to > # Create an instance of _DocValuesOrdinalsReader_ and invoke > _getReader(LeafReaderContext context)_ method to obtain an instance of > _OrdinalsSegmentReader()_ > # _OrdinalsSegmentReader.get(int docID, IntsRef ordinals)_ method is then > used to fetch and decode the binary payload in the document's BinaryDocValues > field. This provides the ordinals that refer to facet labels in the > taxonomy.** > # Lastly TaxonomyReader.getPath(ord) is used to fetch the labels to be > returned. > > Ideally there should be a simple API - *String[] getLabels(docId)* that hides > all the above details and gives us the string labels. This can be part of > *TaxonomyFacets* but that's just one idea. > I am opening this issue to get community feedback and suggestions. > -- This message was sent by Atlassian Jira (v8.3.4#803005) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org