org.elasticsearch.search.rescore.RescoreBuilder Java Examples

The following examples show how to use org.elasticsearch.search.rescore.RescoreBuilder. 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: ShellScope.java    From elasticshell with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new <code>ShellScope</code> given the actual scope object
 * @param scope the actual scope object that depends on the engine in use
 */
ShellScope(Scope scope, ResourceRegistry resourceRegistry) {
    this.scope = scope;
    this.resourceRegistry = resourceRegistry;
    registerJavaClass(Requests.class);
    registerJavaClass(SearchSourceBuilder.class);
    registerJavaClass(QueryBuilders.class);
    registerJavaClass(FilterBuilders.class);
    registerJavaClass(SortBuilders.class);
    registerJavaClass(FacetBuilders.class);
    registerJavaClass(RescoreBuilder.class);
    registerJavaClass(SuggestBuilder.class);
    registerJavaClass(AliasAction.class);
    registerJavaClass(HttpParameters.class);
    registerJavaClass(AllocateAllocationCommand.class);
    registerJavaClass(CancelAllocationCommand.class);
    registerJavaClass(MoveAllocationCommand.class);
    registerJavaClass(ShardId.class);
}
 
Example #2
Source File: SearchSourceBuilder.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public SearchSourceBuilder addRescorer(RescoreBuilder rescoreBuilder) {
    if (rescoreBuilders == null) {
        rescoreBuilders = new ArrayList<>();
    }
    rescoreBuilders.add(rescoreBuilder);
    return this;
}
 
Example #3
Source File: ProductQueryServiceImpl.java    From elasticsearch-tutorial with MIT License 4 votes vote down vote up
@Override
public ProductSearchResult searchProducts(SearchCriteria searchCriteria)
{
    QueryBuilder queryBuilder = getQueryBuilder(searchCriteria);

    SearchRequestBuilder requestBuilder = getSearchRequestBuilder(searchCriteria.getIndexes(), 
                                                                    searchCriteria.getDocumentTypes(), 
                                                                    searchCriteria.getFrom(), 
                                                                    searchCriteria.getSize());
    requestBuilder.addFields(SearchDocumentFieldName.productQueryFields);
    
    if(searchCriteria.isRescoreOnSoldOut())
    {
        Rescorer rescorer = RescoreBuilder.queryRescorer(QueryBuilders.termQuery(SearchDocumentFieldName.SOLD_OUT.getFieldName(), false))
                                           .setQueryWeight(1.0f) //default
                                           .setRescoreQueryWeight(1.5f)
                                           ;
        requestBuilder.setRescorer(rescorer);
    }
    
    if (searchCriteria.hasFilters())
    {
        AndFilterBuilder andFilterBuilder = getFilterBuilderForSearchCriteria(searchCriteria);
        requestBuilder.setQuery(QueryBuilders.filteredQuery(queryBuilder, andFilterBuilder));
    } else
    {
        requestBuilder.setQuery(queryBuilder);
    }

    if (!searchCriteria.isNoFacets() && searchCriteria.getFacets().size() > 0)
    {
        addFacets(searchCriteria, requestBuilder);
    }

  //Add sorting
    if(searchCriteria.getSortOrder() !=null)
    {
        //First on given field
        requestBuilder.addSort(SortBuilders.fieldSort(SearchDocumentFieldName.AVAILABLE_DATE.getFieldName()).order(searchCriteria.getSortOrder()).missing("_last"));
        //then on score based
        requestBuilder.addSort(SortBuilders.scoreSort());
    }

    logger.debug("Executing following search request:" + requestBuilder.internalBuilder().toString());
    
    SearchResponse searchResponse = requestBuilder.execute().actionGet();
    
    printSearchResponseForDebug(searchResponse);
    
    return getProductSearchResults(searchResponse);
}
 
Example #4
Source File: ProductQueryServiceImpl.java    From searchanalytics-bigdata with MIT License 4 votes vote down vote up
@Override
public ProductSearchResult searchProducts(
		final SearchCriteria searchCriteria) {
	final QueryBuilder queryBuilder = getQueryBuilder(searchCriteria);
	final SearchRequestBuilder requestBuilder = getSearchRequestBuilder(
			searchCriteria.getIndexes(), searchCriteria.getDocumentTypes(),
			searchCriteria.getFrom(), searchCriteria.getSize());
	requestBuilder.addFields(SearchDocumentFieldName.productQueryFields);
	if (searchCriteria.isRescoreOnSoldOut()) {
		final Rescorer rescorer = RescoreBuilder
				.queryRescorer(
						QueryBuilders.termQuery(
								SearchDocumentFieldName.SOLD_OUT
										.getFieldName(), false))
				.setQueryWeight(1.0f) // default
				.setRescoreQueryWeight(1.5f);
		requestBuilder.setRescorer(rescorer);
	}
	if (searchCriteria.hasFilters()) {
		final AndFilterBuilder andFilterBuilder = getFilterBuilderForSearchCriteria(searchCriteria);
		requestBuilder.setQuery(QueryBuilders.filteredQuery(queryBuilder,
				andFilterBuilder));
	} else {
		requestBuilder.setQuery(queryBuilder);
	}
	if (!searchCriteria.isNoFacets()
			&& searchCriteria.getFacets().size() > 0) {
		addFacets(searchCriteria, requestBuilder);
	}
	// Add sorting
	if (searchCriteria.getSortOrder() != null) {
		// First on given field
		requestBuilder.addSort(SortBuilders
				.fieldSort(
						SearchDocumentFieldName.AVAILABLE_DATE
								.getFieldName())
				.order(searchCriteria.getSortOrder()).missing("_last"));
		// then on score based
		requestBuilder.addSort(SortBuilders.scoreSort());
	}
	logger.debug("Executing following search request:"
			+ requestBuilder.internalBuilder().toString());
	final SearchResponse searchResponse = requestBuilder.execute()
			.actionGet();
	printSearchResponseForDebug(searchResponse);
	return getProductSearchResults(searchResponse);
}
 
Example #5
Source File: SearchRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
private RescoreBuilder rescoreBuilder() {
    return sourceBuilder().rescore();
}
 
Example #6
Source File: SearchRequestBuilder.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Clears all rescorers on the builder and sets the first one.  To use multiple rescore windows use
 * {@link #addRescorer(org.elasticsearch.search.rescore.RescoreBuilder.Rescorer, int)}.
 *
 * @param rescorer rescorer configuration
 * @return this for chaining
 */
public SearchRequestBuilder setRescorer(RescoreBuilder.Rescorer rescorer) {
    sourceBuilder().clearRescorers();
    return addRescorer(rescorer);
}
 
Example #7
Source File: SearchRequestBuilder.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Clears all rescorers on the builder and sets the first one.  To use multiple rescore windows use
 * {@link #addRescorer(org.elasticsearch.search.rescore.RescoreBuilder.Rescorer, int)}.
 *
 * @param rescorer rescorer configuration
 * @param window   rescore window
 * @return this for chaining
 */
public SearchRequestBuilder setRescorer(RescoreBuilder.Rescorer rescorer, int window) {
    sourceBuilder().clearRescorers();
    return addRescorer(rescorer, window);
}
 
Example #8
Source File: SearchRequestBuilder.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Adds a new rescorer.
 *
 * @param rescorer rescorer configuration
 * @return this for chaining
 */
public SearchRequestBuilder addRescorer(RescoreBuilder.Rescorer rescorer) {
    sourceBuilder().addRescorer(new RescoreBuilder().rescorer(rescorer));
    return this;
}
 
Example #9
Source File: SearchRequestBuilder.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Adds a new rescorer.
 *
 * @param rescorer rescorer configuration
 * @param window   rescore window
 * @return this for chaining
 */
public SearchRequestBuilder addRescorer(RescoreBuilder.Rescorer rescorer, int window) {
    sourceBuilder().addRescorer(new RescoreBuilder().rescorer(rescorer).windowSize(window));
    return this;
}