/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.solr.ltr.feature;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.ltr.TestRerankBase;
import org.apache.solr.ltr.model.LinearModel;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TestEdisMaxSolrFeature extends TestRerankBase {

  @Before
  public void before() throws Exception {
    setuptest(false);

    assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",
        "1"));
    assertU(adoc("id", "2", "title", "w2 2asd asdd didid", "description",
        "w2 2asd asdd didid", "popularity", "2"));
    assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity",
        "3"));
    assertU(adoc("id", "4", "title", "w4", "description", "w4", "popularity",
        "4"));
    assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity",
        "5"));
    assertU(adoc("id", "6", "title", "w1 w2", "description", "w1 w2",
        "popularity", "6"));
    assertU(adoc("id", "7", "title", "w1 w2 w3 w4 w5", "description",
        "w1 w2 w3 w4 w5 w8", "popularity", "7"));
    assertU(adoc("id", "8", "title", "w1 w1 w1 w2 w2 w8", "description",
        "w1 w1 w1 w2 w2", "popularity", "8"));
    assertU(commit());
  }

  @After
  public void after() throws Exception {
    aftertest();
  }

  @Test
  public void testEdisMaxSolrFeature() throws Exception {
    loadFeature(
        "SomeEdisMax",
        SolrFeature.class.getName(),
        "{\"q\":\"{!edismax qf='title description' pf='description' mm=100% boost='pow(popularity, 0.1)' v='w1' tie=0.1}\"}");

    loadModel("EdisMax-model", LinearModel.class.getName(),
        new String[] {"SomeEdisMax"}, "{\"weights\":{\"SomeEdisMax\":1.0}}");

    final SolrQuery query = new SolrQuery();
    query.setQuery("title:w1");
    query.add("fl", "*, score");
    query.add("rows", "4");

    query.add("rq", "{!ltr model=EdisMax-model reRankDocs=4}");
    query.set("debugQuery", "on");
    restTestHarness.query("/query" + query.toQueryString());
    assertJQ("/query" + query.toQueryString(), "/response/numFound/==4");
  }
}

@@ -1018,16 +1018,41 @@
 Before;%0A
+import org.junit.Ignore;%0A
 import o
@@ -2926,11 +2926,713 @@
 4%22);%0A  %7D
+%0A%0A  @Ignore(%22SOLR-15071%22)%0A  @Test%0A  public void testEdisMaxSolrFeatureCustomMM() throws Exception %7B%0A    loadFeature(%0A        %22SomeEdisMaxMM1%22,%0A        SolrFeature.class.getName(),%0A        %22%7B%5C%22q%5C%22:%5C%22%7B!edismax qf='title' mm=1%7D$%7Bterm%7D%5C%22%7D%22);%0A    loadFeature(%0A        %22SomeEdisMaxMM5%22,%0A        SolrFeature.class.getName(),%0A        %22%7B%5C%22q%5C%22:%5C%22%7B!edismax qf='title' mm=5%7D$%7Bterm%7D%5C%22%7D%22);%0A%0A    final SolrQuery query = new SolrQuery();%0A    query.setQuery(%22title:w1 w2 w3 w4 w5 w6 w7 w8%22);%0A    query.add(%22fl%22, %22*,features:%5Bfv store=test efi.term=%5C%22w1 w2 w3 w4 w5 w6 w7 w8%5C%22%5D%22);%0A%0A    restTestHarness.query(%22/query%22 + query.toQueryString());%0A    assertJQ(%22/query%22 + query.toQueryString(), %22/response/numFound/==4%22);%0A  %7D
 %0A%7D%0A

add TestEdisMaxSolrFeature.testEdisMaxSolrFeatureCustomMM() test case (#2201)