blob: 7df98fdd093504918f3bfa909ffdbc53103083f6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.querytransform;
import java.util.List;
import com.yahoo.component.chain.dependencies.After;
import com.yahoo.component.chain.dependencies.Before;
import com.yahoo.search.Searcher;
import com.yahoo.search.query.Sorting.FieldOrder;
import com.yahoo.search.searchchain.Execution;
/**
* Avoid doing relevance calculations if sorting only
* on attributes.
*
* @author Steinar Knutsen
*/
@After("rawQuery")
@Before("transformedQuery")
public class NoRankingSearcher extends Searcher {
private static final String RANK = "[rank]";
private static final String UNRANKED = "unranked";
@Override
public com.yahoo.search.Result search(com.yahoo.search.Query query, Execution execution) {
List<FieldOrder> s = (query.getRanking().getSorting() != null) ? query.getRanking().getSorting().fieldOrders() : null;
if (s == null) {
return execution.search(query);
}
for (FieldOrder f : s) {
if (RANK.equals(f.getFieldName())) {
return execution.search(query);
}
}
query.getRanking().setProfile(UNRANKED);
return execution.search(query);
}
}
|