Package org.apache.lucene.index

Examples of org.apache.lucene.index.NumericDocValues


    this.ascending = ascending;
  }

  @Override
  public Sorter.DocMap sort(final AtomicReader reader) throws IOException {
    final NumericDocValues ndv = reader.getNumericDocValues(fieldName);
    final DocComparator comparator;
    if (ascending) {
      comparator = new DocComparator() {
        @Override
        public int compare(int docID1, int docID2) {
          final long v1 = ndv.get(docID1);
          final long v2 = ndv.get(docID2);
          return v1 < v2 ? -1 : v1 == v2 ? 0 : 1;
        }
      };
    } else {
      comparator = new DocComparator() {
        @Override
        public int compare(int docID1, int docID2) {
          final long v1 = ndv.get(docID1);
          final long v2 = ndv.get(docID2);
          return v1 > v2 ? -1 : v1 == v2 ? 0 : 1;
        }
      };
    }
    return sort(reader.maxDoc(), comparator);
View Full Code Here


    @Override
    public NumericDocValues getNumeric(FieldInfo field) throws IOException {
      assert field.getDocValuesType() == FieldInfo.DocValuesType.NUMERIC ||
             field.getNormType() == FieldInfo.DocValuesType.NUMERIC;
      NumericDocValues values = in.getNumeric(field);
      assert values != null;
      return new AssertingAtomicReader.AssertingNumericDocValues(values, maxDoc);
    }
View Full Code Here

    }
  }

  @Override
  public synchronized NumericDocValues getNumeric(FieldInfo field) throws IOException {
    NumericDocValues instance = numericInstances.get(field.number);
    if (instance == null) {
      instance = loadNumeric(field);
      numericInstances.put(field.number, instance);
    }
    return instance;
View Full Code Here

    }
  }
 
  @Override
  public NumericDocValues getNormValues(String field) throws IOException {
    final NumericDocValues norm = in.getNormValues(field);
    if (norm == null) {
      return null;
    } else {
      return new SortingNumericDocValues(norm, docMap);
    }
View Full Code Here

    }
  }

  @Override
  public NumericDocValues getNumericDocValues(String field) throws IOException {
    final NumericDocValues oldDocValues = in.getNumericDocValues(field);
    if (oldDocValues == null) return null;
    return new SortingNumericDocValues(oldDocValues, docMap);
  }
View Full Code Here

    // Iterate through the results:
    for (int i = 0; i < hits.scoreDocs.length; i++) {
      Document hitDoc = isearcher.doc(hits.scoreDocs[i].doc);
      assertEquals(text, hitDoc.get("fieldname"));
      assert ireader.leaves().size() == 1;
      NumericDocValues dv = ireader.leaves().get(0).reader().getNumericDocValues("dv1");
      assertEquals(5, dv.get(hits.scoreDocs[i].doc));
      BinaryDocValues dv2 = ireader.leaves().get(0).reader().getBinaryDocValues("dv2");
      dv2.get(hits.scoreDocs[i].doc, scratch);
      assertEquals(new BytesRef("hello world"), scratch);
    }
View Full Code Here

    final AtomicReader reader = getOnlySegmentReader(indexReader);
    final Filter parentsFilter = new FixedBitSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("parent", "true"))));
    final FixedBitSet parentBits = (FixedBitSet) parentsFilter.getDocIdSet(reader.getContext(), null);

    final NumericDocValues parentValues = reader.getNumericDocValues("parent_val");
    final Sorter.DocComparator parentComparator = new Sorter.DocComparator() {
      @Override
      public int compare(int docID1, int docID2) {
        assertTrue(parentBits.get(docID1));
        assertTrue(parentBits.get(docID2));
        final long v1 = parentValues.get(docID1);
        final long v2 = parentValues.get(docID2);
        return v1 < v2 ? -1 : v1 == v2 ? 0 : 1;
      }
    };

    final NumericDocValues childValues = reader.getNumericDocValues("child_val");
    final Sorter.DocComparator childComparator = new Sorter.DocComparator() {
      @Override
      public int compare(int docID1, int docID2) {
        assertFalse(parentBits.get(docID1));
        assertFalse(parentBits.get(docID2));
        final long v1 = childValues.get(docID1);
        final long v2 = childValues.get(docID2);
        return v1 < v2 ? -1 : v1 == v2 ? 0 : 1;
      }
    };

    final Sorter sorter = new BlockJoinSorter(parentsFilter) {
     
      @Override
      public String getID() {
        return "Dummy";
      }
     
      @Override
      protected DocComparator getParentComparator(AtomicReader r) {
        assertEquals(reader, r);
        return parentComparator;
      }

      @Override
      protected DocComparator getChildComparator(AtomicReader r) {
        assertEquals(reader, r);
        return childComparator;
      }

    };
    final Sorter.DocMap docMap = sorter.sort(reader);
    assertEquals(reader.maxDoc(), docMap.size());

    int[] children = new int[1];
    int numChildren = 0;
    int previousParent = -1;
    for (int i = 0; i < docMap.size(); ++i) {
      final int oldID = docMap.newToOld(i);
      if (parentBits.get(oldID)) {
        // check that we have the right children
        for (int j = 0; j < numChildren; ++j) {
          assertEquals(oldID, parentBits.nextSetBit(children[j]));
        }
        // check that children are sorted
        for (int j = 1; j < numChildren; ++j) {
          final int doc1 = children[j-1];
          final int doc2 = children[j];
          if (childValues.get(doc1) == childValues.get(doc2)) {
            assertTrue(doc1 < doc2); // sort is stable
          } else {
            assertTrue(childValues.get(doc1) < childValues.get(doc2));
          }
        }
        // check that parents are sorted
        if (previousParent != -1) {
          if (parentValues.get(previousParent) == parentValues.get(oldID)) {
View Full Code Here

      //long t1 = System.nanoTime();
      w.rollback();

      final int maxDoc = r.maxDoc();

      final NumericDocValues weights = r.getNumericDocValues("weight");

      final Sorter.DocComparator comparator = new Sorter.DocComparator() {
          @Override
          public int compare(int docID1, int docID2) {
            final long v1 = weights.get(docID1);
            final long v2 = weights.get(docID2);
            // Reverse sort (highest weight first);
            // java7 only:
            //return Long.compare(v2, v1);
            if (v1 > v2) {
              return -1;
View Full Code Here

    dir2.close();
    super.tearDown();
  }

  private static void assertSorted(AtomicReader reader) throws IOException {
    final NumericDocValues ndv = reader.getNumericDocValues("ndv");
    for (int i = 1; i < reader.maxDoc(); ++i) {
      assertTrue("ndv(" + (i-1) + ")=" + ndv.get(i-1) + ",ndv(" + i + ")=" + ndv.get(i), ndv.get(i-1) <= ndv.get(i));
    }
  }
View Full Code Here

    }
  }
 
  @Test
  public void testNormValues() throws Exception {
    NumericDocValues dv = reader.getNormValues(NORMS_FIELD);
    int maxDoc = reader.maxDoc();
    for (int i = 0; i < maxDoc; i++) {
      assertEquals("incorrect norm value for doc " + i, sortedValues[i].intValue(), dv.get(i));
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.NumericDocValues

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.