
com.scaleset.search.mongo.SimpleSchemaMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scaleset-search-mongo Show documentation
Show all versions of scaleset-search-mongo Show documentation
Java object model for representing query requests in REST protocols.
The newest version!
package com.scaleset.search.mongo;
import com.scaleset.utils.Coerce;
import org.apache.lucene.util.BytesRef;
import java.util.*;
public class SimpleSchemaMapper implements SchemaMapper {
private String defaultField;
private Map> aliases = new HashMap<>();
private Map> simpleSchema = new HashMap<>();
public SimpleSchemaMapper(String defaultField) {
this.defaultField = defaultField;
}
@Override
public String defaultField() {
return defaultField;
}
@Override
public List mapField(String field) {
List result = aliases.get(field);
if (result == null || result.isEmpty()) {
result = Collections.singletonList(field);
}
return result;
}
@Override
public Object mapValue(String field, Object value) {
Class> type = simpleSchema.get(field);
if (type == null) {
type = String.class;
}
if (value instanceof BytesRef) {
value = ((BytesRef) value).utf8ToString();
}
return Coerce.to(value, type);
}
public SimpleSchemaMapper withMapping(String field, Class> type) {
simpleSchema.put(field, type);
return this;
}
public SimpleSchemaMapper withAlias(String field, String... fields) {
aliases.put(field, Arrays.asList(fields));
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy