FileDocCategorySizeDatePackage
TestComplexExplanations.javaAPI DocApache Lucene 2.1.08126Wed Feb 14 10:46:36 GMT 2007org.apache.lucene.search

TestComplexExplanations

public class TestComplexExplanations extends TestExplanations
TestExplanations subclass that builds up super crazy complex queries on the assumption that if the explanations work out right for them, they should work for anything.

Fields Summary
Constructors Summary
Methods Summary
public voidsetUp()
Override the Similarity used in our searcher with one that plays nice with boosts of 0.0

    super.setUp();
    searcher.setSimilarity(new DefaultSimilarity() {
        public float queryNorm(float sumOfSquaredWeights) {
          return 1.0f; // / (float) Math.sqrt(1.0f + sumOfSquaredWeights);
        }
      });
  
public voidtest1()

    
    BooleanQuery q = new BooleanQuery();
    
    q.add(qp.parse("\"w1 w2\"~1"), Occur.MUST);
    q.add(snear(st("w2"),
                sor("w5","zz"),
                4, true),
          Occur.SHOULD);
    q.add(snear(sf("w3",2), st("w2"), st("w3"), 5, true),
          Occur.SHOULD);
    
    Query t = new FilteredQuery(qp.parse("xx"),
                                new ItemizedFilter(new int[] {1,3}));
    t.setBoost(1000);
    q.add(t, Occur.SHOULD);
    
    t = new ConstantScoreQuery(new ItemizedFilter(new int[] {0,2}));
    t.setBoost(30);
    q.add(t, Occur.SHOULD);
    
    DisjunctionMaxQuery dm = new DisjunctionMaxQuery(0.2f);
    dm.add(snear(st("w2"),
                 sor("w5","zz"),
                 4, true));
    dm.add(qp.parse("QQ"));
    dm.add(qp.parse("xx yy -zz"));
    dm.add(qp.parse("-xx -w1"));

    DisjunctionMaxQuery dm2 = new DisjunctionMaxQuery(0.5f);
    dm2.add(qp.parse("w1"));
    dm2.add(qp.parse("w2"));
    dm2.add(qp.parse("w3"));
    dm.add(dm2);

    q.add(dm, Occur.SHOULD);

    BooleanQuery b = new BooleanQuery();
    b.setMinimumNumberShouldMatch(2);
    b.add(snear("w1","w2",1,true), Occur.SHOULD);
    b.add(snear("w2","w3",1,true), Occur.SHOULD);
    b.add(snear("w1","w3",3,true), Occur.SHOULD);

    q.add(b, Occur.SHOULD);
    
    qtest(q, new int[] { 0,1,2 });
  
public voidtest2()

    
    BooleanQuery q = new BooleanQuery();
    
    q.add(qp.parse("\"w1 w2\"~1"), Occur.MUST);
    q.add(snear(st("w2"),
                sor("w5","zz"),
                4, true),
          Occur.SHOULD);
    q.add(snear(sf("w3",2), st("w2"), st("w3"), 5, true),
          Occur.SHOULD);
    
    Query t = new FilteredQuery(qp.parse("xx"),
                                new ItemizedFilter(new int[] {1,3}));
    t.setBoost(1000);
    q.add(t, Occur.SHOULD);
    
    t = new ConstantScoreQuery(new ItemizedFilter(new int[] {0,2}));
    t.setBoost(-20.0f);
    q.add(t, Occur.SHOULD);
    
    DisjunctionMaxQuery dm = new DisjunctionMaxQuery(0.2f);
    dm.add(snear(st("w2"),
                 sor("w5","zz"),
                 4, true));
    dm.add(qp.parse("QQ"));
    dm.add(qp.parse("xx yy -zz"));
    dm.add(qp.parse("-xx -w1"));

    DisjunctionMaxQuery dm2 = new DisjunctionMaxQuery(0.5f);
    dm2.add(qp.parse("w1"));
    dm2.add(qp.parse("w2"));
    dm2.add(qp.parse("w3"));
    dm.add(dm2);

    q.add(dm, Occur.SHOULD);

    BooleanQuery b = new BooleanQuery();
    b.setMinimumNumberShouldMatch(2);
    b.add(snear("w1","w2",1,true), Occur.SHOULD);
    b.add(snear("w2","w3",1,true), Occur.SHOULD);
    b.add(snear("w1","w3",3,true), Occur.SHOULD);
    b.setBoost(0.0f);
    
    q.add(b, Occur.SHOULD);
    
    qtest(q, new int[] { 0,1,2 });
  
public voidtestBQ12()

    // NOTE: using qtest not bqtest
    qtest("w1 w2^0.0", new int[] { 0,1,2,3 });
  
public voidtestBQ13()

    // NOTE: using qtest not bqtest
    qtest("w1 -w5^0.0", new int[] { 1,2,3 });
  
public voidtestBQ18()

    // NOTE: using qtest not bqtest
    qtest("+w1^0.0 w2", new int[] { 0,1,2,3 });
  
public voidtestBQ21()

    bqtest("(+w1 w2)^0.0", new int[] { 0,1,2,3 });
  
public voidtestBQ22()

    bqtest("(+w1^0.0 w2)^0.0", new int[] { 0,1,2,3 });
  
public voidtestCSQ4()

    Query q = new ConstantScoreQuery(new ItemizedFilter(new int[] {3}));
    q.setBoost(0);
    bqtest(q, new int[] {3});
  
public voidtestDMQ10()

    DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.5f);
    q.add(qp.parse("yy w5^100"));
    q.add(qp.parse("xx^0"));
    q.setBoost(0.0f);
    bqtest(q, new int[] { 0,2,3 });
  
public voidtestFQ5()

    bqtest(new FilteredQuery(qp.parse("xx^0"),
                             new ItemizedFilter(new int[] {1,3})),
           new int[] {3});
  
public voidtestMA3()

    Query q=new MatchAllDocsQuery();
    q.setBoost(0);
    bqtest(q, new int[] { 0,1,2,3 });
  
public voidtestMPQ7()

    MultiPhraseQuery q = new MultiPhraseQuery();
    q.add(ta(new String[] {"w1"}));
    q.add(ta(new String[] {"w2"}));
    q.setSlop(1);
    q.setBoost(0.0f);
    bqtest(q, new int[] { 0,1,2 });
  
public voidtestSF3()

    SpanQuery q = sf(("w1"),1);
    q.setBoost(0);
    bqtest(q, new int[] {0,1,2,3});
  
public voidtestSF7()

    SpanQuery q = sf(("xx"),3);
    q.setBoost(0);
    bqtest(q, new int[] {2,3});
  
public voidtestSNot3()

    SpanQuery q = snot(sf("w1",10),st("QQ"));
    q.setBoost(0);
    bqtest(q, new int[] {0,1,2,3});
  
public voidtestSNot6()

    SpanQuery q = snot(sf("w1",10),st("xx"));
    q.setBoost(0);
    bqtest(q, new int[] {0,1,2,3});
  
public voidtestSNot8()

    // NOTE: using qtest not bqtest
    SpanQuery f = snear("w1","w3",10,true);
    f.setBoost(0);
    SpanQuery q = snot(f, st("xx"));
    qtest(q, new int[] {0,1,3});
  
public voidtestSNot9()

    // NOTE: using qtest not bqtest
    SpanQuery t = st("xx");
    t.setBoost(0);
    SpanQuery q = snot(snear("w1","w3",10,true), t);
    qtest(q, new int[] {0,1,3});
  
public voidtestST3()

    SpanQuery q = st("w1");
    q.setBoost(0);
    bqtest(q, new int[] {0,1,2,3});
  
public voidtestST6()

    SpanQuery q = st("xx");
    q.setBoost(0);
    qtest(q, new int[] {2,3});
  
public voidtestT3()

    bqtest("w1^0.0", new int[] { 0,1,2,3 });