/** Sparse faceting: returns any dimension that had any * hits, topCount labels per dimension. */ public SortedSetDocValuesFacetCounts(SortedSetDocValuesReaderState state, FacetsCollector hits) throws IOException { this.state = state; this.field = state.getField(); dv = state.getDocValues(); counts = new int[state.getSize()]; //System.out.println("field=" + field); count(hits.getMatchingDocs()); }
@Override final protected Facets getFacets(final String dimension) throws IOException { if (sortedSetFacetField.equals(facetsConfig.getDimConfig(dimension).indexFieldName)) { if (queryContext.docValueReaderState == null) return null; if (queryContext.docValueReaderState.getOrdRange(dimension) == null) return null; } return results.facets; } }
@Override public List<FacetResult> getAllDims(int topN) throws IOException { List<FacetResult> results = new ArrayList<>(); for(Map.Entry<String,OrdRange> ent : state.getPrefixToOrdRange().entrySet()) { FacetResult fr = getDim(ent.getKey(), ent.getValue(), topN); if (fr != null) { results.add(fr); } } // Sort by highest count: Collections.sort(results, new Comparator<FacetResult>() { @Override public int compare(FacetResult a, FacetResult b) { if (a.value.intValue() > b.value.intValue()) { return -1; } else if (b.value.intValue() > a.value.intValue()) { return 1; } else { return a.dim.compareTo(b.dim); } } }); return results; } }
private void filterFacet(int docId) throws IOException { Document document = reader.document(docId); // filter using doc values (avoiding requiring stored values) if (!filter.isAccessible(document.getField(FieldNames.PATH).stringValue() + "/" + dimension)) { SortedSetDocValues docValues = state.getDocValues(); docValues.setDocument(docId); TermsEnum termsEnum = docValues.termsEnum(); long ord = docValues.nextOrd(); while (ord != SortedSetDocValues.NO_MORE_ORDS) { termsEnum.seekExact(ord); String facetDVTerm = termsEnum.term().utf8ToString(); String [] facetDVDimPaths = FacetsConfig.stringToPath(facetDVTerm); // first element is dimention name for (int i = 1; i < facetDVDimPaths.length; i++) { markInaccessbile(facetDVDimPaths[i]); } ord = docValues.nextOrd(); } } }
MixedDrillSideways(QueryExecution queryExecution) { super(queryExecution.queryContext.indexSearcher, queryExecution.facetsConfig, queryExecution.queryContext.taxonomyReader, queryExecution.queryContext.docValueReaderState, queryExecution.queryContext.executorService); this.stateIndexField = state == null ? null : state.getField(); }
/** Does all the "real work" of tallying up the counts. */ private final void countAll() throws IOException, InterruptedException { //System.out.println("ssdv count"); OrdinalMap ordinalMap; // TODO: is this right? really, we need a way to // verify that this ordinalMap "matches" the leaves in // matchingDocs... if (dv instanceof MultiDocValues.MultiSortedSetDocValues) { ordinalMap = ((MultiSortedSetDocValues) dv).mapping; } else { ordinalMap = null; } List<Future<Void>> results = new ArrayList<>(); for (LeafReaderContext context : state.getReader().leaves()) { results.add(exec.submit(new CountOneSegment(context.reader(), null, ordinalMap, context.ord))); } for (Future<Void> result : results) { try { result.get(); } catch (ExecutionException ee) { // Theoretically cause can be null; guard against that. Throwable cause = ee.getCause(); throw IOUtils.rethrowAlways(cause != null ? cause : ee); } } }
IndexReader origReader = state.getOrigReader();
private void filterFacet(int docId) throws IOException { Document document = reader.document(docId); // filter using doc values (avoiding requiring stored values) if (!filter.isAccessible(document.getField(FieldNames.PATH).stringValue() + "/" + dimension)) { SortedSetDocValues docValues = state.getDocValues(); docValues.setDocument(docId); TermsEnum termsEnum = docValues.termsEnum(); long ord = docValues.nextOrd(); while (ord != SortedSetDocValues.NO_MORE_ORDS) { termsEnum.seekExact(ord); String facetDVTerm = termsEnum.term().utf8ToString(); String [] facetDVDimPaths = FacetsConfig.stringToPath(facetDVTerm); // first element is dimention name for (int i = 1; i < facetDVDimPaths.length; i++) { markInaccessbile(facetDVDimPaths[i]); } ord = docValues.nextOrd(); } } }
IndexReader reader = state.getReader(); List<Future<Void>> results = new ArrayList<>();
/** Counts all facet dimensions across the provided hits. */ public SortedSetDocValuesFacetCounts(SortedSetDocValuesReaderState state, FacetsCollector hits) throws IOException { this.state = state; this.field = state.getField(); dv = state.getDocValues(); counts = new int[state.getSize()]; if (hits == null) { // browse only countAll(); } else { count(hits.getMatchingDocs()); } }
@Override public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException { if (topN <= 0) { throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")"); } if (path.length > 0) { throw new IllegalArgumentException("path should be 0 length"); } OrdRange ordRange = state.getOrdRange(dim); if (ordRange == null) { throw new IllegalArgumentException("dimension \"" + dim + "\" was not indexed"); } return getDim(dim, ordRange, topN); }
@Override public List<FacetResult> getAllDims(int topN) throws IOException { List<FacetResult> results = new ArrayList<>(); for(Map.Entry<String,OrdRange> ent : state.getPrefixToOrdRange().entrySet()) { FacetResult fr = getDim(ent.getKey(), ent.getValue(), topN); if (fr != null) { results.add(fr); } } // Sort by highest count: Collections.sort(results, new Comparator<FacetResult>() { @Override public int compare(FacetResult a, FacetResult b) { if (a.value.intValue() > b.value.intValue()) { return -1; } else if (b.value.intValue() > a.value.intValue()) { return 1; } else { return a.dim.compareTo(b.dim); } } }); return results; } }
/** Does all the "real work" of tallying up the counts. */ private final void count(List<MatchingDocs> matchingDocs) throws IOException { //System.out.println("ssdv count"); OrdinalMap ordinalMap; // TODO: is this right? really, we need a way to // verify that this ordinalMap "matches" the leaves in // matchingDocs... if (dv instanceof MultiDocValues.MultiSortedSetDocValues && matchingDocs.size() > 1) { ordinalMap = ((MultiSortedSetDocValues) dv).mapping; } else { ordinalMap = null; } IndexReader reader = state.getReader(); for(MatchingDocs hits : matchingDocs) { // LUCENE-5090: make sure the provided reader context "matches" // the top-level reader passed to the // SortedSetDocValuesReaderState, else cryptic // AIOOBE can happen: if (ReaderUtil.getTopLevelContext(hits.context).reader() != reader) { throw new IllegalStateException("the SortedSetDocValuesReaderState provided to this class does not match the reader being searched; you must create a new SortedSetDocValuesReaderState every time you open a new IndexReader"); } countOneSegment(ordinalMap, hits.context.reader(), hits.context.ord, hits); } }
/** Counts all facet dimensions across the provided hits. */ public ConcurrentSortedSetDocValuesFacetCounts(SortedSetDocValuesReaderState state, FacetsCollector hits, ExecutorService exec) throws IOException, InterruptedException { this.state = state; this.field = state.getField(); this.exec = exec; dv = state.getDocValues(); counts = new AtomicIntegerArray(state.getSize()); if (hits == null) { // browse only countAll(); } else { count(hits.getMatchingDocs()); } }
@Override public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException { if (topN <= 0) { throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")"); } if (path.length > 0) { throw new IllegalArgumentException("path should be 0 length"); } OrdRange ordRange = state.getOrdRange(dim); if (ordRange == null) { throw new IllegalArgumentException("dimension \"" + dim + "\" was not indexed"); } return getDim(dim, ordRange, topN); }
@Override public List<FacetResult> getAllDims(int topN) throws IOException { List<FacetResult> results = new ArrayList<>(); for(Map.Entry<String,OrdRange> ent : state.getPrefixToOrdRange().entrySet()) { FacetResult fr = getDim(ent.getKey(), ent.getValue(), topN); if (fr != null) { results.add(fr); } } // Sort by highest count: Collections.sort(results, new Comparator<FacetResult>() { @Override public int compare(FacetResult a, FacetResult b) { if (a.value.intValue() > b.value.intValue()) { return -1; } else if (b.value.intValue() > a.value.intValue()) { return 1; } else { return a.dim.compareTo(b.dim); } } }); return results; } }
/** Does all the "real work" of tallying up the counts. */ private final void countAll() throws IOException { //System.out.println("ssdv count"); OrdinalMap ordinalMap; // TODO: is this right? really, we need a way to // verify that this ordinalMap "matches" the leaves in // matchingDocs... if (dv instanceof MultiDocValues.MultiSortedSetDocValues) { ordinalMap = ((MultiSortedSetDocValues) dv).mapping; } else { ordinalMap = null; } for(LeafReaderContext context : state.getReader().leaves()) { countOneSegment(ordinalMap, context.reader(), context.ord, null); } }
@Override public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException { if (topN <= 0) { throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")"); } if (path.length > 0) { throw new IllegalArgumentException("path should be 0 length"); } OrdRange ordRange = state.getOrdRange(dim); if (ordRange == null) { throw new IllegalArgumentException("dimension \"" + dim + "\" was not indexed"); } return getDim(dim, ordRange, topN); }
@Override final protected Facets getFacets(final String dimension) throws IOException { final String indexFieldName = facetsConfig.getDimConfig(dimension).indexFieldName; if (indexFieldName == null) return null; if (indexFieldName.equals(sortedSetFacetField)) { if (queryContext.docValueReaderState != null) if (queryContext.docValueReaderState.getOrdRange(dimension) != null) return sortedSetCounts; } else { switch (indexFieldName) { case FieldDefinition.TAXONOMY_FACET_FIELD: return taxonomyCounts; case FieldDefinition.TAXONOMY_INT_ASSOC_FACET_FIELD: return intTaxonomyCounts; case FieldDefinition.TAXONOMY_FLOAT_ASSOC_FACET_FIELD: return floatTaxonomyCounts; default: break; } } return null; } }