org.elasticsearch.index.query.MoreLikeThisQueryBuilder Java Examples

The following examples show how to use org.elasticsearch.index.query.MoreLikeThisQueryBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItemServiceImpl.java    From poseidon with Apache License 2.0 6 votes vote down vote up
@Override
public Page<EsItem> recommend(List<String> itemIds, int page, int size) {
	Pageable pageable = PageRequest.of(page, size);
	String[] itemCatNames;
	if (itemIds.size() != 0) {
		List<EsItem> esItems = itemRepository.findByItemIdIn(itemIds);
		itemCatNames = esItems.stream().map(EsItem::getItemCatName).toArray(String[]::new);
	}
	else {
		itemCatNames = new String[] { "手机" };
	}
	System.out.println(Arrays.toString(itemCatNames));
	MoreLikeThisQueryBuilder moreLikeThisQueryBuilder = QueryBuilders
			.moreLikeThisQuery(new String[] { "itemCatName" }, itemCatNames, null).minTermFreq(1);
	NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
	nativeSearchQueryBuilder.withQuery(moreLikeThisQueryBuilder).withPageable(pageable)
			.withSort(SortBuilders.fieldSort("sale").order(SortOrder.DESC));
	NativeSearchQuery query = nativeSearchQueryBuilder.build();
	// return elasticsearchTemplate.queryForPage(query, EsItem.class);
	return itemRepository.search(query);
}
 
Example #2
Source File: ElasticClient.java    From Stargraph with MIT License 4 votes vote down vote up
public MoreLikeThisQueryBuilder.Item buildMLTItem(String id) {
    return new MoreLikeThisQueryBuilder.Item(getIndexName(), getIndexType(), id);
}
 
Example #3
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 4 votes vote down vote up
protected MoreLikeThisQueryBuilder regMoreLikeThisQueryQ(String name, String[] likeTexts) {
    MoreLikeThisQueryBuilder moreLikeThisQuery = QueryBuilders.moreLikeThisQuery(new String[] { name }, likeTexts, null);
    regQ(moreLikeThisQuery);
    return moreLikeThisQuery;
}
 
Example #4
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 4 votes vote down vote up
protected MoreLikeThisQueryBuilder regMoreLikeThisQueryQ(String name, String[] likeTexts) {
    MoreLikeThisQueryBuilder moreLikeThisQuery = QueryBuilders.moreLikeThisQuery(new String[] { name }, likeTexts, null);
    regQ(moreLikeThisQuery);
    return moreLikeThisQuery;
}
 
Example #5
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 4 votes vote down vote up
protected MoreLikeThisQueryBuilder regMoreLikeThisQueryQ(String name, String[] likeTexts) {
    MoreLikeThisQueryBuilder moreLikeThisQuery = QueryBuilders.moreLikeThisQuery(new String[] { name }, likeTexts, null);
    regQ(moreLikeThisQuery);
    return moreLikeThisQuery;
}