コード例 #1
0
  public TermsLongFacetExecutor(
      IndexNumericFieldData indexFieldData,
      int size,
      int shardSize,
      TermsFacet.ComparatorType comparatorType,
      boolean allTerms,
      SearchContext context,
      ImmutableSet<BytesRef> excluded,
      SearchScript script,
      CacheRecycler cacheRecycler) {
    this.indexFieldData = indexFieldData;
    this.size = size;
    this.shardSize = shardSize;
    this.comparatorType = comparatorType;
    this.script = script;
    this.excluded = excluded;
    this.facets = cacheRecycler.longIntMap(-1);

    if (allTerms) {
      for (AtomicReaderContext readerContext : context.searcher().getTopReaderContext().leaves()) {
        int maxDoc = readerContext.reader().maxDoc();
        LongValues values = indexFieldData.load(readerContext).getLongValues();
        for (int docId = 0; docId < maxDoc; docId++) {
          final int numValues = values.setDocument(docId);
          final LongIntOpenHashMap v = facets.v();
          for (int i = 0; i < numValues; i++) {
            v.putIfAbsent(values.nextValue(), 0);
          }
        }
      }
    }
  }
コード例 #2
0
    @Override
    protected String getDistanceString(LeafReaderContext ctx, int docId) {

      StringBuilder values = new StringBuilder(mode.name());
      values.append("[");
      final SortedNumericDoubleValues doubleValues = fieldData.load(ctx).getDoubleValues();
      doubleValues.setDocument(docId);
      final int num = doubleValues.count();
      if (num > 0) {
        for (int i = 0; i < num; i++) {
          double value = doubleValues.valueAt(i);
          values.append("Math.max(Math.abs(");
          values
              .append(value)
              .append("(=doc value) - ")
              .append(origin)
              .append("(=origin))) - ")
              .append(offset)
              .append("(=offset), 0)");
          if (i != num - 1) {
            values.append(", ");
          }
        }
      } else {
        values.append("0.0");
      }
      values.append("]");
      return values.toString();
    }
コード例 #3
0
  @Test
  public void testDateScripts() throws Exception {
    fillSingleValueAllSet();
    IndexNumericFieldData indexFieldData = getForField("value");
    AtomicNumericFieldData fieldData = indexFieldData.load(refreshReader());

    ScriptDocValues.Longs scriptValues = (ScriptDocValues.Longs) fieldData.getScriptValues();
    scriptValues.setNextDocId(0);
    assertThat(scriptValues.getValue(), equalTo(2l));
    assertThat(scriptValues.getDate().getMillis(), equalTo(2l));
    assertThat(scriptValues.getDate().getZone(), equalTo(DateTimeZone.UTC));
  }
コード例 #4
0
  private void test(List<TLongSet> values) throws Exception {
    StringField id = new StringField("_id", "", Field.Store.NO);

    for (int i = 0; i < values.size(); ++i) {
      Document doc = new Document();
      id.setStringValue("" + i);
      doc.add(id);
      final TLongSet v = values.get(i);
      for (TLongIterator it = v.iterator(); it.hasNext(); ) {
        LongField value = new LongField("value", it.next(), Field.Store.NO);
        doc.add(value);
      }
      writer.addDocument(doc);
    }
    writer.forceMerge(1);

    final IndexNumericFieldData indexFieldData = getForField("value");
    final AtomicNumericFieldData atomicFieldData = indexFieldData.load(refreshReader());
    final LongValues data = atomicFieldData.getLongValues();
    final DoubleValues doubleData = atomicFieldData.getDoubleValues();
    final TLongSet set = new TLongHashSet();
    final TDoubleSet doubleSet = new TDoubleHashSet();
    for (int i = 0; i < values.size(); ++i) {
      final TLongSet v = values.get(i);

      assertThat(data.hasValue(i), equalTo(!v.isEmpty()));
      assertThat(doubleData.hasValue(i), equalTo(!v.isEmpty()));

      if (v.isEmpty()) {
        assertThat(data.getValue(i), equalTo(0L));
        assertThat(doubleData.getValue(i), equalTo(0d));
      }

      set.clear();
      for (LongValues.Iter iter = data.getIter(i); iter.hasNext(); ) {
        set.add(iter.next());
      }
      assertThat(set, equalTo(v));

      final TDoubleSet doubleV = new TDoubleHashSet();
      for (TLongIterator it = v.iterator(); it.hasNext(); ) {
        doubleV.add((double) it.next());
      }
      doubleSet.clear();
      for (DoubleValues.Iter iter = doubleData.getIter(i); iter.hasNext(); ) {
        doubleSet.add(iter.next());
      }
      assertThat(doubleSet, equalTo(doubleV));
    }
  }
コード例 #5
0
  @Test
  public void testOptimizeTypeLong() throws Exception {
    Document d = new Document();
    d.add(new StringField("_id", "1", Field.Store.NO));
    d.add(new LongField("value", Integer.MAX_VALUE + 1l, Field.Store.NO));
    writer.addDocument(d);

    d = new Document();
    d.add(new StringField("_id", "2", Field.Store.NO));
    d.add(new LongField("value", Integer.MIN_VALUE - 1l, Field.Store.NO));
    writer.addDocument(d);

    IndexNumericFieldData indexFieldData =
        ifdService.getForField(new FieldMapper.Names("value"), new FieldDataType("long"));
    AtomicNumericFieldData fieldData = indexFieldData.load(refreshReader());
    assertThat(fieldData, instanceOf(PackedArrayAtomicFieldData.class));
    assertThat(fieldData.getLongValues().getValue(0), equalTo((long) Integer.MAX_VALUE + 1l));
    assertThat(fieldData.getLongValues().getValue(1), equalTo((long) Integer.MIN_VALUE - 1l));
  }
コード例 #6
0
    @Override
    protected NumericDoubleValues distance(LeafReaderContext context) {
      final SortedNumericDoubleValues doubleValues = fieldData.load(context).getDoubleValues();
      return mode.select(
          new MultiValueMode.UnsortedNumericDoubleValues() {
            @Override
            public int count() {
              return doubleValues.count();
            }

            @Override
            public void setDocument(int docId) {
              doubleValues.setDocument(docId);
            }

            @Override
            public double valueAt(int index) {
              return Math.max(0.0d, Math.abs(doubleValues.valueAt(index) - origin) - offset);
            }
          },
          0.0);
    }
 @Override
 protected void doSetNextReader(AtomicReaderContext context) throws IOException {
   keyValues = keyIndexFieldData.load(context).getLongValues();
   valueScript.setNextReader(context);
 }