Example usage for org.apache.lucene.index SortedSetDocValues NO_MORE_ORDS

List of usage examples for org.apache.lucene.index SortedSetDocValues NO_MORE_ORDS

Introduction

In this page you can find the example usage for org.apache.lucene.index SortedSetDocValues NO_MORE_ORDS.

Prototype

long NO_MORE_ORDS

To view the source code for org.apache.lucene.index SortedSetDocValues NO_MORE_ORDS.

Click Source Link

Document

When returned by #nextOrd() it means there are no more ordinals for the document.

Usage

From source file:com.kmwllc.search.graph.GraphTermsCollector.java

private void addEdgeIdsToResult(int doc) throws IOException {
    // set the doc to pull the edges ids for.
    docTermOrds.setDocument(doc);/*from   ww w .  ja v a2 s .  c  o  m*/
    // TODO: why is this final?
    BytesRef scratch = new BytesRef();
    long ord;
    while ((ord = docTermOrds.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
        scratch = docTermOrds.lookupOrd(ord);
        // add the edge id to the collector terms.
        // TODO: how do we handle non-string type fields?
        // do i need to worry about that here?
        collectorTerms.add(scratch);
    }
}

From source file:dk.statsbiblioteket.netark.dvenabler.DVReaderTest.java

License:Apache License

private static List<String> getSortedSetDocValues(AtomicReaderContext atomContext, int docID, String field)
        throws IOException {
    SortedSetDocValues dvs = atomContext.reader().getSortedSetDocValues(field);
    if (dvs == null) {
        throw new IllegalStateException("No SortedSetDocValues for field '" + field + "'");
    }//from w  w w  .j  a  v a2s . co m
    dvs.setDocument(docID);
    List<String> values = new ArrayList<String>();
    BytesRef result = new BytesRef();
    long ord;
    while ((ord = dvs.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
        dvs.lookupOrd(ord, result);
        values.add(result.utf8ToString());
    }
    return values;
}

From source file:io.crate.expression.reference.doc.lucene.IpColumnReference.java

License:Apache License

@Override
public void setNextDocId(int docId) throws IOException {
    if (values.advanceExact(docId)) {
        long ord = values.nextOrd();
        if (values.nextOrd() != SortedSetDocValues.NO_MORE_ORDS) {
            throw new GroupByOnArrayUnsupportedException(columnName);
        }//from   w  ww.  jav  a  2s  . c o  m
        BytesRef encoded = values.lookupOrd(ord);
        value = BytesRefs.toBytesRef(DocValueFormat.IP.format(encoded));
    } else {
        value = null;
    }
}

From source file:lucene.security.index.SecureAtomicReaderTestBase.java

License:Apache License

@Test
public void testSortedSetDocValues() throws IOException {
    SecureAtomicReader secureReader = getSecureReader();
    SortedSetDocValues sortedSetDocValues = secureReader.getSortedSetDocValues("sortedset");
    {/*from  w  w w  . j  ava 2s  .c o  m*/
        BytesRef result = new BytesRef();
        int docID = 0;
        sortedSetDocValues.setDocument(docID);
        long ord = -1;
        assertTrue((ord = sortedSetDocValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS);
        sortedSetDocValues.lookupOrd(ord, result);
        assertEquals(new BytesRef(Integer.toString(docID)), result);

        assertTrue((ord = sortedSetDocValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS);
        sortedSetDocValues.lookupOrd(ord, result);
        assertEquals(new BytesRef("0" + Integer.toString(docID)), result);

        assertTrue((ord = sortedSetDocValues.nextOrd()) == SortedSetDocValues.NO_MORE_ORDS);
    }

    {
        int docID = 1;
        sortedSetDocValues.setDocument(docID);
        assertTrue(sortedSetDocValues.nextOrd() == SortedSetDocValues.NO_MORE_ORDS);
    }

    {
        BytesRef result = new BytesRef();
        int docID = 2;
        sortedSetDocValues.setDocument(docID);
        long ord = -1;
        assertTrue((ord = sortedSetDocValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS);
        sortedSetDocValues.lookupOrd(ord, result);
        assertEquals(new BytesRef("0" + Integer.toString(docID)), result);

        assertTrue((ord = sortedSetDocValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS);
        sortedSetDocValues.lookupOrd(ord, result);
        assertEquals(new BytesRef(Integer.toString(docID)), result);

        assertTrue((ord = sortedSetDocValues.nextOrd()) == SortedSetDocValues.NO_MORE_ORDS);
    }

    {
        int docID = 3;
        sortedSetDocValues.setDocument(docID);
        assertTrue(sortedSetDocValues.nextOrd() == SortedSetDocValues.NO_MORE_ORDS);
    }
}

From source file:org.alfresco.solr.transformer.DocValueDocTransformer.java

License:Open Source License

@Override
public void transform(SolrDocument doc, int docid, float score) throws IOException {
    for (String fieldName : context.getSearcher().getFieldNames()) {
        SchemaField schemaField = context.getSearcher().getSchema().getFieldOrNull(fieldName);
        if (schemaField != null) {
            if (schemaField.hasDocValues()) {
                SortedDocValues sortedDocValues = context.getSearcher().getSlowAtomicReader()
                        .getSortedDocValues(fieldName);
                if (sortedDocValues != null) {
                    int ordinal = sortedDocValues.getOrd(docid);
                    if (ordinal > -1) {
                        doc.removeFields(fieldName);
                        String alfrescoFieldName = AlfrescoSolrDataModel.getInstance()
                                .getAlfrescoPropertyFromSchemaField(fieldName);
                        doc.removeFields(alfrescoFieldName);
                        doc.addField(alfrescoFieldName, schemaField.getType().toObject(schemaField,
                                sortedDocValues.lookupOrd(ordinal)));
                    }/*  w w  w .j  a  v  a  2 s  .  co  m*/
                }

                SortedSetDocValues sortedSetDocValues = context.getSearcher().getSlowAtomicReader()
                        .getSortedSetDocValues(fieldName);
                if (sortedSetDocValues != null) {
                    ArrayList<Object> newValues = new ArrayList<Object>();
                    sortedSetDocValues.setDocument(docid);
                    long ordinal;
                    while ((ordinal = sortedSetDocValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
                        newValues.add(schemaField.getType().toObject(schemaField,
                                sortedSetDocValues.lookupOrd(ordinal)));
                    }
                    doc.removeFields(fieldName);
                    String alfrescoFieldName = AlfrescoSolrDataModel.getInstance()
                            .getAlfrescoPropertyFromSchemaField(fieldName);
                    doc.removeFields(alfrescoFieldName);
                    doc.addField(alfrescoFieldName, newValues);
                }

                BinaryDocValues binaryDocValues = context.getSearcher().getSlowAtomicReader()
                        .getBinaryDocValues(fieldName);
                if (binaryDocValues != null) {
                    doc.removeFields(fieldName);
                    String alfrescoFieldName = AlfrescoSolrDataModel.getInstance()
                            .getAlfrescoPropertyFromSchemaField(fieldName);
                    doc.removeFields(alfrescoFieldName);
                    doc.addField(alfrescoFieldName,
                            schemaField.getType().toObject(schemaField, binaryDocValues.get(docid)));
                }

                if (schemaField.getType().getNumericType() != null) {
                    NumericDocValues numericDocValues = context.getSearcher().getSlowAtomicReader()
                            .getNumericDocValues(fieldName);
                    if (numericDocValues != null) {
                        doc.removeFields(fieldName);
                        String alfrescoFieldName = AlfrescoSolrDataModel.getInstance()
                                .getAlfrescoPropertyFromSchemaField(fieldName);
                        doc.removeFields(alfrescoFieldName);
                        switch (schemaField.getType().getNumericType()) {
                        case DOUBLE:
                            doc.addField(alfrescoFieldName,
                                    Double.longBitsToDouble(numericDocValues.get(docid)));
                            break;
                        case FLOAT:
                            doc.addField(alfrescoFieldName,
                                    Float.intBitsToFloat((int) numericDocValues.get(docid)));
                            break;
                        case INT:
                            doc.addField(alfrescoFieldName, (int) numericDocValues.get(docid));
                            break;
                        case LONG:
                            doc.addField(alfrescoFieldName, numericDocValues.get(docid));
                            break;
                        }
                    }

                    SortedNumericDocValues sortedNumericDocValues = context.getSearcher().getSlowAtomicReader()
                            .getSortedNumericDocValues(fieldName);
                    if (sortedNumericDocValues != null) {
                        sortedNumericDocValues.setDocument(docid);
                        doc.removeFields(fieldName);
                        String alfrescoFieldName = AlfrescoSolrDataModel.getInstance()
                                .getAlfrescoPropertyFromSchemaField(fieldName);
                        doc.removeFields(alfrescoFieldName);
                        ArrayList<Object> newValues = new ArrayList<Object>(sortedNumericDocValues.count());
                        if (sortedNumericDocValues.count() > 0) {

                            for (int i = 0; i < sortedNumericDocValues.count(); i++) {
                                switch (schemaField.getType().getNumericType()) {
                                case DOUBLE:
                                    newValues.add(NumericUtils
                                            .sortableLongToDouble(sortedNumericDocValues.valueAt(i)));
                                    break;
                                case FLOAT:
                                    newValues.add(NumericUtils
                                            .sortableIntToFloat((int) sortedNumericDocValues.valueAt(i)));
                                    break;
                                case INT:
                                    newValues.add((int) sortedNumericDocValues.valueAt(i));
                                    break;
                                case LONG:
                                    newValues.add(sortedNumericDocValues.valueAt(i));
                                    break;

                                }
                            }
                        }
                        doc.addField(alfrescoFieldName, newValues);

                    }
                }
            }
        }
    }

}

From source file:org.apache.solr.analytics.accumulator.facet.FieldFacetAccumulator.java

License:Apache License

/**
 * Tell the FacetingAccumulator to collect the doc with the 
 * given fieldFacet and value(s).//from ww  w . j  a va 2 s  . c  o m
 */
@Override
public void collect(int doc) throws IOException {
    if (multiValued) {
        boolean exists = false;
        if (setValues != null) {
            setValues.setDocument(doc);
            int term;
            while ((term = (int) setValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
                exists = true;
                final BytesRef value = setValues.lookupOrd(term);
                parent.collectField(doc, name, parser.parse(value));
            }
        }
        if (!exists) {
            parent.collectField(doc, name, FacetingAccumulator.MISSING_VALUE);
        }
    } else {
        if (numField) {
            if (numValues != null) {
                long v = numValues.get(doc);
                if (v != 0 || numValuesBits.get(doc)) {
                    parent.collectField(doc, name, ((NumericParser) parser).parseNum(v));
                } else {
                    parent.collectField(doc, name, FacetingAccumulator.MISSING_VALUE);
                }
            } else {
                parent.collectField(doc, name, FacetingAccumulator.MISSING_VALUE);
            }
        } else {
            if (sortValues != null) {
                final int ord = sortValues.getOrd(doc);
                if (ord < 0) {
                    parent.collectField(doc, name, FacetingAccumulator.MISSING_VALUE);
                } else {
                    parent.collectField(doc, name, parser.parse(sortValues.lookupOrd(ord)));
                }
            } else {
                parent.collectField(doc, name, FacetingAccumulator.MISSING_VALUE);
            }
        }
    }
}

From source file:org.apache.solr.analytics.function.field.BooleanMultiField.java

License:Apache License

@Override
public void collect(int doc) throws IOException {
    count = 0;/*www  .  j a  va  2  s.  co  m*/
    if (docValues.advanceExact(doc)) {
        int term;
        while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
            if (count == values.length) {
                resizeValues();
            }
            values[count++] = term == trueOrd;
        }
    }
}

From source file:org.apache.solr.analytics.function.field.DoubleMultiTrieField.java

License:Apache License

@Override
public void collect(int doc) throws IOException {
    count = 0;/*w w  w .ja  v  a2 s . c  o m*/
    if (docValues.advanceExact(doc)) {
        int term;
        while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
            if (count == values.length) {
                resizeValues();
            }
            values[count++] = NumericUtils
                    .sortableLongToDouble(LegacyNumericUtils.prefixCodedToLong(docValues.lookupOrd(term)));
        }
    }
}

From source file:org.apache.solr.analytics.function.field.FloatMultiTrieField.java

License:Apache License

@Override
public void collect(int doc) throws IOException {
    count = 0;//  w ww  .  j  a  va2s. c o  m
    if (docValues.advanceExact(doc)) {
        int term;
        while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
            if (count == values.length) {
                resizeValues();
            }
            values[count++] = NumericUtils
                    .sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(docValues.lookupOrd(term)));
        }
    }
}

From source file:org.apache.solr.analytics.function.field.IntMultiTrieField.java

License:Apache License

@Override
public void collect(int doc) throws IOException {
    count = 0;/*www.  ja  v  a  2s .c  o  m*/
    if (docValues.advanceExact(doc)) {
        int term;
        while ((term = (int) docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
            if (count == values.length) {
                resizeValues();
            }
            values[count++] = LegacyNumericUtils.prefixCodedToInt(docValues.lookupOrd(term));
        }
    }
}