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(); }
/** 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 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); }
/** User drills down on 'Publish Year/2010'. */ private FacetResult drillDown() throws IOException { DirectoryReader indexReader = DirectoryReader.open(indexDir); IndexSearcher searcher = new IndexSearcher(indexReader); SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexReader); // Now user drills down on Publish Year/2010: DrillDownQuery q = new DrillDownQuery(config); q.add("Publish Year", "2010"); FacetsCollector fc = new FacetsCollector(); FacetsCollector.search(searcher, q, 10, fc); // Retrieve results Facets facets = new SortedSetDocValuesFacetCounts(state, fc); FacetResult result = facets.getTopChildren(10, "Author"); indexReader.close(); return result; }
/** 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 void newFieldNoStore(String fieldName, Object value, FieldConsumer consumer) { final String stringValue = getStringValue(value); if (stringValue != null) consumer.accept(genericFieldName, fieldName, new SortedSetDocValuesFacetField(fieldName, stringValue)); }
static SortedSetDocValuesReaderState getNewFacetsState(final IndexReader indexReader, final String stateFacetField) throws IOException { try { return new DefaultSortedSetDocValuesReaderState(indexReader, stateFacetField == null ? FieldDefinition.DEFAULT_SORTEDSET_FACET_FIELD : stateFacetField); } catch (IllegalArgumentException e) { if (e.getMessage().contains("was not indexed with SortedSetDocValues")) return null; throw e; } }
@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 { if (sortedSetFacetField.equals(facetsConfig.getDimConfig(dimension).indexFieldName)) { if (queryContext.docValueReaderState == null) return null; if (queryContext.docValueReaderState.getOrdRange(dimension) == null) return null; } return results.facets; } }
private FacetResult getTopChildren0(int topN, String dim, String... path) throws IOException { FacetResult topChildren = super.getTopChildren(topN, dim, path); if (topChildren == null) { return null; } InaccessibleFacetCountManager inaccessibleFacetCountManager = new InaccessibleFacetCountManager(dim, reader, filter, state, facetsCollector, topChildren.labelValues); inaccessibleFacetCountManager.filterFacets(); LabelAndValue[] labelAndValues = inaccessibleFacetCountManager.updateLabelAndValue(); int childCount = labelAndValues.length; Number value = 0; for (LabelAndValue lv : labelAndValues) { value = value.longValue() + lv.value.longValue(); } return new FacetResult(dim, path, value, labelAndValues, childCount); }
/** 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 List<FacetResult> getAllDims(int topN) throws IOException { if (docValuesFacets == null) { return taxonomyFacets == null ? null : taxonomyFacets.getAllDims(topN); } if (taxonomyFacets == null) return docValuesFacets.getAllDims(topN); final List<FacetResult> facetResultList = taxonomyFacets.getAllDims(topN); facetResultList.addAll(docValuesFacets.getAllDims(topN)); return facetResultList; } }
/** User drills down on 'Publish Year/2010'. */ private FacetResult drillDown() throws IOException { DirectoryReader indexReader = DirectoryReader.open(directory); IndexSearcher searcher = new IndexSearcher(indexReader); SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexReader); // Now user drills down on Publish Year/2010: DrillDownQuery q = new DrillDownQuery(config); q.add("Publish Year", "2010"); FacetsCollector fc = new FacetsCollector(); FacetsCollector.search(searcher, q, 10, fc); // Retrieve results Facets facets = new SortedSetDocValuesFacetCounts(state, fc); FacetResult result = facets.getTopChildren(10, "Author"); indexReader.close(); return result; }
/** 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()); } }
void textField(final String fieldName, final Object value, final FieldConsumer consumer) { consumer.accept(genericFieldName, fieldName, new SortedSetDocValuesFacetField(getTextName(fieldName), value.toString())); } }
@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; } }
private FacetResult getTopChildren0(int topN, String dim, String... path) throws IOException { FacetResult topChildren = super.getTopChildren(topN, dim, path); if (topChildren == null) { return null; } InaccessibleFacetCountManager inaccessibleFacetCountManager = new InaccessibleFacetCountManager(dim, reader, filter, state, facetsCollector, topChildren.labelValues); inaccessibleFacetCountManager.filterFacets(); LabelAndValue[] labelAndValues = inaccessibleFacetCountManager.updateLabelAndValue(); int childCount = labelAndValues.length; Number value = 0; for (LabelAndValue lv : labelAndValues) { value = value.longValue() + lv.value.longValue(); } return new FacetResult(dim, path, value, labelAndValues, childCount); }
/** 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); } }
@Override void newFieldWithStore(String fieldName, Object value, FieldConsumer consumer) { final String stringValue = getStringValue(value); if (stringValue == null) return; consumer.accept(genericFieldName, fieldName, new SortedSetDocValuesFacetField(fieldName, stringValue)); consumer.accept(genericFieldName, fieldName, new StoredField(fieldName, stringValue)); }