コード例 #1
0
  @Test
  public void testQueryText() {

    Float boost = 0.7f;
    Object[] values = new Object[] {"houses", "cats"};

    Schema schema = schema().mapper("name", textMapper()).defaultAnalyzer("english").build();

    ContainsCondition condition = new ContainsCondition(boost, "name", values);
    Query query = condition.query(schema);
    assertNotNull("Query is not built", query);
    assertEquals("Query type is wrong", BooleanQuery.class, query.getClass());

    BooleanQuery booleanQuery = (BooleanQuery) query;
    assertEquals("Query boost is wrong", 0.7f, query.getBoost(), 0);
    BooleanClause[] clauses = booleanQuery.getClauses();
    assertEquals(
        "Query is wrong",
        "hous",
        ((TermQuery) clauses[0].getQuery()).getTerm().bytes().utf8ToString());
    assertEquals(
        "Query is wrong",
        "cat",
        ((TermQuery) clauses[1].getQuery()).getTerm().bytes().utf8ToString());
  }
コード例 #2
0
 @Test
 public void testToString() {
   ContainsCondition condition = new ContainsCondition(0.7f, "field", "value1", "value2");
   assertEquals(
       "Method #toString is wrong",
       "ContainsCondition{boost=0.7, field=field, values=[value1, value2]}",
       condition.toString());
 }
コード例 #3
0
  @Test
  public void testQueryNumeric() {

    Float boost = 0.7f;
    Object[] values = new Object[] {1, 2, 3};

    Schema schema = schema().mapper("name", integerMapper()).build();

    ContainsCondition condition = new ContainsCondition(boost, "name", values);
    Query query = condition.query(schema);
    assertNotNull("Query is not built", query);
    assertEquals("Query type is wrong", BooleanQuery.class, query.getClass());

    BooleanQuery booleanQuery = (BooleanQuery) query;
    assertEquals("Boost is not set", 0.7f, query.getBoost(), 0);
    BooleanClause[] clauses = booleanQuery.getClauses();
    assertEquals("Query is wrong", values.length, clauses.length);
    for (int i = 0; i < values.length; i++) {
      NumericRangeQuery<?> numericRangeQuery = (NumericRangeQuery<?>) clauses[i].getQuery();
      assertEquals("Query is wrong", values[i], numericRangeQuery.getMin());
      assertEquals("Query is wrong", values[i], numericRangeQuery.getMax());
    }
  }