Example usage for org.apache.lucene.util LongValues IDENTITY

List of usage examples for org.apache.lucene.util LongValues IDENTITY

Introduction

In this page you can find the example usage for org.apache.lucene.util LongValues IDENTITY.

Prototype

LongValues IDENTITY

To view the source code for org.apache.lucene.util LongValues IDENTITY.

Click Source Link

Document

An instance that returns the provided value.

Usage

From source file:org.apache.solr.search.facet.FacetFieldProcessorByHashDV.java

License:Apache License

private void collectDocs() throws IOException {
    if (calc instanceof TermOrdCalc) { // Strings

        // TODO support SortedSetDocValues
        SortedDocValues globalDocValues = FieldUtil.getSortedDocValues(fcontext.qcontext, sf, null);
        ((TermOrdCalc) calc).lookupOrdFunction = ord -> {
            try {
                return globalDocValues.lookupOrd(ord);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }//from  ww w  .j a  v a2s. c o  m
        };

        DocSetUtil.collectSortedDocSet(fcontext.base, fcontext.searcher.getIndexReader(),
                new SimpleCollector() {
                    SortedDocValues docValues = globalDocValues; // this segment/leaf. NN
                    LongValues toGlobal = LongValues.IDENTITY; // this segment to global ordinal. NN

                    @Override
                    public boolean needsScores() {
                        return false;
                    }

                    @Override
                    protected void doSetNextReader(LeafReaderContext ctx) throws IOException {
                        setNextReaderFirstPhase(ctx);
                        if (globalDocValues instanceof MultiDocValues.MultiSortedDocValues) {
                            MultiDocValues.MultiSortedDocValues multiDocValues = (MultiDocValues.MultiSortedDocValues) globalDocValues;
                            docValues = multiDocValues.values[ctx.ord];
                            toGlobal = multiDocValues.mapping.getGlobalOrds(ctx.ord);
                        }
                    }

                    @Override
                    public void collect(int segDoc) throws IOException {
                        if (segDoc > docValues.docID()) {
                            docValues.advance(segDoc);
                        }
                        if (segDoc == docValues.docID()) {
                            long val = toGlobal.get(docValues.ordValue());
                            collectValFirstPhase(segDoc, val);
                        }
                    }
                });

    } else { // Numeric:

        // TODO support SortedNumericDocValues
        DocSetUtil.collectSortedDocSet(fcontext.base, fcontext.searcher.getIndexReader(),
                new SimpleCollector() {
                    NumericDocValues values = null; //NN

                    @Override
                    public boolean needsScores() {
                        return false;
                    }

                    @Override
                    protected void doSetNextReader(LeafReaderContext ctx) throws IOException {
                        setNextReaderFirstPhase(ctx);
                        values = DocValues.getNumeric(ctx.reader(), sf.getName());
                    }

                    @Override
                    public void collect(int segDoc) throws IOException {
                        if (segDoc > values.docID()) {
                            values.advance(segDoc);
                        }
                        if (segDoc == values.docID()) {
                            collectValFirstPhase(segDoc, values.longValue());
                        }
                    }
                });
    }
}