Example usage for org.apache.lucene.search QueryUtils check

List of usage examples for org.apache.lucene.search QueryUtils check

Introduction

In this page you can find the example usage for org.apache.lucene.search QueryUtils check.

Prototype

public static void check(Random random, Query q1, IndexSearcher s) 

Source Link

Document

Various query sanity checks on a searcher, some checks are only done for instanceof IndexSearcher.

Usage

From source file:org.apache.solr.search.function.TestOrdValues.java

License:Apache License

private void doTestRank(String field, boolean inOrder) throws Exception {
    IndexReader r = DirectoryReader.open(dir);
    IndexSearcher s = newSearcher(r);//from   w  w w .  j a  v a  2  s.  c  om
    ValueSource vs;
    if (inOrder) {
        vs = new OrdFieldSource(field);
    } else {
        vs = new ReverseOrdFieldSource(field);
    }

    Query q = new FunctionQuery(vs);
    log("test: " + q);
    QueryUtils.check(random(), q, s);
    ScoreDoc[] h = s.search(q, 1000).scoreDocs;
    assertEquals("All docs should be matched!", N_DOCS, h.length);
    String prevID = inOrder ? "IE" // greater than all ids of docs in this test ("ID0001", etc.)
            : "IC"; // smaller than all ids of docs in this test ("ID0001", etc.)

    for (int i = 0; i < h.length; i++) {
        String resID = s.doc(h[i].doc).get(ID_FIELD);
        log(i + ".   score=" + h[i].score + "  -  " + resID);
        log(s.explain(q, h[i].doc));
        if (inOrder) {
            assertTrue("res id " + resID + " should be < prev res id " + prevID, resID.compareTo(prevID) < 0);
        } else {
            assertTrue("res id " + resID + " should be > prev res id " + prevID, resID.compareTo(prevID) > 0);
        }
        prevID = resID;
    }
    r.close();
}