Commit b57ffbae authored by shiyu's avatar shiyu

提示词补全

parent 0a01f627
......@@ -6,10 +6,12 @@ import co.elastic.clients.elasticsearch._types.query_dsl.*;
import co.elastic.clients.elasticsearch.core.*;
import co.elastic.clients.elasticsearch.core.bulk.BulkOperation;
import co.elastic.clients.elasticsearch.core.bulk.CreateOperation;
import co.elastic.clients.elasticsearch.core.search.FieldCollapse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.wwdz.ch.db.bean.EsPageInfo;
import com.wwdz.ch.db.bean.ItemOfEs;
import com.wwdz.ch.db.domain.Item;
import com.wwdz.ch.db.dto.request.CoinRequestDto;
import com.wwdz.ch.db.dto.request.EsSearchRequestDto;
import com.xxdxxs.utils.DateUtils;
import com.xxdxxs.utils.EntityMapper;
......@@ -121,7 +123,6 @@ public class ItemEsDao {
long total = searchResponse.hits().total().value();
logger.info("总数据量 : {}", total);
List<Hit<ItemOfEs>> hitList = searchResponse.hits().hits();
logger.info("====== getResponse : {}", searchResponse);
List<Long> idList = new ArrayList<>();
for (Hit<ItemOfEs> itemOfEsHit : hitList) {
ItemOfEs itemOfEs = itemOfEsHit.source();
......@@ -243,5 +244,28 @@ public class ItemEsDao {
return null;
}
public List<ItemOfEs> getCuewords(EsSearchRequestDto esSearchRequestDto) {
List<ItemOfEs> itemOfEsList = new ArrayList<>();
try {
SearchRequest.Builder builder = new SearchRequest.Builder();
Query query = QueryBuilders.matchPhrasePrefix(q -> q.field("name").query(esSearchRequestDto.getContent()));
builder.source(sourceBuild->sourceBuild.filter(f->f.includes("id", "name")));
builder.collapse(c->c.field("name.keyword"));
builder.query(query);
builder.size(esSearchRequestDto.getSize());
SearchRequest searchRequest = builder.build();
logger.info("提示词查询语句 : {}", searchRequest.toString());
SearchResponse<ItemOfEs> searchResponse = elasticsearchClient.search(searchRequest, ItemOfEs.class);
long total = searchResponse.hits().total().value();
logger.info("总数据量 : {}", total);
List<Hit<ItemOfEs>> hitList = searchResponse.hits().hits();
for (Hit<ItemOfEs> itemOfEsHit : hitList) {
ItemOfEs itemOfEs = itemOfEsHit.source();
itemOfEsList.add(itemOfEs);
}
} catch (Exception e) {
logger.error("提示词查询 出错 :{}", e);
}
return itemOfEsList;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment