diff --git a/build.gradle b/build.gradle index d5941886..408af45e 100644 --- a/build.gradle +++ b/build.gradle @@ -6,12 +6,12 @@ buildscript { } dependencies { - classpath "org.elasticsearch.gradle:build-tools:6.7.1" + classpath "org.elasticsearch.gradle:build-tools:7.0.0" } } group = 'com.o19s' -version = '1.1.1-es6.7.1' +version = '1.1.1-es7.0.0' apply plugin: 'java' apply plugin: 'idea' @@ -46,15 +46,16 @@ repositories { } dependencies { - compile "org.apache.lucene:lucene-expressions:7.7.0" + compile "org.apache.lucene:lucene-expressions:8.0.0" compile 'org.antlr:antlr4-runtime:4.5.1-1' compile 'org.ow2.asm:asm:5.0.4' compile 'org.ow2.asm:asm-commons:5.0.4' compile 'org.ow2.asm:asm-tree:5.0.4' - compile 'org.elasticsearch:elasticsearch:6.7.1' + compile 'org.elasticsearch:elasticsearch:7.0.0' compile 'com.o19s:RankyMcRankFace:0.1.1' compile "com.github.spullara.mustache.java:compiler:0.9.3" - testCompile 'org.elasticsearch.test:framework:6.7.1' + testCompile 'org.elasticsearch.test:framework:7.0.0' + } dependencyLicenses { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5f1b1201..3b21cecb 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/src/main/java/com/o19s/es/explore/ExplorerQuery.java b/src/main/java/com/o19s/es/explore/ExplorerQuery.java index 450047bb..2e73cee3 100644 --- a/src/main/java/com/o19s/es/explore/ExplorerQuery.java +++ b/src/main/java/com/o19s/es/explore/ExplorerQuery.java @@ -13,12 +13,13 @@ * limitations under the License. * */ + package com.o19s.es.explore; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermContext; +import org.apache.lucene.index.TermStates; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.ConstantScoreScorer; @@ -27,6 +28,7 @@ import org.apache.lucene.search.Explanation; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TermStatistics; import org.apache.lucene.search.Weight; @@ -54,6 +56,7 @@ private boolean isCollectionScoped() { } public Query getQuery() { return this.query; } + public String getType() { return this.type; } @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") @@ -72,7 +75,7 @@ private boolean equalsTo(ExplorerQuery other) { public Query rewrite(IndexReader reader) throws IOException { Query rewritten = query.rewrite(reader); - if(rewritten != query) { + if (rewritten != query) { return new ExplorerQuery(rewritten, type); } @@ -85,25 +88,29 @@ public int hashCode() { } @Override - public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { - if (!needsScores) { - return searcher.createWeight(query, false, boost); + public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) + throws IOException { + if (!scoreMode.needsScores()) { + return searcher.createWeight(query, scoreMode, boost); } - final Weight subWeight = searcher.createWeight(query, true, boost); + final Weight subWeight = searcher.createWeight(query, scoreMode, boost); Set terms = new HashSet<>(); subWeight.extractTerms(terms); - if(isCollectionScoped()) { + if (isCollectionScoped()) { ClassicSimilarity sim = new ClassicSimilarity(); StatisticsHelper df_stats = new StatisticsHelper(); StatisticsHelper idf_stats = new StatisticsHelper(); StatisticsHelper ttf_stats = new StatisticsHelper(); - for(Term term : terms) { - TermContext ctx = TermContext.build(searcher.getTopReaderContext(), term); + for (Term term : terms) { + TermStates ctx = TermStates.build(searcher.getTopReaderContext(), term, scoreMode.needsScores()); TermStatistics tStats = searcher.termStatistics(term, ctx); - df_stats.add(tStats.docFreq()); - idf_stats.add(sim.idf(tStats.docFreq(), searcher.getIndexReader().numDocs())); - ttf_stats.add(tStats.totalTermFreq()); + if(tStats != null){ + df_stats.add(tStats.docFreq()); + idf_stats.add(sim.idf(tStats.docFreq(), searcher.getIndexReader().numDocs())); + ttf_stats.add(tStats.totalTermFreq()); + + } } /* @@ -113,7 +120,7 @@ public Weight createWeight(IndexSearcher searcher, boolean needsScores, float bo */ float constantScore; - if(terms.size() > 0) { + if (terms.size() > 0) { switch (type) { case ("sum_classic_idf"): constantScore = idf_stats.getSum(); @@ -185,7 +192,7 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio @Override public Scorer scorer(LeafReaderContext context) throws IOException { - return new ConstantScoreScorer(this, constantScore, DocIdSetIterator.all(context.reader().maxDoc())); + return new ConstantScoreScorer(this, constantScore, scoreMode, DocIdSetIterator.all(context.reader().maxDoc())); } @Override @@ -198,15 +205,16 @@ public boolean isCacheable(LeafReaderContext ctx) { // Rewrite this into a boolean query where we can inject our PostingsExplorerQuery BooleanQuery.Builder qb = new BooleanQuery.Builder(); for (Term t : terms) { - qb.add(new BooleanClause(new PostingsExplorerQuery(t, PostingsExplorerQuery.Type.TF), BooleanClause.Occur.SHOULD)); + qb.add(new BooleanClause(new PostingsExplorerQuery(t, PostingsExplorerQuery.Type.TF), + BooleanClause.Occur.SHOULD)); } // FIXME: completely refactor this class and stop accepting a random query but a list of terms directly // rewriting at this point is wrong, additionally we certainly build the TermContext twice for every terms // problem is that we rely on extractTerms which happen too late in the process Query q = qb.build().rewrite(searcher.getIndexReader()); - return new ExplorerQuery.ExplorerWeight(this, searcher.createWeight(q, true, boost), type); + return new ExplorerQuery.ExplorerWeight(this, searcher.createWeight(q, scoreMode, boost), type); } - throw new IllegalArgumentException( "Unknown ExplorerQuery type [" + type + "]" ); + throw new IllegalArgumentException("Unknown ExplorerQuery type [" + type + "]"); } static class ExplorerWeight extends Weight { diff --git a/src/main/java/com/o19s/es/explore/ExplorerScorer.java b/src/main/java/com/o19s/es/explore/ExplorerScorer.java index f3e2a7bf..b31b2906 100644 --- a/src/main/java/com/o19s/es/explore/ExplorerScorer.java +++ b/src/main/java/com/o19s/es/explore/ExplorerScorer.java @@ -37,7 +37,7 @@ public float score() throws IOException { // Grab freq from subscorer, or the children if available if(subScorer.getChildren().size() > 0) { - for(ChildScorer child : subScorer.getChildren()) { + for(ChildScorable child : subScorer.getChildren()) { assert child.child instanceof PostingsExplorerQuery.PostingsExplorerScorer; if(child.child.docID() == docID()) { tf_stats.add(child.child.score()); @@ -83,4 +83,14 @@ public int docID() { public DocIdSetIterator iterator() { return subScorer.iterator(); } + + /** + * Return the maximum score that documents between the last {@code target} + * that this iterator was {@link #advanceShallow(int) shallow-advanced} to + * included and {@code upTo} included. + */ + @Override + public float getMaxScore(int upTo) throws IOException { + return Float.POSITIVE_INFINITY; + } } diff --git a/src/main/java/com/o19s/es/explore/PostingsExplorerQuery.java b/src/main/java/com/o19s/es/explore/PostingsExplorerQuery.java index 904ca31f..8e60e26b 100644 --- a/src/main/java/com/o19s/es/explore/PostingsExplorerQuery.java +++ b/src/main/java/com/o19s/es/explore/PostingsExplorerQuery.java @@ -22,13 +22,14 @@ import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.ReaderUtil; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermContext; import org.apache.lucene.index.TermState; +import org.apache.lucene.index.TermStates; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; @@ -63,8 +64,8 @@ public String toString(String field) { @Override public boolean equals(Object obj) { return this.sameClassAs(obj) - && this.term.equals(((PostingsExplorerQuery)obj).term) - && this.type.equals(((PostingsExplorerQuery)obj).type); + && this.term.equals(((PostingsExplorerQuery) obj).term) + && this.type.equals(((PostingsExplorerQuery) obj).type); } @Override @@ -73,10 +74,13 @@ public int hashCode() { } @Override - public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { + public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) + throws IOException { IndexReaderContext context = searcher.getTopReaderContext(); - assert needsScores : "Should not be used in filtering mode"; - return new PostingsExplorerWeight(this, this.term, TermContext.build(context, this.term), this.type); + assert scoreMode.needsScores() : "Should not be used in filtering mode"; + return new PostingsExplorerWeight(this, this.term, TermStates.build(context, this.term, + scoreMode.needsScores()), + this.type); } /** @@ -100,10 +104,10 @@ public Scorer apply(Weight weight, TermsEnum termsEnum) throws IOException { static class PostingsExplorerWeight extends Weight { private final Term term; - private final TermContext termStates; + private final TermStates termStates; private final Type type; - PostingsExplorerWeight(Query query, Term term, TermContext termStates, Type type) { + PostingsExplorerWeight(Query query, Term term, TermStates termStates, Type type) { super(query); this.term = term; this.termStates = termStates; @@ -120,15 +124,17 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio Scorer scorer = this.scorer(context); int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { - return Explanation.match(scorer.score(), "weight(" + this.getQuery() + " in doc " + newDoc + ")"); + return Explanation + .match(scorer.score(), "weight(" + this.getQuery() + " in doc " + newDoc + ")"); } - return Explanation.noMatch("no matching term" ); + return Explanation.noMatch("no matching term"); } @Override public Scorer scorer(LeafReaderContext context) throws IOException { - assert this.termStates != null && this.termStates.wasBuiltFor(ReaderUtil.getTopLevelContext(context)); - TermState state = this.termStates.get(context.ord); + assert this.termStates != null && this.termStates + .wasBuiltFor(ReaderUtil.getTopLevelContext(context)); + TermState state = this.termStates.get(context); if (state == null) { return null; } else { @@ -172,5 +178,15 @@ static class TFScorer extends PostingsExplorerScorer { public float score() throws IOException { return this.postingsEnum.freq(); } + + /** + * Return the maximum score that documents between the last {@code target} + * that this iterator was {@link #advanceShallow(int) shallow-advanced} to + * included and {@code upTo} included. + */ + @Override + public float getMaxScore(int upTo) throws IOException { + return Float.POSITIVE_INFINITY; + } } } diff --git a/src/main/java/com/o19s/es/ltr/LtrQueryParserPlugin.java b/src/main/java/com/o19s/es/ltr/LtrQueryParserPlugin.java index be688f19..615f4160 100644 --- a/src/main/java/com/o19s/es/ltr/LtrQueryParserPlugin.java +++ b/src/main/java/com/o19s/es/ltr/LtrQueryParserPlugin.java @@ -16,7 +16,6 @@ */ package com.o19s.es.ltr; -import ciir.umass.edu.learning.RankerFactory; import com.o19s.es.explore.ExplorerQueryBuilder; import com.o19s.es.ltr.action.AddFeaturesToSetAction; import com.o19s.es.ltr.action.CachesStatsAction; @@ -53,6 +52,7 @@ import com.o19s.es.ltr.rest.RestSimpleFeatureStore; import com.o19s.es.ltr.utils.FeatureStoreLoader; import com.o19s.es.ltr.utils.Suppliers; + import org.apache.lucene.analysis.core.KeywordTokenizer; import org.apache.lucene.analysis.miscellaneous.LengthFilter; import org.apache.lucene.analysis.ngram.EdgeNGramTokenFilter; @@ -100,6 +100,8 @@ import java.util.List; import java.util.function.Supplier; +import ciir.umass.edu.learning.RankerFactory; + import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static java.util.Collections.unmodifiableList; @@ -253,6 +255,6 @@ public List getPreConfiguredTokenFilters() { public List getPreConfiguredTokenizers() { return Collections.singletonList(PreConfiguredTokenizer.singleton("ltr_keyword", - () -> new KeywordTokenizer(KeywordTokenizer.DEFAULT_BUFFER_SIZE), null)); + () -> new KeywordTokenizer(KeywordTokenizer.DEFAULT_BUFFER_SIZE))); } } diff --git a/src/main/java/com/o19s/es/ltr/action/AddFeaturesToSetAction.java b/src/main/java/com/o19s/es/ltr/action/AddFeaturesToSetAction.java index 67df5018..9ab6e7ef 100644 --- a/src/main/java/com/o19s/es/ltr/action/AddFeaturesToSetAction.java +++ b/src/main/java/com/o19s/es/ltr/action/AddFeaturesToSetAction.java @@ -36,8 +36,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; -public class AddFeaturesToSetAction extends Action { +public class AddFeaturesToSetAction extends Action { public static final AddFeaturesToSetAction INSTANCE = new AddFeaturesToSetAction(); public static final String NAME = "cluster:admin/ltr/store/add-features-to-set"; @@ -45,19 +44,13 @@ protected AddFeaturesToSetAction() { super(NAME); } - @Override - public AddFeaturesToSetRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new AddFeaturesToSetRequestBuilder(client); - } - @Override public AddFeaturesToSetResponse newResponse() { return new AddFeaturesToSetResponse(); } - public static class AddFeaturesToSetRequestBuilder extends ActionRequestBuilder { - protected AddFeaturesToSetRequestBuilder(ElasticsearchClient client) { + public static class AddFeaturesToSetRequestBuilder extends ActionRequestBuilder { + public AddFeaturesToSetRequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new AddFeaturesToSetRequest()); } } diff --git a/src/main/java/com/o19s/es/ltr/action/CachesStatsAction.java b/src/main/java/com/o19s/es/ltr/action/CachesStatsAction.java index 5a5a3a9b..432a1069 100644 --- a/src/main/java/com/o19s/es/ltr/action/CachesStatsAction.java +++ b/src/main/java/com/o19s/es/ltr/action/CachesStatsAction.java @@ -37,8 +37,7 @@ import java.util.List; import java.util.Map; -public class CachesStatsAction extends Action { +public class CachesStatsAction extends Action { public static final String NAME = "cluster:admin/ltr/caches/stats"; public static final CachesStatsAction INSTANCE = new CachesStatsAction(); @@ -46,22 +45,11 @@ protected CachesStatsAction() { super(NAME); } - @Override - public CacheStatsRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new CacheStatsRequestBuilder(client); - } - @Override public CachesStatsNodesResponse newResponse() { return new CachesStatsNodesResponse(); } - public static class CacheStatsRequestBuilder extends ActionRequestBuilder { - protected CacheStatsRequestBuilder(ElasticsearchClient client) { - super(client, INSTANCE, new CachesStatsNodesRequest()); - } - } public static class CachesStatsNodesRequest extends BaseNodesRequest { } @@ -309,4 +297,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } } } + + public static class CachesStatsActionBuilder extends + ActionRequestBuilder { + public CachesStatsActionBuilder(ElasticsearchClient client){ + super(client, INSTANCE, new CachesStatsNodesRequest()); + } + } + } diff --git a/src/main/java/com/o19s/es/ltr/action/ClearCachesAction.java b/src/main/java/com/o19s/es/ltr/action/ClearCachesAction.java index a4ac4e22..b197317c 100644 --- a/src/main/java/com/o19s/es/ltr/action/ClearCachesAction.java +++ b/src/main/java/com/o19s/es/ltr/action/ClearCachesAction.java @@ -35,8 +35,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; -public class ClearCachesAction extends Action { +public class ClearCachesAction extends Action { public static final String NAME = "cluster:admin/ltr/caches"; public static final ClearCachesAction INSTANCE = new ClearCachesAction(); @@ -44,19 +43,13 @@ private ClearCachesAction() { super(NAME); } - @Override - public RequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new RequestBuilder(client); - } - @Override public ClearCachesNodesResponse newResponse() { return new ClearCachesNodesResponse(); } - public static class RequestBuilder extends ActionRequestBuilder { - RequestBuilder(ElasticsearchClient client) { + public static class RequestBuilder extends ActionRequestBuilder { + public RequestBuilder(ElasticsearchClient client) { super(client, ClearCachesAction.INSTANCE, new ClearCachesNodesRequest()); } } diff --git a/src/main/java/com/o19s/es/ltr/action/CreateModelFromSetAction.java b/src/main/java/com/o19s/es/ltr/action/CreateModelFromSetAction.java index 3762c68b..a0ba7f56 100644 --- a/src/main/java/com/o19s/es/ltr/action/CreateModelFromSetAction.java +++ b/src/main/java/com/o19s/es/ltr/action/CreateModelFromSetAction.java @@ -35,8 +35,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; -public class CreateModelFromSetAction extends Action { +public class CreateModelFromSetAction extends Action { public static final String NAME = "cluster:admin/ltr/store/create-model-from-set"; public static final CreateModelFromSetAction INSTANCE = new CreateModelFromSetAction(); @@ -44,11 +43,6 @@ protected CreateModelFromSetAction() { super(NAME); } - @Override - public CreateModelFromSetRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new CreateModelFromSetRequestBuilder(client); - } - /** * Creates a new response instance. */ @@ -58,9 +52,9 @@ public CreateModelFromSetResponse newResponse() { } public static class CreateModelFromSetRequestBuilder extends ActionRequestBuilder { + CreateModelFromSetResponse> { - protected CreateModelFromSetRequestBuilder(ElasticsearchClient client) { + public CreateModelFromSetRequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new CreateModelFromSetRequest()); } diff --git a/src/main/java/com/o19s/es/ltr/action/FeatureStoreAction.java b/src/main/java/com/o19s/es/ltr/action/FeatureStoreAction.java index 57f64a8a..00cf5b04 100644 --- a/src/main/java/com/o19s/es/ltr/action/FeatureStoreAction.java +++ b/src/main/java/com/o19s/es/ltr/action/FeatureStoreAction.java @@ -37,8 +37,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; -public class FeatureStoreAction extends Action { +public class FeatureStoreAction extends Action { public static final String NAME = "cluster:admin/ltr/featurestore/data"; public static final FeatureStoreAction INSTANCE = new FeatureStoreAction(); @@ -51,14 +50,9 @@ public FeatureStoreResponse newResponse() { return new FeatureStoreResponse(); } - @Override - public FeatureStoreRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new FeatureStoreRequestBuilder(client, this); - } - public static class FeatureStoreRequestBuilder - extends ActionRequestBuilder { - FeatureStoreRequestBuilder(ElasticsearchClient client, FeatureStoreAction action) { + extends ActionRequestBuilder { + public FeatureStoreRequestBuilder(ElasticsearchClient client, FeatureStoreAction action) { super(client, action, new FeatureStoreRequest()); } } diff --git a/src/main/java/com/o19s/es/ltr/action/ListStoresAction.java b/src/main/java/com/o19s/es/ltr/action/ListStoresAction.java index 891298f2..fbeb4a5b 100644 --- a/src/main/java/com/o19s/es/ltr/action/ListStoresAction.java +++ b/src/main/java/com/o19s/es/ltr/action/ListStoresAction.java @@ -36,8 +36,7 @@ import java.util.Objects; import java.util.stream.Collectors; -public class ListStoresAction extends Action { +public class ListStoresAction extends Action { public static final String NAME = "cluster:admin/ltr/featurestore/list"; public static final ListStoresAction INSTANCE = new ListStoresAction(); @@ -50,18 +49,6 @@ public ListStoresActionResponse newResponse() { return new ListStoresActionResponse(); } - @Override - public ListStoresActionRequestBuilder newRequestBuilder(ElasticsearchClient client) { - return new ListStoresActionRequestBuilder(client); - } - - public static class ListStoresActionRequestBuilder extends ActionRequestBuilder { - protected ListStoresActionRequestBuilder(ElasticsearchClient client) { - super(client, INSTANCE, new ListStoresActionRequest()); - } - } - public static class ListStoresActionRequest extends MasterNodeReadRequest { @Override public ActionRequestValidationException validate() { @@ -155,4 +142,11 @@ public Map getCounts() { return counts; } } + + public static class ListStoresActionBuilder extends + ActionRequestBuilder { + public ListStoresActionBuilder(ElasticsearchClient client){ + super(client, INSTANCE, new ListStoresActionRequest()); + } + } } diff --git a/src/main/java/com/o19s/es/ltr/action/TransportAddFeatureToSetAction.java b/src/main/java/com/o19s/es/ltr/action/TransportAddFeatureToSetAction.java index ea55b264..c404453b 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportAddFeatureToSetAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportAddFeatureToSetAction.java @@ -24,7 +24,6 @@ import com.o19s.es.ltr.feature.store.StoredFeature; import com.o19s.es.ltr.feature.store.StoredFeatureSet; import com.o19s.es.ltr.feature.store.index.IndexFeatureStore; -import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; @@ -67,19 +66,13 @@ public TransportAddFeatureToSetAction(Settings settings, ThreadPool threadPool, IndexNameExpressionResolver indexNameExpressionResolver, ClusterService clusterService, TransportSearchAction searchAction, TransportGetAction getAction, TransportFeatureStoreAction featureStoreAction) { - super(settings, AddFeaturesToSetAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, - AddFeaturesToSetRequest::new); + super(AddFeaturesToSetAction.NAME, transportService, actionFilters, AddFeaturesToSetRequest::new); this.clusterService = clusterService; this.searchAction = searchAction; this.getAction = getAction; this.featureStoreAction = featureStoreAction; } - @Override - protected final void doExecute(AddFeaturesToSetRequest request, ActionListener listener) { - throw new UnsupportedOperationException("attempt to execute a TransportAddFeatureToSetAction without a task"); - } - @Override protected void doExecute(Task task, AddFeaturesToSetRequest request, ActionListener listener) { if (!clusterService.state().routingTable().hasIndex(request.getStore())) { @@ -181,7 +174,6 @@ private void fetchFeaturesFromStore() { srequest.source().query(bq); srequest.source().fetchSource(true); srequest.source().size(StoredFeatureSet.MAX_FEATURES); - ActionFuture resp = searchAction.execute(srequest); searchAction.execute(srequest, wrap(this::onSearchResponse, this::onSearchFailure)); } @@ -215,10 +207,10 @@ private void onGetResponse(GetResponse getResponse) { private void onSearchResponse(SearchResponse sr) { try { - if (sr.getHits().getTotalHits() > StoredFeatureSet.MAX_FEATURES) { + if (sr.getHits().getTotalHits().value > StoredFeatureSet.MAX_FEATURES) { throw new IllegalArgumentException("The feature query [" + featureNamesQuery + "] returns too many features"); } - if (sr.getHits().getTotalHits() == 0) { + if (sr.getHits().getTotalHits().value == 0) { throw new IllegalArgumentException("The feature query [" + featureNamesQuery + "] returned no features"); } final List features = new ArrayList<>(sr.getHits().getHits().length); diff --git a/src/main/java/com/o19s/es/ltr/action/TransportCacheStatsAction.java b/src/main/java/com/o19s/es/ltr/action/TransportCacheStatsAction.java index b8616fca..3291e149 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportCacheStatsAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportCacheStatsAction.java @@ -42,9 +42,9 @@ public TransportCacheStatsAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Caches caches) { - super(settings, CachesStatsAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver, - CachesStatsNodesRequest::new, CachesStatsNodeRequest::new, ThreadPool.Names.MANAGEMENT, - CachesStatsAction.CachesStatsNodeResponse.class); + super(CachesStatsAction.NAME, threadPool, clusterService, transportService, + actionFilters, CachesStatsNodesRequest::new, CachesStatsNodeRequest::new, + ThreadPool.Names.MANAGEMENT, CachesStatsAction.CachesStatsNodeResponse.class); this.caches = caches; } diff --git a/src/main/java/com/o19s/es/ltr/action/TransportClearCachesAction.java b/src/main/java/com/o19s/es/ltr/action/TransportClearCachesAction.java index ed976cfa..8d722059 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportClearCachesAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportClearCachesAction.java @@ -45,7 +45,7 @@ public TransportClearCachesAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Caches caches) { - super(settings, ClearCachesAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver, + super(ClearCachesAction.NAME, threadPool, clusterService, transportService, actionFilters, ClearCachesNodesRequest::new, ClearCachesNodeRequest::new, ThreadPool.Names.MANAGEMENT, ClearCachesNodeResponse.class); this.caches = caches; } diff --git a/src/main/java/com/o19s/es/ltr/action/TransportCreateModelFromSetAction.java b/src/main/java/com/o19s/es/ltr/action/TransportCreateModelFromSetAction.java index 1ec532cb..f6b214f3 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportCreateModelFromSetAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportCreateModelFromSetAction.java @@ -50,18 +50,12 @@ public TransportCreateModelFromSetAction(Settings settings, ThreadPool threadPoo IndexNameExpressionResolver indexNameExpressionResolver, ClusterService clusterService, TransportGetAction getAction, TransportFeatureStoreAction featureStoreAction) { - super(settings, CreateModelFromSetAction.NAME, threadPool, transportService, - actionFilters, indexNameExpressionResolver, CreateModelFromSetRequest::new); + super(CreateModelFromSetAction.NAME, transportService, actionFilters, CreateModelFromSetRequest::new); this.clusterService = clusterService; this.getAction = getAction; this.featureStoreAction = featureStoreAction; } - @Override - protected final void doExecute(CreateModelFromSetRequest request, ActionListener listener) { - throw new UnsupportedOperationException("attempt to execute a TransportCreateModelFromSetAction without a task"); - } - @Override protected void doExecute(Task task, CreateModelFromSetRequest request, ActionListener listener) { if (!clusterService.state().routingTable().hasIndex(request.getStore())) { diff --git a/src/main/java/com/o19s/es/ltr/action/TransportFeatureStoreAction.java b/src/main/java/com/o19s/es/ltr/action/TransportFeatureStoreAction.java index a4ed7a6b..44db0e55 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportFeatureStoreAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportFeatureStoreAction.java @@ -62,19 +62,13 @@ public TransportFeatureStoreAction(Settings settings, ThreadPool threadPool, Tra ClusterService clusterService, Client client, LtrRankerParserFactory factory, TransportClearCachesAction clearCachesAction) { - super(settings, FeatureStoreAction.NAME, false, threadPool, transportService, actionFilters, - indexNameExpressionResolver, FeatureStoreRequest::new); + super(FeatureStoreAction.NAME, false, transportService, actionFilters, FeatureStoreRequest::new); this.factory = factory; this.clusterService = clusterService; this.clearCachesAction = clearCachesAction; this.client = client; } - @Override - protected void doExecute(FeatureStoreRequest request, ActionListener listener) { - throw new UnsupportedOperationException("attempt to execute a TransportFeatureStoreAction without a task"); - } - @Override protected void doExecute(Task task, FeatureStoreRequest request, ActionListener listener) { if (!clusterService.state().routingTable().hasIndex(request.getStore())) { @@ -157,7 +151,7 @@ private void validate(FeatureValidation validation, Runnable onSuccess) { ValidatingLtrQueryBuilder ltrBuilder = new ValidatingLtrQueryBuilder(element, validation, factory); - SearchRequestBuilder builder = SearchAction.INSTANCE.newRequestBuilder(client); + SearchRequestBuilder builder = new SearchRequestBuilder(client, SearchAction.INSTANCE); builder.setIndices(validation.getIndex()); builder.setQuery(ltrBuilder); builder.setFrom(0); diff --git a/src/main/java/com/o19s/es/ltr/action/TransportListStoresAction.java b/src/main/java/com/o19s/es/ltr/action/TransportListStoresAction.java index 734ed402..73d7beab 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportListStoresAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportListStoresAction.java @@ -62,8 +62,8 @@ public class TransportListStoresAction extends TransportMasterNodeReadAction loggers, IndexSearcher searcher, SearchHit[] hits) throws IOException { @@ -90,7 +87,7 @@ void doLog(Query query, List loggers, IndexSearcher searcher, Se int endDoc = 0; int docBase = 0; Scorer scorer = null; - Weight weight = searcher.createWeight(searcher.rewrite(query), true, 1F); + Weight weight = searcher.createWeight(searcher.rewrite(query), ScoreMode.COMPLETE, 1F); // Loop logic borrowed from lucene QueryRescorer while (hitUpto < reordered.length) { SearchHit hit = reordered[hitUpto]; @@ -109,7 +106,7 @@ void doLog(Query query, List loggers, IndexSearcher searcher, Se scorer = weight.scorer(readerContext); } - if(scorer != null) { + if (scorer != null) { int targetDoc = docID - docBase; int actualDoc = scorer.docID(); if (actualDoc < targetDoc) { @@ -132,15 +129,17 @@ private Tuple extractQuery(LoggingSearchExtBuilder. } return toLogger(logSpec, inspectQuery(q) .orElseThrow(() -> new IllegalArgumentException("Query named [" + logSpec.getNamedQuery() + - "] must be a [sltr] query [" + - ((q instanceof BoostQuery) ? ((BoostQuery)q).getQuery().getClass().getSimpleName() : q.getClass().getSimpleName()) + - "] found"))); + "] must be a [sltr] query [" + + ((q instanceof BoostQuery) ? ((BoostQuery) q).getQuery().getClass().getSimpleName( + + ) : q.getClass().getSimpleName()) + + "] found"))); } private Tuple extractRescore(LoggingSearchExtBuilder.LogSpec logSpec, List contexts) { if (logSpec.getRescoreIndex() >= contexts.size()) { - throw new IllegalArgumentException("rescore index [" + logSpec.getRescoreIndex()+"] is out of bounds, only " + + throw new IllegalArgumentException("rescore index [" + logSpec.getRescoreIndex() + "] is out of bounds, only " + "[" + contexts.size() + "] rescore context(s) are available"); } RescoreContext context = contexts.get(logSpec.getRescoreIndex()); @@ -152,8 +151,8 @@ private Tuple extractRescore(LoggingSearchExtBuilde QueryRescorer.QueryRescoreContext qrescore = (QueryRescorer.QueryRescoreContext) context; return toLogger(logSpec, inspectQuery(qrescore.query()) .orElseThrow(() -> new IllegalArgumentException("Expected a [sltr] query but found a " + - "[" + qrescore.query().getClass().getSimpleName() + "] " + - "at index [" + logSpec.getRescoreIndex() + "]"))); + "[" + qrescore.query().getClass().getSimpleName() + "] " + + "at index [" + logSpec.getRescoreIndex() + "]"))); } private Optional inspectQuery(Query q) { @@ -199,7 +198,7 @@ static class HitLogConsumer implements LogLtrRanker.LogConsumer { } private void rebuild() { - List> ini = new ArrayList<>(set.size()) ; + List> ini = new ArrayList<>(set.size()); for (int i = 0; i < set.size(); i++) { Map defaultKeyVal = new HashMap<>(); @@ -216,11 +215,6 @@ private void rebuild() { public void accept(int featureOrdinal, float score) { assert currentLog != null; assert currentHit != null; - if (Float.isNaN(score)) { - // NOTE: should we fail on Float#isInfinite() as well? - throw new LtrLoggingException("FeatureĀ [" + set.feature(featureOrdinal).name() +"] produced a NaN value " + - "for doc [" + currentHit.getId() + "]" ); - } currentLog.get(featureOrdinal).put("value", score); } @@ -229,7 +223,7 @@ void nextDoc(SearchHit hit) { hit.fields(new HashMap<>()); } DocumentField logs = hit.getFields() - .computeIfAbsent(FIELD_NAME,(k) -> newLogField()); + .computeIfAbsent(FIELD_NAME, (k) -> newLogField()); Map>> entries = logs.getValue(); rebuild(); currentHit = hit; diff --git a/src/main/java/com/o19s/es/ltr/logging/LtrLoggingException.java b/src/main/java/com/o19s/es/ltr/logging/LtrLoggingException.java deleted file mode 100644 index 18829db6..00000000 --- a/src/main/java/com/o19s/es/ltr/logging/LtrLoggingException.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright [2017] Wikimedia Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.o19s.es.ltr.logging; - -/** - * Error happening while logging feature values. - */ -public class LtrLoggingException extends RuntimeException { - public LtrLoggingException(String s) { - super(s); - } -} diff --git a/src/main/java/com/o19s/es/ltr/query/DerivedExpressionQuery.java b/src/main/java/com/o19s/es/ltr/query/DerivedExpressionQuery.java index c38a683e..f834b2c4 100644 --- a/src/main/java/com/o19s/es/ltr/query/DerivedExpressionQuery.java +++ b/src/main/java/com/o19s/es/ltr/query/DerivedExpressionQuery.java @@ -30,6 +30,7 @@ import org.apache.lucene.search.Explanation; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; @@ -94,8 +95,8 @@ public String toString(String field) { } @Override - public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { - if (!needsScores) { + public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { + if (!scoreMode.needsScores()) { // If scores are not needed simply return a constant score on all docs return new ConstantScoreWeight(this.query, boost) { @Override @@ -105,7 +106,8 @@ public boolean isCacheable(LeafReaderContext ctx) { @Override public Scorer scorer(LeafReaderContext context) throws IOException { - return new ConstantScoreScorer(this, score(), DocIdSetIterator.all(context.reader().maxDoc())); + return new ConstantScoreScorer(this, score(), + scoreMode, DocIdSetIterator.all(context.reader().maxDoc())); } }; } @@ -215,6 +217,16 @@ public float score() throws IOException { public DocIdSetIterator iterator() { return iterator; } + + /** + * Return the maximum score that documents between the last {@code target} + * that this iterator was {@link #advanceShallow(int) shallow-advanced} to + * included and {@code upTo} included. + */ + @Override + public float getMaxScore(int upTo) throws IOException { + return Float.POSITIVE_INFINITY; + } } static class FVDoubleValuesSource extends DoubleValuesSource { diff --git a/src/main/java/com/o19s/es/ltr/query/NoopScorer.java b/src/main/java/com/o19s/es/ltr/query/NoopScorer.java index 2605b8b8..82700c7b 100644 --- a/src/main/java/com/o19s/es/ltr/query/NoopScorer.java +++ b/src/main/java/com/o19s/es/ltr/query/NoopScorer.java @@ -56,4 +56,14 @@ public float score() throws IOException { public DocIdSetIterator iterator() { return _noopIter; } + + /** + * Return the maximum score that documents between the last {@code target} + * that this iterator was {@link #advanceShallow(int) shallow-advanced} to + * included and {@code upTo} included. + */ + @Override + public float getMaxScore(int upTo) throws IOException { + return Float.POSITIVE_INFINITY; + } } diff --git a/src/main/java/com/o19s/es/ltr/query/RankerQuery.java b/src/main/java/com/o19s/es/ltr/query/RankerQuery.java index 775442e6..8f834f22 100644 --- a/src/main/java/com/o19s/es/ltr/query/RankerQuery.java +++ b/src/main/java/com/o19s/es/ltr/query/RankerQuery.java @@ -37,6 +37,7 @@ import org.apache.lucene.search.Explanation; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; @@ -170,13 +171,14 @@ public FeatureSet featureSet() { } @Override - public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { - if (!needsScores) { + public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { + if (!scoreMode.needsScores()) { // If scores are not needed simply return a constant score on all docs return new ConstantScoreWeight(this, boost) { @Override public Scorer scorer(LeafReaderContext context) throws IOException { - return new ConstantScoreScorer(this, score(), DocIdSetIterator.all(context.reader().maxDoc())); + return new ConstantScoreScorer(this, score(), + scoreMode, DocIdSetIterator.all(context.reader().maxDoc())); } @Override @@ -196,7 +198,7 @@ public boolean isCacheable(LeafReaderContext ctx) { if (q instanceof LtrRewritableQuery) { q = ((LtrRewritableQuery)q).ltrRewrite(vectorSupplier); } - weights.add(searcher.createWeight(q, true, boost)); + weights.add(searcher.createWeight(q, ScoreMode.COMPLETE, boost)); } return new RankerWeight(this, weights, ltrRankerWrapper, features); } @@ -245,7 +247,7 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio subs.add(Explanation.noMatch(featureString + " [no match, default value 0.0 used]")); } else { subs.add(Explanation.match(explain.getValue(), featureString, explain)); - d.setFeatureScore(ordinal, explain.getValue()); + d.setFeatureScore(ordinal, explain.getValue().floatValue()); } } float modelScore = ranker.score(d); @@ -320,6 +322,16 @@ public float score() throws IOException { public DocIdSetIterator iterator() { return iterator; } + + /** + * Return the maximum score that documents between the last {@code target} + * that this iterator was {@link #advanceShallow(int) shallow-advanced} to + * included and {@code upTo} included. + */ + @Override + public float getMaxScore(int upTo) throws IOException { + return Float.POSITIVE_INFINITY; + } } } diff --git a/src/main/java/com/o19s/es/ltr/ranker/ranklib/RankLibScriptEngine.java b/src/main/java/com/o19s/es/ltr/ranker/ranklib/RankLibScriptEngine.java index c5956e3e..2cfd3cd6 100644 --- a/src/main/java/com/o19s/es/ltr/ranker/ranklib/RankLibScriptEngine.java +++ b/src/main/java/com/o19s/es/ltr/ranker/ranklib/RankLibScriptEngine.java @@ -18,7 +18,6 @@ import com.o19s.es.ltr.ranker.LtrRanker; import com.o19s.es.ltr.ranker.parser.LtrRankerParserFactory; -import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptEngine; @@ -36,7 +35,7 @@ * So this code acts as a hook for deserializing Ranklib models from ranklib XML * and as a convenient means for caching those deserialized model */ -public class RankLibScriptEngine extends AbstractComponent implements ScriptEngine { +public class RankLibScriptEngine implements ScriptEngine { public static final String NAME = "ranklib"; public static final String EXTENSION = "ranklib"; diff --git a/src/main/java/com/o19s/es/ltr/rest/RestAddFeatureToSet.java b/src/main/java/com/o19s/es/ltr/rest/RestAddFeatureToSet.java index 74eda159..6eb052ac 100644 --- a/src/main/java/com/o19s/es/ltr/rest/RestAddFeatureToSet.java +++ b/src/main/java/com/o19s/es/ltr/rest/RestAddFeatureToSet.java @@ -16,7 +16,6 @@ package com.o19s.es.ltr.rest; -import com.o19s.es.ltr.action.AddFeaturesToSetAction; import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetRequestBuilder; import com.o19s.es.ltr.feature.FeatureValidation; import com.o19s.es.ltr.feature.store.StoredFeature; @@ -75,7 +74,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli "or directly in the body not both"); } - AddFeaturesToSetRequestBuilder builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client); + AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client); builder.request().setStore(store); builder.request().setFeatureSet(setName); builder.request().setFeatureNameQuery(featureQuery); diff --git a/src/main/java/com/o19s/es/ltr/rest/RestCreateModelFromSet.java b/src/main/java/com/o19s/es/ltr/rest/RestCreateModelFromSet.java index 315c7fd7..e0a65d1e 100644 --- a/src/main/java/com/o19s/es/ltr/rest/RestCreateModelFromSet.java +++ b/src/main/java/com/o19s/es/ltr/rest/RestCreateModelFromSet.java @@ -63,7 +63,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli String routing = request.param("routing"); ParserState state = new ParserState(); request.withContentOrSourceParamParserOrNull((p) -> ParserState.parse(p, state)); - CreateModelFromSetRequestBuilder builder = CreateModelFromSetAction.INSTANCE.newRequestBuilder(client); + CreateModelFromSetRequestBuilder builder = new CreateModelFromSetRequestBuilder(client); if (expectedVersion != null) { builder.withVersion(store, request.param("name"), expectedVersion, state.model.name, state.model.model); } else { diff --git a/src/main/java/com/o19s/es/ltr/rest/RestFeatureStoreCaches.java b/src/main/java/com/o19s/es/ltr/rest/RestFeatureStoreCaches.java index 7b3808ee..31b0c67b 100644 --- a/src/main/java/com/o19s/es/ltr/rest/RestFeatureStoreCaches.java +++ b/src/main/java/com/o19s/es/ltr/rest/RestFeatureStoreCaches.java @@ -19,6 +19,7 @@ import com.o19s.es.ltr.action.CachesStatsAction; import com.o19s.es.ltr.action.ClearCachesAction; import com.o19s.es.ltr.action.ClearCachesAction.ClearCachesNodesResponse; + import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -66,13 +67,14 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli } } + @SuppressWarnings({"rawtypes", "unchecked"}) private RestChannelConsumer getStats(NodeClient client) { - return (channel) -> CachesStatsAction.INSTANCE.newRequestBuilder(client).execute(new NodesResponseRestListener<>(channel)); + return (channel) -> new CachesStatsAction.CachesStatsActionBuilder(client).execute(new NodesResponseRestListener(channel)); } private RestChannelConsumer clearCache(RestRequest request, NodeClient client) { String storeName = indexName(request); - ClearCachesAction.RequestBuilder builder = ClearCachesAction.INSTANCE.newRequestBuilder(client); + ClearCachesAction.RequestBuilder builder = new ClearCachesAction.RequestBuilder(client); builder.request().clearStore(storeName); return (channel) -> builder.execute(new RestBuilderListener(channel) { @Override diff --git a/src/main/java/com/o19s/es/ltr/rest/RestSimpleFeatureStore.java b/src/main/java/com/o19s/es/ltr/rest/RestSimpleFeatureStore.java index 9b048478..4c30e3cd 100644 --- a/src/main/java/com/o19s/es/ltr/rest/RestSimpleFeatureStore.java +++ b/src/main/java/com/o19s/es/ltr/rest/RestSimpleFeatureStore.java @@ -208,7 +208,7 @@ public RestResponse buildResponse(IndicesExistsResponse indicesExistsResponse, } RestChannelConsumer listStores(NodeClient client) { - return (channel) -> ListStoresAction.INSTANCE.newRequestBuilder(client).execute( + return (channel) -> new ListStoresAction.ListStoresActionBuilder(client).execute( new RestToXContentListener<>(channel)); } @@ -248,7 +248,8 @@ RestChannelConsumer addOrUpdate(NodeClient client, String type, String indexName return (channel) -> channel.sendResponse(new BytesRestResponse(channel, RestStatus.METHOD_NOT_ALLOWED, iae)); } } - FeatureStoreAction.FeatureStoreRequestBuilder builder = FeatureStoreAction.INSTANCE.newRequestBuilder(client); + FeatureStoreAction.FeatureStoreRequestBuilder builder = new FeatureStoreAction.FeatureStoreRequestBuilder( + client, FeatureStoreAction.INSTANCE); if (request.method() == RestRequest.Method.PUT) { builder.request().setAction(FeatureStoreAction.FeatureStoreRequest.Action.CREATE); } else { @@ -275,7 +276,7 @@ RestChannelConsumer delete(NodeClient client, String type, String indexName, Res // wrap the response so we can send another request to clear the cache // usually we send only one transport request from the rest layer // it's still unclear which direction we should take (thick or thin REST layer?) - ClearCachesAction.RequestBuilder clearCache = ClearCachesAction.INSTANCE.newRequestBuilder(client); + ClearCachesAction.RequestBuilder clearCache = new ClearCachesAction.RequestBuilder(client); switch (type) { case StoredFeature.TYPE: clearCache.request().clearFeature(indexName, name); diff --git a/src/test/java/com/o19s/es/explore/ExplorerQueryTests.java b/src/test/java/com/o19s/es/explore/ExplorerQueryTests.java index 893ddd04..544b79c2 100644 --- a/src/test/java/com/o19s/es/explore/ExplorerQueryTests.java +++ b/src/test/java/com/o19s/es/explore/ExplorerQueryTests.java @@ -110,7 +110,7 @@ public void testBooleanQuery() throws Exception { // Verify tf score TopDocs docs = searcher.search(eq, 4); - assertThat(docs.getMaxScore(), equalTo(3.0f)); + assertThat(docs.scoreDocs[0].score, equalTo(3.0f)); } public void testUniqueTerms() throws Exception { @@ -136,7 +136,7 @@ public void testUniqueTerms() throws Exception { // Verify score is 5 (5 unique terms) TopDocs docs = searcher.search(eq, 4); - assertThat(docs.getMaxScore(), equalTo(5.0f)); + assertThat(docs.scoreDocs[0].score, equalTo(5.0f)); } public void testInvalidStat() throws Exception { diff --git a/src/test/java/com/o19s/es/ltr/action/AddFeaturesToSetActionIT.java b/src/test/java/com/o19s/es/ltr/action/AddFeaturesToSetActionIT.java index 1910d755..9c9be4a2 100644 --- a/src/test/java/com/o19s/es/ltr/action/AddFeaturesToSetActionIT.java +++ b/src/test/java/com/o19s/es/ltr/action/AddFeaturesToSetActionIT.java @@ -45,7 +45,7 @@ public void testAddToSetWithQuery() throws Exception { addElement(randomFeature("another")); - AddFeaturesToSetRequestBuilder builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("new_feature_set"); builder.request().setFeatureNameQuery("feature*"); builder.request().setStore(IndexFeatureStore.DEFAULT_STORE); @@ -59,7 +59,7 @@ public void testAddToSetWithQuery() throws Exception { assertEquals(features.size(), set.size()); assertTrue(features.stream().map(StoredFeature::name).allMatch(set::hasFeature)); - builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + builder = new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("new_feature_set"); builder.request().setFeatureNameQuery("another"); builder.request().setStore(IndexFeatureStore.DEFAULT_STORE); @@ -78,7 +78,7 @@ public void testAddToSetWithList() throws Exception { features.add(feat); } - AddFeaturesToSetRequestBuilder builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("new_feature_set"); builder.request().setFeatures(features); builder.request().setStore(IndexFeatureStore.DEFAULT_STORE); @@ -92,7 +92,7 @@ public void testAddToSetWithList() throws Exception { assertEquals(features.size(), set.size()); assertTrue(features.stream().map(StoredFeature::name).allMatch(set::hasFeature)); - builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + builder = new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("new_feature_set"); builder.request().setFeatures(Collections.singletonList(randomFeature("another_feature"))); builder.request().setStore(IndexFeatureStore.DEFAULT_STORE); @@ -105,7 +105,7 @@ public void testAddToSetWithList() throws Exception { } public void testFailuresWhenEmpty() throws Exception { - AddFeaturesToSetRequestBuilder builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("new_broken_set"); builder.request().setFeatureNameQuery("doesnotexist*"); builder.request().setStore(IndexFeatureStore.DEFAULT_STORE); @@ -118,7 +118,7 @@ public void testFailuresWhenEmpty() throws Exception { public void testFailuresOnDuplicates() throws Exception { addElement(randomFeature("duplicated")); - AddFeaturesToSetRequestBuilder builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("duplicated_set"); builder.request().setFeatureNameQuery("duplicated*"); builder.request().setStore(IndexFeatureStore.DEFAULT_STORE); @@ -128,7 +128,7 @@ public void testFailuresOnDuplicates() throws Exception { assertEquals(1, resp.getResponse().getVersion()); - AddFeaturesToSetRequestBuilder builder2 = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetRequestBuilder builder2= new AddFeaturesToSetRequestBuilder(client()); builder2.request().setFeatureSet("duplicated_set"); builder2.request().setFeatureNameQuery("duplicated"); builder2.request().setStore(IndexFeatureStore.DEFAULT_STORE); @@ -143,7 +143,7 @@ public void testMergeWithQuery() throws Exception { addElement(randomFeature("duplicated")); addElement(randomFeature("new_feature")); - AddFeaturesToSetRequestBuilder builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetRequestBuilder builder= new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("merged_set"); builder.request().setFeatureNameQuery("duplicated*"); builder.request().setStore(IndexFeatureStore.DEFAULT_STORE); @@ -153,7 +153,7 @@ public void testMergeWithQuery() throws Exception { assertEquals(DocWriteResponse.Result.CREATED, resp.getResponse().getResult()); assertEquals(1, resp.getResponse().getVersion()); - builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + builder= new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("merged_set"); builder.request().setFeatureNameQuery("*"); builder.request().setStore(IndexFeatureStore.DEFAULT_STORE); @@ -176,7 +176,7 @@ public void testMergeWithList() throws Exception { features.add(feat); } - AddFeaturesToSetRequestBuilder builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetRequestBuilder builder= new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("new_feature_set"); builder.request().setFeatures(features); builder.request().setMerge(true); @@ -191,7 +191,7 @@ public void testMergeWithList() throws Exception { assertEquals(features.size(), set.size()); assertTrue(features.stream().map(StoredFeature::name).allMatch(set::hasFeature)); - builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + builder= new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("new_feature_set"); builder.request().setFeatures(asList(randomFeature("another_feature"), randomFeature("feature0"))); builder.request().setMerge(true); diff --git a/src/test/java/com/o19s/es/ltr/action/BaseIntegrationTest.java b/src/test/java/com/o19s/es/ltr/action/BaseIntegrationTest.java index 292312ab..15aff3cf 100644 --- a/src/test/java/com/o19s/es/ltr/action/BaseIntegrationTest.java +++ b/src/test/java/com/o19s/es/ltr/action/BaseIntegrationTest.java @@ -35,7 +35,6 @@ import org.elasticsearch.script.ScoreScript; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptEngine; -import org.elasticsearch.script.SearchScript; import org.elasticsearch.test.ESSingleNodeTestCase; import org.junit.Before; @@ -48,6 +47,8 @@ import static com.o19s.es.ltr.feature.store.ScriptFeature.FEATURE_VECTOR; public abstract class BaseIntegrationTest extends ESSingleNodeTestCase { + + public static final ScriptContext AGGS_CONTEXT = new ScriptContext<>("aggs", ScoreScript.Factory.class); @Override protected Collection> getPlugins() { return Arrays.asList(LtrQueryParserPlugin.class, NativeScriptPlugin.class); @@ -105,7 +106,8 @@ protected LtrRankerParserFactory parserFactory() { public FeatureStoreResponse addElement(StorableElement element, @Nullable FeatureValidation validation, String store) throws ExecutionException, InterruptedException { - FeatureStoreRequestBuilder builder = FeatureStoreAction.INSTANCE.newRequestBuilder(client()); + FeatureStoreRequestBuilder builder = + new FeatureStoreRequestBuilder(client(), FeatureStoreAction.INSTANCE); builder.request().setStorableElement(element); builder.request().setAction(FeatureStoreAction.FeatureStoreRequest.Action.CREATE); builder.request().setStore(store); @@ -147,7 +149,7 @@ public String getType() { @Override public FactoryType compile(String scriptName, String scriptSource, ScriptContext context, Map params) { - if (!context.equals(ScoreScript.CONTEXT) && (!context.equals(SearchScript.AGGS_CONTEXT))) { + if (!context.equals(ScoreScript.CONTEXT) && (!context.equals(AGGS_CONTEXT))) { throw new IllegalArgumentException(getType() + " scripts cannot be used for context [" + context.name + "]"); } diff --git a/src/test/java/com/o19s/es/ltr/action/ListStoresActionIT.java b/src/test/java/com/o19s/es/ltr/action/ListStoresActionIT.java index d2f20b36..db6feed5 100644 --- a/src/test/java/com/o19s/es/ltr/action/ListStoresActionIT.java +++ b/src/test/java/com/o19s/es/ltr/action/ListStoresActionIT.java @@ -41,7 +41,7 @@ public void testListStore() throws Exception { infos.put(IndexFeatureStore.storeName(store), new IndexStoreInfo(store, IndexFeatureStore.VERSION, addElements(store))); } - ListStoresActionResponse resp = ListStoresAction.INSTANCE.newRequestBuilder(client()).execute().get(); + ListStoresActionResponse resp = new ListStoresAction.ListStoresActionBuilder(client()).execute().get(); assertEquals(infos.size(), resp.getStores().size()); assertEquals(infos.keySet(), resp.getStores().keySet()); for (String k : infos.keySet()) { diff --git a/src/test/java/com/o19s/es/ltr/action/ValidatingFeatureStoreActionIT.java b/src/test/java/com/o19s/es/ltr/action/ValidatingFeatureStoreActionIT.java index d973494c..e55b7d3b 100644 --- a/src/test/java/com/o19s/es/ltr/action/ValidatingFeatureStoreActionIT.java +++ b/src/test/java/com/o19s/es/ltr/action/ValidatingFeatureStoreActionIT.java @@ -90,7 +90,7 @@ public void testValidationOnAddFeatureToSet() { StoredFeature brokenFeature = new StoredFeature("broken", singletonList("query_string"), "mustache", brokenQuery); Map params = new HashMap<>(); params.put("query_string", "a query"); - AddFeaturesToSetAction.AddFeaturesToSetRequestBuilder request = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetAction.AddFeaturesToSetRequestBuilder request = new AddFeaturesToSetAction.AddFeaturesToSetRequestBuilder(client()); request.request().setStore(IndexFeatureStore.DEFAULT_STORE); request.request().setValidation(new FeatureValidation("test_index", params)); request.request().setFeatures(Arrays.asList(feature, brokenFeature)); @@ -112,7 +112,8 @@ public void testValidationOnCreateModelFromSet() throws ExecutionException, Inte StoredFeatureSet brokenFeatureSet = new StoredFeatureSet("my_feature_set", Arrays.asList(feature, brokenFeature)); // Store a broken feature set addElement(brokenFeatureSet); - CreateModelFromSetAction.CreateModelFromSetRequestBuilder request = CreateModelFromSetAction.INSTANCE.newRequestBuilder(client()); + CreateModelFromSetAction.CreateModelFromSetRequestBuilder request = + new CreateModelFromSetAction.CreateModelFromSetRequestBuilder(client()); request.request().setValidation(new FeatureValidation("test_index", params)); StoredLtrModel.LtrModelDefinition definition = new StoredLtrModel.LtrModelDefinition("model/linear", "{\"test\": 2.1, \"broken\": 4.3}", true); diff --git a/src/test/java/com/o19s/es/ltr/logging/LoggingFetchSubPhaseTests.java b/src/test/java/com/o19s/es/ltr/logging/LoggingFetchSubPhaseTests.java index 441c5d83..2ae6d0b5 100644 --- a/src/test/java/com/o19s/es/ltr/logging/LoggingFetchSubPhaseTests.java +++ b/src/test/java/com/o19s/es/ltr/logging/LoggingFetchSubPhaseTests.java @@ -16,7 +16,6 @@ package com.o19s.es.ltr.logging; -import com.o19s.es.ltr.LtrTestUtils; import com.o19s.es.ltr.feature.PrebuiltFeature; import com.o19s.es.ltr.feature.PrebuiltFeatureSet; import com.o19s.es.ltr.feature.PrebuiltLtrModel; @@ -34,10 +33,10 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.SimpleCollector; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.Directory; @@ -62,7 +61,6 @@ import java.util.Map; import java.util.UUID; -import static java.util.Collections.singletonList; import static org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction.Modifier.LN2P; import static org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType.FLOAT; @@ -148,22 +146,19 @@ public void testLogging() throws IOException { } } - public void testBogusQuery() throws IOException { - PrebuiltFeatureSet set = new PrebuiltFeatureSet("test", - singletonList(new PrebuiltFeature("test", new BoostQuery(new MatchAllDocsQuery(), Float.NaN)))); - LoggingFetchSubPhase.HitLogConsumer logger1 = new LoggingFetchSubPhase.HitLogConsumer("logger1", set, true); - RankerQuery q = RankerQuery.build(new PrebuiltLtrModel("test", LtrTestUtils.buildRandomRanker(set.size()), set)); - Query lq = q.toLoggerQuery(logger1, true); - LoggingFetchSubPhase subPhase = new LoggingFetchSubPhase(); - SearchHit[] hits = selectRandomHits(); - expectThrows(LtrLoggingException.class, () -> subPhase.doLog(lq, singletonList(logger1), searcher, hits)); - } - public SearchHit[] selectRandomHits() throws IOException { int minHits = TestUtil.nextInt(random(), 5, 10); int maxHits = TestUtil.nextInt(random(), minHits, minHits+10); List hits = new ArrayList<>(maxHits); searcher.search(new MatchAllDocsQuery(), new SimpleCollector() { + /** + * Indicates what features are required from the scorer. + */ + @Override + public ScoreMode scoreMode() { + return ScoreMode.COMPLETE_NO_SCORES; + } + LeafReaderContext context; @Override @@ -183,10 +178,6 @@ public void collect(int doc) throws IOException { } } - @Override - public boolean needsScores() { - return false; - } }); assert hits.size() >= minHits; Collections.shuffle(hits, random()); diff --git a/src/test/java/com/o19s/es/ltr/query/LtrQueryBuilderTests.java b/src/test/java/com/o19s/es/ltr/query/LtrQueryBuilderTests.java index b5a82d63..6c727ab2 100644 --- a/src/test/java/com/o19s/es/ltr/query/LtrQueryBuilderTests.java +++ b/src/test/java/com/o19s/es/ltr/query/LtrQueryBuilderTests.java @@ -232,4 +232,10 @@ public void testMustRewrite() throws IOException { protected void doAssertLuceneQuery(LtrQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException { assertThat(query, instanceOf(RankerQuery.class)); } + + @Override + protected boolean isCacheable(LtrQueryBuilder queryBuilder){ + return false; + } + } diff --git a/src/test/java/com/o19s/es/ltr/query/LtrQueryTests.java b/src/test/java/com/o19s/es/ltr/query/LtrQueryTests.java index 7f6e4681..adb731ac 100644 --- a/src/test/java/com/o19s/es/ltr/query/LtrQueryTests.java +++ b/src/test/java/com/o19s/es/ltr/query/LtrQueryTests.java @@ -47,15 +47,16 @@ import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.Query; +import org.apache.lucene.search.Scorable; import org.apache.lucene.search.ScoreDoc; -import org.apache.lucene.search.Scorer; +import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.SimpleCollector; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.similarities.AfterEffectB; import org.apache.lucene.search.similarities.AxiomaticF3LOG; import org.apache.lucene.search.similarities.BM25Similarity; -import org.apache.lucene.search.similarities.BasicModelBE; +import org.apache.lucene.search.similarities.BasicModelG; import org.apache.lucene.search.similarities.BooleanSimilarity; import org.apache.lucene.search.similarities.ClassicSimilarity; import org.apache.lucene.search.similarities.DFISimilarity; @@ -140,7 +141,7 @@ public void setupIndex() throws IOException { new LMJelinekMercerSimilarity(0.2F), new AxiomaticF3LOG(0.5F, 10), new DFISimilarity(new IndependenceChiSquared()), - new DFRSimilarity(new BasicModelBE(), new AfterEffectB(), new NormalizationH1()), + new DFRSimilarity(new BasicModelG(), new AfterEffectB(), new NormalizationH1()), new IBSimilarity(new DistributionLL(), new LambdaDF(), new NormalizationH3()) ); similarity = sims.get(random().nextInt(sims.size())); @@ -181,15 +182,19 @@ public void reset() { RankerQuery query = RankerQuery.buildLogQuery(logger, set, null, Collections.emptyMap()); searcherUnderTest.search(query, new SimpleCollector() { + private LeafReaderContext context; - private Scorer scorer; + private Scorable scorer; + /** + * Indicates what features are required from the scorer. + */ @Override - public boolean needsScores() { - return true; + public ScoreMode scoreMode() { + return ScoreMode.COMPLETE; } @Override - public void setScorer(Scorer scorer) throws IOException { + public void setScorer(Scorable scorer) throws IOException { this.scorer = scorer; } @@ -268,7 +273,7 @@ public void checkModelWithFeatures(List features, int[] modelFe // each RankList appears to correspond to a // query RankerTrainer trainer = new RankerTrainer(); - Ranker ranker = trainer.train(/*what type of model ot train*/RANKER_TYPE.LAMBDAMART, + Ranker ranker = trainer.train(/*what type of model ot train*/RANKER_TYPE.RANKNET, /*The training data*/ samples /*which features to use*/, featuresToUse /*how to score ranking*/, new NDCGScorer()); @@ -324,7 +329,7 @@ private void assertScoresMatch(List features, float[] scores, // It produces 0.56103003 for feat:0 in doc1 using score() but 0.5610301 using explain Explanation expl = searcherUnderTest.explain(ltrQuery, docId); - assertEquals("Explain scores match with similarity " + similarity.getClass(), expl.getValue(), + assertEquals("Explain scores match with similarity " + similarity.getClass(), expl.getValue().floatValue(), queryScore, 5 * Math.ulp(modelScore)); checkFeatureNames(expl, features); } diff --git a/src/test/java/com/o19s/es/ltr/query/StoredLtrQueryBuilderTests.java b/src/test/java/com/o19s/es/ltr/query/StoredLtrQueryBuilderTests.java index 1f1b508b..a539d5f8 100644 --- a/src/test/java/com/o19s/es/ltr/query/StoredLtrQueryBuilderTests.java +++ b/src/test/java/com/o19s/es/ltr/query/StoredLtrQueryBuilderTests.java @@ -235,4 +235,9 @@ protected FeatureStoreLoader getFeatureStoreLoader() { return LtrTestUtils.wrapMemStore(StoredLtrQueryBuilderTests.store); } } + + @Override + protected boolean isCacheable(StoredLtrQueryBuilder queryBuilder){ + return false; + } } diff --git a/src/test/java/com/o19s/es/ltr/query/StoredLtrQueryIT.java b/src/test/java/com/o19s/es/ltr/query/StoredLtrQueryIT.java index ae61d71d..6368a526 100644 --- a/src/test/java/com/o19s/es/ltr/query/StoredLtrQueryIT.java +++ b/src/test/java/com/o19s/es/ltr/query/StoredLtrQueryIT.java @@ -18,13 +18,11 @@ package com.o19s.es.ltr.query; import com.o19s.es.ltr.LtrTestUtils; -import com.o19s.es.ltr.action.AddFeaturesToSetAction; import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetRequestBuilder; import com.o19s.es.ltr.action.BaseIntegrationTest; import com.o19s.es.ltr.action.CachesStatsAction; import com.o19s.es.ltr.action.CachesStatsAction.CachesStatsNodesResponse; import com.o19s.es.ltr.action.ClearCachesAction; -import com.o19s.es.ltr.action.CreateModelFromSetAction; import com.o19s.es.ltr.action.CreateModelFromSetAction.CreateModelFromSetRequestBuilder; import com.o19s.es.ltr.feature.store.ScriptFeature; import com.o19s.es.ltr.feature.store.StoredFeature; @@ -72,7 +70,7 @@ public void testScriptFeatureUseCase() throws Exception { addElement(new StoredFeature("feature6", Arrays.asList("query", "extra_multiplier_ltr"), ScriptFeature.TEMPLATE_LANGUAGE, "{\"lang\": \"native\", \"source\": \"feature_extractor\", \"params\": { \"dependent_feature\": \"feature1\"," + " \"extra_script_params\" : {\"extra_multiplier_ltr\": \"extra_multiplier\"}}}")); - AddFeaturesToSetRequestBuilder builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("my_set"); builder.request().setFeatureNameQuery("feature1"); @@ -81,7 +79,7 @@ public void testScriptFeatureUseCase() throws Exception { builder.request().setFeatureNameQuery("feature6"); long version = builder.get().getResponse().getVersion(); - CreateModelFromSetRequestBuilder createModelFromSetRequestBuilder = CreateModelFromSetAction.INSTANCE.newRequestBuilder(client()); + CreateModelFromSetRequestBuilder createModelFromSetRequestBuilder = new CreateModelFromSetRequestBuilder(client()); createModelFromSetRequestBuilder.withVersion(IndexFeatureStore.DEFAULT_STORE, "my_set", version, "my_model", new StoredLtrModel.LtrModelDefinition("model/linear", SIMPLE_SCRIPT_MODEL, true)); createModelFromSetRequestBuilder.get(); @@ -99,7 +97,7 @@ public void testScriptFeatureUseCase() throws Exception { .setRescoreQueryWeight(1)); SearchResponse sr = sb.get(); - assertEquals(1, sr.getHits().getTotalHits()); + assertEquals(1, sr.getHits().getTotalHits().value); assertThat(sr.getHits().getAt(0).getScore(), Matchers.greaterThanOrEqualTo(29.0f)); assertThat(sr.getHits().getAt(0).getScore(), Matchers.lessThanOrEqualTo(30.0f)); } @@ -119,7 +117,7 @@ public void testFullUsecase() throws Exception { "{\"lang\": \"native\", \"source\": \"feature_extractor\", \"params\": { \"dependent_feature\": \"feature1\"}}")); - AddFeaturesToSetRequestBuilder builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("my_set"); builder.request().setFeatureNameQuery("feature1"); builder.request().setStore(IndexFeatureStore.DEFAULT_STORE); @@ -140,7 +138,7 @@ public void testFullUsecase() throws Exception { builder.request().setFeatureNameQuery("feature6"); long version = builder.get().getResponse().getVersion(); - CreateModelFromSetRequestBuilder createModelFromSetRequestBuilder = CreateModelFromSetAction.INSTANCE.newRequestBuilder(client()); + CreateModelFromSetRequestBuilder createModelFromSetRequestBuilder = new CreateModelFromSetRequestBuilder(client()); createModelFromSetRequestBuilder.withVersion(IndexFeatureStore.DEFAULT_STORE, "my_set", version, "my_model", new StoredLtrModel.LtrModelDefinition("model/linear", SIMPLE_MODEL, true)); createModelFromSetRequestBuilder.get(); @@ -160,7 +158,7 @@ public void testFullUsecase() throws Exception { .setRescoreQueryWeight(1)); SearchResponse sr = sb.get(); - assertEquals(1, sr.getHits().getTotalHits()); + assertEquals(1, sr.getHits().getTotalHits().value); if (negativeScore) { assertThat(sr.getHits().getAt(0).getScore(), Matchers.lessThanOrEqualTo(-10.0f)); @@ -181,7 +179,7 @@ public void testFullUsecase() throws Exception { .setRescoreQueryWeight(1)); sr = sb.get(); - assertEquals(1, sr.getHits().getTotalHits()); + assertEquals(1, sr.getHits().getTotalHits().value); if (negativeScore) { assertThat(sr.getHits().getAt(0).getScore(), Matchers.lessThanOrEqualTo(-10.0f)); @@ -212,7 +210,7 @@ public void testFullUsecase() throws Exception { .setRescoreQueryWeight(1)); sr = sb.get(); - assertEquals(1, sr.getHits().getTotalHits()); + assertEquals(1, sr.getHits().getTotalHits().value); assertThat(sr.getHits().getAt(0).getScore(), Matchers.greaterThan(0.0f)); assertThat(sr.getHits().getAt(0).getScore(), Matchers.lessThanOrEqualTo(1.0f)); @@ -227,7 +225,7 @@ public void testFullUsecase() throws Exception { .setQueryWeight(0) .setRescoreQueryWeight(1)); sr = sb.get(); - assertEquals(1, sr.getHits().getTotalHits()); + assertEquals(1, sr.getHits().getTotalHits().value); assertThat(sr.getHits().getAt(0).getScore(), Matchers.greaterThan(28.0f)); assertThat(sr.getHits().getAt(0).getScore(), Matchers.lessThan(30.0f)); @@ -242,7 +240,7 @@ public void testFullUsecase() throws Exception { .setQueryWeight(0) .setRescoreQueryWeight(1)); sr = sb.get(); - assertEquals(1, sr.getHits().getTotalHits()); + assertEquals(1, sr.getHits().getTotalHits().value); assertThat(sr.getHits().getAt(0).getScore(), Matchers.lessThan(-28.0f)); assertThat(sr.getHits().getAt(0).getScore(), Matchers.greaterThan(-30.0f)); @@ -257,11 +255,11 @@ public void testFullUsecase() throws Exception { .setQueryWeight(0) .setRescoreQueryWeight(1)); sr = sb.get(); - assertEquals(1, sr.getHits().getTotalHits()); + assertEquals(1, sr.getHits().getTotalHits().value); assertThat(sr.getHits().getAt(0).getScore(), Matchers.greaterThan(0.2876f + 2.876f)); StoredLtrModel model = getElement(StoredLtrModel.class, StoredLtrModel.TYPE, "my_model"); - CachesStatsNodesResponse stats = CachesStatsAction.INSTANCE.newRequestBuilder(client()).execute().get(); + CachesStatsNodesResponse stats = new CachesStatsAction.CachesStatsActionBuilder(client()).execute().get(); assertEquals(1, stats.getAll().getTotal().getCount()); assertEquals(model.compile(parserFactory()).ramBytesUsed(), stats.getAll().getTotal().getRam()); assertEquals(1, stats.getAll().getModels().getCount()); @@ -271,11 +269,11 @@ public void testFullUsecase() throws Exception { assertEquals(0, stats.getAll().getFeaturesets().getCount()); assertEquals(0, stats.getAll().getFeaturesets().getRam()); - ClearCachesAction.RequestBuilder clearCache = ClearCachesAction.INSTANCE.newRequestBuilder(client()); + ClearCachesAction.RequestBuilder clearCache = new ClearCachesAction.RequestBuilder(client()); clearCache.request().clearModel(IndexFeatureStore.DEFAULT_STORE, "my_model"); clearCache.get(); - stats = CachesStatsAction.INSTANCE.newRequestBuilder(client()).execute().get(); + stats = new CachesStatsAction.CachesStatsActionBuilder(client()).execute().get(); assertEquals(0, stats.getAll().getTotal().getCount()); assertEquals(0, stats.getAll().getTotal().getRam()); @@ -285,7 +283,7 @@ public void testInvalidDerived() throws Exception { addElement(new StoredFeature("bad_df", Collections.singletonList("query"), "derived_expression", "what + is + this")); - AddFeaturesToSetRequestBuilder builder = AddFeaturesToSetAction.INSTANCE.newRequestBuilder(client()); + AddFeaturesToSetRequestBuilder builder = new AddFeaturesToSetRequestBuilder(client()); builder.request().setFeatureSet("my_bad_set"); builder.request().setFeatureNameQuery("bad_df"); builder.request().setStore(IndexFeatureStore.DEFAULT_STORE); diff --git a/src/test/resources/rest-api-spec/test/fstore/20_features.yml b/src/test/resources/rest-api-spec/test/fstore/20_features.yml index 36df7d94..633baf82 100644 --- a/src/test/resources/rest-api-spec/test/fstore/20_features.yml +++ b/src/test/resources/rest-api-spec/test/fstore/20_features.yml @@ -60,19 +60,19 @@ - do: ltr.list_feature: {} - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_feature: prefix: my - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_feature: prefix: hop - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - do: ltr.delete_feature: @@ -155,21 +155,21 @@ ltr.list_feature: store: mystore - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_feature: store: mystore prefix: my - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_feature: store: mystore prefix: hop - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - do: ltr.delete_feature: diff --git a/src/test/resources/rest-api-spec/test/fstore/30_featuresets.yml b/src/test/resources/rest-api-spec/test/fstore/30_featuresets.yml index 35fa0681..a3eed333 100644 --- a/src/test/resources/rest-api-spec/test/fstore/30_featuresets.yml +++ b/src/test/resources/rest-api-spec/test/fstore/30_featuresets.yml @@ -73,19 +73,19 @@ - do: ltr.list_featureset: {} - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_featureset: prefix: my - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_featureset: prefix: hop - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - do: ltr.delete_featureset: @@ -180,21 +180,21 @@ ltr.list_featureset: store: mystore - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_featureset: store: mystore prefix: my - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_featureset: store: mystore prefix: hop - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - do: ltr.delete_featureset: diff --git a/src/test/resources/rest-api-spec/test/fstore/40_models.yml b/src/test/resources/rest-api-spec/test/fstore/40_models.yml index 82578c03..c939a6c4 100644 --- a/src/test/resources/rest-api-spec/test/fstore/40_models.yml +++ b/src/test/resources/rest-api-spec/test/fstore/40_models.yml @@ -66,19 +66,19 @@ - do: ltr.list_model: {} - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_model: prefix: my - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_model: prefix: hop - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - do: ltr.delete_model: @@ -164,21 +164,21 @@ ltr.list_model: store: mystore - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_model: store: mystore prefix: my - - match: { hits.total: 1 } + - match: { hits.total.value: 1 } - do: ltr.list_model: store: mystore prefix: hop - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - do: ltr.delete_model: diff --git a/src/test/resources/rest-api-spec/test/fstore/80_search_w_partial_models.yml b/src/test/resources/rest-api-spec/test/fstore/80_search_w_partial_models.yml index de005bf7..4434990e 100644 --- a/src/test/resources/rest-api-spec/test/fstore/80_search_w_partial_models.yml +++ b/src/test/resources/rest-api-spec/test/fstore/80_search_w_partial_models.yml @@ -84,10 +84,10 @@ setup: 1 1.0 - -2.0 + 2.0 - 2.0 + 4.0