bharath-techie commented on issue #13188:
URL: https://github.com/apache/lucene/issues/13188#issuecomment-2082180161

   Hi @jpountz ,
   Good question, if we take `StarTreeDataCube` as an example implementation of 
the above format :
   
   We will traverse the `StarTree` and `StarTreeDocValues` (dimensionDocValues 
- if needed ) during query to get the resultant docIdSet. 
   
   #### StarTreeQuery
   ```
   @Override
     public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, 
float boost)
         throws IOException {
       return new ConstantScoreWeight(this, boost) {
         @Override
         public Scorer scorer(LeafReaderContext context) throws IOException {
           StarTreeAggregatedValues starTreeValues = null;
           DocIdSetIterator result = null;
           DataCubeValues<?> dataCubVals = 
context.reader().getDataCubeValues(field);
           Object dataCubeValues = dataCubVals.getDataCubeValues();
           if (dataCubeValues != null) {
             starTreeValues = (StarTreeAggregatedValues) dataCubeValues;
             StarTreeFilter filter = new StarTreeFilter(starTreeValues, 
filterPredicateMap, groupByCols);
             // Traverse star tree and get the resultant DocIdSetIterator of 
star tree + star tree doc values
             result = filter.getStarTreeResult();
           }
           return new ConstantScoreScorer(this, score(), scoreMode, result);
         }
   
         @Override
         public boolean isCacheable(LeafReaderContext ctx) {
           return false;
         }
       };
     }
   ```
   
   And coming to `collector` changes, the collector needs to traverse the 
`StarTreeDocValues` to get the values based on the associated `DocIds`. 
   
   For example `collect` override for `sum` aggregation will look like below 
where we traverse the associated `metricDocValues`.
   
   #### SumCollector
   ```
         @Override
         public void collect(int doc)
             throws IOException {
           StarTreeAggregatedValues starAggs = null;
           docsBuilder.grow(1).add(doc);
           DataCubeValues<?> dataCubVals = 
context.reader().getDataCubeValues(field);
           Object dataCubeValues = dataCubVals.getDataCubeValues();
           if(starAggs != null) {
             StarTreeAggregatedValues val = (StarTreeAggregatedValues) starAggs;
   
             NumericDocValues dv = val.metricValues.get("status_sum");
             dv.advanceExact(doc);
   
             sum += dv.longValue();
           }
           totalHits++;
         }
   ```
   
   #### Example:
   
   ```
   private void queryWithFilter(IndexWriter w)
         throws IOException {
   
       final IndexReader reader = DirectoryReader.open(w);
       final IndexSearcher searcher = newSearcher(reader, false);
       Set<String> groupByCols = new HashSet<>();
       //groupByCols.add("day");
       Map<String, List<Predicate<Integer>>> predicateMap = new HashMap<>();
       List<Predicate<Integer>> predicates = new ArrayList<>();
       predicates.add(day -> day > 2 && day < 5);
       predicates.add(day -> day == 30);
       predicateMap.put("day", predicates);
       predicates = new ArrayList<>();
       predicates.add(status -> status == 200);
       predicateMap.put("status", predicates);
       final Query starTreeQuery = new StarTreeQuery(predicateMap, groupByCols);
   
       searcher.search(starTreeQuery, getStarTreeSumCollector());
   ```
   
   Code 
[reference](https://github.com/bharath-techie/lucene/commit/c0de03709d29991a568a27bddcf680bf2889d868#diff-a4e79e3507c88803d95fd5c9654e35c1bb0bdd72823f1300dbd6747b93e749b5)
 - This contains star tree implementation but this is old code where I've not 
integrated yet with DataCubes format etc. , I've followed `Approach 2 - Extend 
DocValues format` but the query/collect logic should remain similar.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to