protected void verifyFilter(String geoFileName, int maxDocs) throws IOException {
    MappedFieldNameFilterConverter fieldNameConverter =
        buildFieldNameConverter(geoFileName, maxDocs);

    // Verify mapping is correct
    List<String> filterFields = fieldNameConverter.getFields(LOCATION_BIT_MASK);
    assertEquals("Expected a single field that maps to the bit mask", 1, filterFields.size());
    assertEquals(LOCATION_FIELD, filterFields.get(0));

    filterFields = fieldNameConverter.getFields(IMAGE_LOCATION_BIT_MASK);
    assertEquals("Expected a single field that maps to the bit mask", 1, filterFields.size());
    assertEquals(IMAGE_LOCATION_FIELD, filterFields.get(0));

    // verify that half the documents have one filter and the other half have the other
    int countImageLocationFiltered = 0;
    int countLocationFiltered = 0;

    GeoSegmentReader<CartesianGeoRecord> reader =
        new GeoSegmentReader<CartesianGeoRecord>(
            directory, geoFileName, maxDocs, 1024, geoRecordSerializer, geoComparator);
    Iterator<CartesianGeoRecord> geoIter =
        reader.getIterator(
            CartesianGeoRecord.MIN_VALID_GEORECORD, CartesianGeoRecord.MAX_VALID_GEORECORD);
    while (geoIter.hasNext()) {
      CartesianGeoRecord geoRecord = geoIter.next();
      if (fieldNameConverter.fieldIsInFilter(LOCATION_FIELD, geoRecord.filterByte)) {
        countLocationFiltered++;
      }

      if (fieldNameConverter.fieldIsInFilter(IMAGE_LOCATION_FIELD, geoRecord.filterByte)) {
        countImageLocationFiltered++;
      }
    }

    assertEquals(
        "Expected one point per doc to be filtered by default location",
        maxDocs,
        countLocationFiltered);
    assertEquals(
        "Expected one point per doc to be filtered by image location",
        maxDocs,
        countImageLocationFiltered);
  }
Esempio n. 2
0
  private void loadCurrentIndex() throws IOException {
    inMemoryIndex.clear();

    GeoSegmentReader<IDGeoRecord> currentIndex = getGeoSegmentReader();
    try {
      Iterator<IDGeoRecord> currentIndexIterator =
          currentIndex.getIterator(
              IDGeoRecord.MIN_VALID_GEORECORD, IDGeoRecord.MAX_VALID_GEORECORD);

      while (currentIndexIterator.hasNext()) {
        IDGeoRecord geoRecord = currentIndexIterator.next();

        if (!removedRecords.contains(geoRecord.id)) {
          inMemoryIndex.add(geoRecord);
        }
      }
    } finally {
      currentIndex.close();
    }
  }