Search in sources :

Example 1 with QueryInstance

use of com.shencangsheng.view.query.model.QueryInstance in project View-Elasticsearch by shencangsheng.

the class QueryTest method main.

public static void main(String[] args) throws Exception {
    FileReader templateJson = new FileReader("template.json");
    String queryJson = templateJson.readString();
    ObjectMapper objectMapper = new ObjectMapper();
    List<QueryInstance> queryInstances = objectMapper.readValue(queryJson, new TypeReference<>() {
    });
    BoolQueryBuilder boolQueryBuilder = BoolQueryBuilderFactory.boolQueryBuilderFactory(queryInstances, new TemplateModuleInstance());
    System.out.println(boolQueryBuilder);
}
Also used : QueryInstance(com.shencangsheng.view.query.model.QueryInstance) TemplateModuleInstance(com.shencangsheng.view.module.TemplateModuleInstance) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FileReader(cn.hutool.core.io.file.FileReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with QueryInstance

use of com.shencangsheng.view.query.model.QueryInstance in project View-Elasticsearch by shencangsheng.

the class QueryModuleDeserializer method deserialize.

@Override
public QueryInstance deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    QueryInstance queryInstance = new QueryInstance();
    JsonNode node = p.getCodec().readTree(p);
    String module = node.get("module").asText();
    AbstractModuleInstance moduleInstance = ReflectUtil.newInstance(queryInstance.getClass().getAnnotation(ModuleInstanceAnnotation.class).moduleInstance());
    AbstractPropertyInstance propertyInstance = moduleInstance.getModule(module);
    Map<String, PropertyInstance> properties = propertyInstance.getProperties();
    JsonNode query = node.get("query");
    List<SuperQuery> superQueries = Lists.newArrayListWithCapacity(query.size());
    for (JsonNode element : query) {
        String key = element.get("key").asText();
        PropertyInstance property = properties.get(key);
        ((ObjectNode) element).putPOJO("property", property);
        superQueries.add(ctxt.readTreeAsValue(element, SuperQuery.class));
    }
    queryInstance.setModule(module);
    queryInstance.setQuery(superQueries);
    return queryInstance;
}
Also used : QueryInstance(com.shencangsheng.view.query.model.QueryInstance) AbstractPropertyInstance(com.shencangsheng.view.mappings.AbstractPropertyInstance) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SuperQuery(com.shencangsheng.view.query.model.SuperQuery) JsonNode(com.fasterxml.jackson.databind.JsonNode) PropertyInstance(com.shencangsheng.view.mappings.PropertyInstance) AbstractPropertyInstance(com.shencangsheng.view.mappings.AbstractPropertyInstance) AbstractModuleInstance(com.shencangsheng.view.module.AbstractModuleInstance)

Aggregations

QueryInstance (com.shencangsheng.view.query.model.QueryInstance)2 FileReader (cn.hutool.core.io.file.FileReader)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 AbstractPropertyInstance (com.shencangsheng.view.mappings.AbstractPropertyInstance)1 PropertyInstance (com.shencangsheng.view.mappings.PropertyInstance)1 AbstractModuleInstance (com.shencangsheng.view.module.AbstractModuleInstance)1 TemplateModuleInstance (com.shencangsheng.view.module.TemplateModuleInstance)1 SuperQuery (com.shencangsheng.view.query.model.SuperQuery)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1