/** {@inheritDoc} */
 @Override
 @SuppressWarnings("unchecked")
 public final Query query(Schema schema) {
   Mapper mapper = schema.getMapper(field);
   if (mapper == null) {
     throw new IndexException("No mapper found for field '%s'", field);
   } else if (!SingleColumnMapper.class.isAssignableFrom(mapper.getClass())) {
     throw new IndexException(
         "Field '%s' requires a mapper of type '%s' but found '%s'",
         field, SingleColumnMapper.class.getSimpleName(), mapper);
   }
   return query((SingleColumnMapper<?>) mapper, schema.getAnalyzer());
 }
  @Test
  public void testSortField() {

    Mapper mapper = new StringMapper("field", null, null, null);

    Schema schema = mock(Schema.class);
    when(schema.getAnalyzer()).thenReturn(PreBuiltAnalyzers.DEFAULT.get());
    when(schema.getMapper("field")).thenReturn(mapper);

    SortField sortField = new SortField("field", true);
    org.apache.lucene.search.SortField luceneSortField = sortField.sortField(schema);

    assertNotNull(luceneSortField);
    assertEquals(org.apache.lucene.search.SortField.class, luceneSortField.getClass());
  }
  /** {@inheritDoc} */
  @Override
  public Query query(Schema schema) {

    Mapper mapper = schema.getMapper(field);
    if (!(mapper instanceof GeoPointMapper)) {
      throw new IllegalArgumentException("Geo point mapper required");
    }
    GeoPointMapper geoPointMapper = (GeoPointMapper) mapper;
    SpatialStrategy spatialStrategy = geoPointMapper.getStrategy();

    BooleanQuery query = new BooleanQuery();
    query.add(query(maxGeoDistance, spatialStrategy), BooleanClause.Occur.MUST);
    if (minGeoDistance != null) {
      query.add(query(minGeoDistance, spatialStrategy), BooleanClause.Occur.MUST_NOT);
    }
    query.setBoost(boost);
    return query;
  }
  @Test
  public void testComparatorNatural() {

    Schema schema = mock(Schema.class);
    when(schema.getAnalyzer()).thenReturn(PreBuiltAnalyzers.DEFAULT.get());
    when(schema.getMapper("field")).thenReturn(new StringMapper("field", null, null, null));

    SortField sortField = new SortField("field", false);
    Comparator<Columns> comparator = sortField.comparator();

    Column<String> lowerColumn = Column.fromComposed("field", "a", UTF8Type.instance, false);
    Column<String> upperColumn = Column.fromComposed("field", "z", UTF8Type.instance, false);
    Columns columns1 = new Columns().add(lowerColumn);
    Columns columns2 = new Columns().add(upperColumn);

    assertEquals(-25, comparator.compare(columns1, columns2));
    assertEquals(0, comparator.compare(columns1, columns1));
  }