Search in sources :

Example 6 with EntityIndex

use of io.openk9.entity.manager.model.index.EntityIndex in project openk9 by smclab.

the class EntityService method search.

public List<EntityIndex> search(long tenantId, QueryBuilder queryBuilder, int from, int size) {
    SearchRequest searchRequest = new SearchRequest(tenantId + "-entity");
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.query(queryBuilder);
    searchSourceBuilder.size(from);
    searchSourceBuilder.size(size);
    searchRequest.source(searchSourceBuilder);
    try {
        SearchResponse searchResponse = _restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
        SearchHits hits = searchResponse.getHits();
        List<EntityIndex> results = new ArrayList<>(hits.getHits().length);
        for (SearchHit hit : hits.getHits()) {
            String sourceAsString = hit.getSourceAsString();
            JsonObject json = new JsonObject(sourceAsString);
            EntityIndex entityIndex = json.mapTo(EntityIndex.class);
            entityIndex.setScore(hit.getScore());
            results.add(entityIndex);
        }
        return results;
    } catch (Exception e) {
        _logger.error(e.getMessage());
    }
    return List.of();
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) SearchHit(org.elasticsearch.search.SearchHit) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) EntityIndex(io.openk9.entity.manager.model.index.EntityIndex) SearchHits(org.elasticsearch.search.SearchHits) IOException(java.io.IOException) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

EntityIndex (io.openk9.entity.manager.model.index.EntityIndex)6 EntityNameCleaner (io.openk9.entity.manager.cleaner.EntityNameCleaner)2 ArrayList (java.util.ArrayList)2 AliasedExpression (org.neo4j.cypherdsl.core.AliasedExpression)2 Node (org.neo4j.cypherdsl.core.Node)2 Property (org.neo4j.cypherdsl.core.Property)2 Statement (org.neo4j.cypherdsl.core.Statement)2 SymbolicName (org.neo4j.cypherdsl.core.SymbolicName)2 Member (com.hazelcast.cluster.Member)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 IExecutorService (com.hazelcast.core.IExecutorService)1 IMap (com.hazelcast.map.IMap)1 Predicates (com.hazelcast.query.Predicates)1 GetEntitiesCallable (io.openk9.entity.manager.action.GetEntitiesCallable)1 AssociableEntityKey (io.openk9.entity.manager.cache.model.AssociableEntityKey)1 Entity (io.openk9.entity.manager.cache.model.Entity)1 EntityKey (io.openk9.entity.manager.cache.model.EntityKey)1 EntityNameCleanerProvider (io.openk9.entity.manager.cleaner.EntityNameCleanerProvider)1 EntityGraphConfig (io.openk9.entity.manager.config.EntityGraphConfig)1