blob: a551c465ca5fc57ee813cd7267e3b6e87712cef5 [file] [log] [blame]
/*
* 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.analytics.facet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
public class QueryFacetTest extends SolrAnalyticsFacetTestCase {
@BeforeClass
public static void populate() throws Exception {
for (int j = 0; j < NUM_LOOPS; ++j) {
int i = j%INT;
long l = j%LONG;
float f = j%FLOAT;
double d = j%DOUBLE;
String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
String dtm = (1800+j%DATE + 10) + "-12-31T23:59:59Z";
String s = "str" + (j%STRING);
List<String> fields = new ArrayList<>();
fields.add("id"); fields.add("1000"+j);
if ( i != 0 ) {
fields.add("int_i"); fields.add("" + i);
fields.add("int_im"); fields.add("" + i);
fields.add("int_im"); fields.add("" + (i+10));
}
if ( l != 0l ) {
fields.add("long_l"); fields.add("" + l);
fields.add("long_lm"); fields.add("" + l);
fields.add("long_lm"); fields.add("" + (l+10));
}
if ( f != 0.0f ) {
fields.add("float_f"); fields.add("" + f);
fields.add("float_fm"); fields.add("" + f);
fields.add("float_fm"); fields.add("" + (f+10));
}
if ( d != 0.0d ) {
fields.add("double_d"); fields.add("" + d);
fields.add("double_dm"); fields.add("" + d);
fields.add("double_dm"); fields.add("" + (d+10));
}
if ( (j%DATE) != 0 ) {
fields.add("date_dt"); fields.add(dt);
fields.add("date_dtm"); fields.add(dt);
fields.add("date_dtm"); fields.add(dtm);
}
if ( (j%STRING) != 0 ) {
fields.add("string_s"); fields.add(s);
fields.add("string_sm"); fields.add(s);
fields.add("string_sm"); fields.add(s + "_second");
}
addDoc(fields);
}
commitDocs();
}
static public final int INT = 7;
static public final int LONG = 2;
static public final int FLOAT = 6;
static public final int DOUBLE = 5;
static public final int DATE = 3;
static public final int STRING = 4;
static public final int NUM_LOOPS = 20;
@Test
public void queryFacetTest() throws Exception {
Map<String, String> expressions = new HashMap<>();
expressions.put("mean", "mean(int_i)");
expressions.put("count", "count(string_sm)");
// Value Facet "with_missing"
addFacet("with_missing", "{ 'type':'query', 'queries':{'q1':'long_l:1 AND float_f:1.0','q2':'double_dm:[3 TO 11] OR double_dm:1'}}");
addFacetValue("q1");
addFacetResult("mean", 4.0);
addFacetResult("count", 8L);
addFacetValue("q2");
addFacetResult("mean", 38.0/11.0);
addFacetResult("count", 18L);
testGrouping(expressions);
}
}