Methods Summary |
---|
private void | dumpResults(java.lang.String qType, org.apache.lucene.search.Query q, int numDocs)
Hits h = searcher.search(q);
assertTrue(qType +" should produce results ", h.length()>0);
if(printResults)
{
System.out.println("========="+qType+"============");
for(int i=0;i<Math.min(numDocs,h.length());i++)
{
org.apache.lucene.document.Document ldoc=h.doc(i);
System.out.println("["+ldoc.get("date")+"]"+ldoc.get("contents"));
}
System.out.println();
}
|
private org.apache.lucene.search.Query | parse(java.lang.String xmlFileName)
InputStream xmlStream=TestParser.class.getResourceAsStream(xmlFileName);
Query result=builder.parse(xmlStream);
xmlStream.close();
return result;
|
protected void | setUp()
/*
* @see TestCase#setUp()
*/
super.setUp();
//initialize the parser
builder=new CorePlusExtensionsParser(analyzer,new QueryParser("contents", analyzer));
//initialize the index (done once, then cached in static data for use with ALL tests)
if(dir==null)
{
BufferedReader d = new BufferedReader(new InputStreamReader(TestParser.class.getResourceAsStream("reuters21578.txt")));
dir=new RAMDirectory();
IndexWriter writer=new IndexWriter(dir,analyzer,true);
String line = d.readLine();
while(line!=null)
{
int endOfDate=line.indexOf('\t");
String date=line.substring(0,endOfDate).trim();
String content=line.substring(endOfDate).trim();
org.apache.lucene.document.Document doc =new org.apache.lucene.document.Document();
doc.add(new Field("date",date,Field.Store.YES,Field.Index.TOKENIZED));
doc.add(new Field("contents",content,Field.Store.YES,Field.Index.TOKENIZED));
writer.addDocument(doc);
line=d.readLine();
}
d.close();
}
reader=IndexReader.open(dir);
searcher=new IndexSearcher(reader);
|
protected void | tearDown()
reader.close();
searcher.close();
// dir.close();
|
public void | testBooleanFilterXML()
Query q=parse("BooleanFilter.xml");
dumpResults("Boolean filter", q, 5);
|
public void | testBooleanQueryXML()
Query q=parse("BooleanQuery.xml");
dumpResults("BooleanQuery", q, 5);
|
public void | testBoostingQueryXML()
Query q=parse("BoostingQuery.xml");
dumpResults("boosting ",q, 5);
|
public void | testCachedFilterXML()
Query q=parse("CachedFilter.xml");
dumpResults("Cached filter", q, 5);
|
public void | testConstantScoreQueryXML()
Query q=parse("ConstantScoreQuery.xml");
dumpResults("ConstantScoreQuery",q, 5);
|
public void | testFuzzyLikeThisQueryXML()
Query q=parse("FuzzyLikeThisQuery.xml");
//show rewritten fuzzyLikeThisQuery - see what is being matched on
if(printResults)
{
System.out.println(q.rewrite(reader));
}
dumpResults("FuzzyLikeThis", q, 5);
|
public void | testLikeThisQueryXML()
Query q=parse("LikeThisQuery.xml");
dumpResults("like this", q, 5);
|
public void | testMatchAllDocsPlusFilterXML()
Query q=parse("MatchAllDocsQuery.xml");
dumpResults("MatchAllDocsQuery with range filter", q, 5);
|
public void | testNestedBooleanQuery()
Query q=parse("NestedBooleanQuery.xml");
dumpResults("Nested Boolean query", q, 5);
|
public void | testRangeFilterQueryXML()
Query q=parse("RangeFilterQuery.xml");
dumpResults("RangeFilter", q, 5);
|
public void | testSimpleTermsQueryXML()
Query q=parse("TermsQuery.xml");
dumpResults("TermsQuery", q, 5);
|
public void | testSimpleXML()
Query q=parse("TermQuery.xml");
dumpResults("TermQuery", q, 5);
|
public void | testSpanTermXML()
Query q=parse("SpanQuery.xml");
dumpResults("Span Query",q, 5);
|
public void | testTermsFilterXML()
Query q=parse("TermsFilterQuery.xml");
dumpResults("Terms Filter",q, 5);
|
public void | testUserQueryXML()
Query q=parse("UserInputQuery.xml");
dumpResults("UserInput with Filter", q, 5);
|