nithya balan

Greenhorn
+ Follow
since Nov 03, 2024
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by nithya balan

I am using lucene 9.12 for my project I want to do facet with facet criteria and time range query
I refer many sites and check many combinations but all won't help me on this. Anyone please suggest to achieve facet count with facet and time criteria.

Here I have attached my sample code
public void dotestSearch(IndexReader reader){
System.out.println("NewFacetingImpl:: dotestSearch");
       try
       {
FacetsConfig facetsConfig = new FacetsConfig();
IndexSearcher searcher = new IndexSearcher(reader);
               Query timeRangeQuery = LongPoint.newRangeQuery("timestamp",startDate,endDate);
DrillDownQuery drillDownQuery = new DrillDownQuery(facetsConfig);
drillDownQuery.add("category", "electronics");
drillDownQuery.add("timestamp", timeRangeQuery);
System.out.println("facet Query:: "+drillDownQuery);

// Create a DefaultSortedSetDocValuesReaderState for the "category" facet
       SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader);

// Collect facets from the matching documents
        FacetsCollector facetsCollector = new FacetsCollector();
        FacetsCollector.search(searcher, drillDownQuery, 10, facetsCollector);

        SortedSetDocValuesFacetCounts srcFacetCounts = new SortedSetDocValuesFacetCounts(state, facetsCollector);

        // Get the facet results for the brand field
//Facets facets = new SortedSetDocValuesFacetCounts(state, facetsCollector);
        FacetResult result = srcFacetCounts.getTopChildren(10, "brand");


       System.out.println(" facet counts for dst facet");
        if (result != null) {
            for (LabelAndValue lv : result.labelValues) {
               System.out.println(lv.label + ": " + lv.value);
            }
        } else {
            System.out.println("No results found.");
        }

}
       catch(Exception e)
       {
           e.printStackTrace();
       }
  }

thanks inadvance!