Methods Summary |
---|
org.apache.lucene.document.Document | getDocumentFromString(java.lang.String nameValuePairs)
org.apache.lucene.document.Document result=new org.apache.lucene.document.Document();
StringTokenizer st=new StringTokenizer(nameValuePairs,"\t=");
while(st.hasMoreTokens())
{
String name=st.nextToken().trim();
if(st.hasMoreTokens())
{
String value=st.nextToken().trim();
result.add(new Field(name,value,Field.Store.YES,Field.Index.TOKENIZED));
}
}
return result;
|
java.util.Properties | getPropsFromString(java.lang.String nameValuePairs)
Properties result=new Properties();
StringTokenizer st=new StringTokenizer(nameValuePairs,"\t=");
while(st.hasMoreTokens())
{
String name=st.nextToken().trim();
if(st.hasMoreTokens())
{
String value=st.nextToken().trim();
result.setProperty(name,value);
}
}
return result;
|
protected void | setUp()
super.setUp();
//Create an index
RAMDirectory dir=new RAMDirectory();
IndexWriter w=new IndexWriter(dir,analyzer,true);
for (int i = 0; i < docFieldValues.length; i++)
{
w.addDocument(getDocumentFromString(docFieldValues[i]));
}
w.optimize();
w.close();
searcher=new IndexSearcher(dir);
//initialize the parser
builder=new CorePlusExtensionsParser(analyzer,new QueryParser("artist", analyzer));
|
protected void | tearDown()
searcher.close();
|
public void | testFormTransforms()
//Cache all the query templates we will be referring to.
QueryTemplateManager qtm=new QueryTemplateManager();
qtm.addQueryTemplate("albumBooleanQuery", getClass().getResourceAsStream("albumBooleanQuery.xsl"));
qtm.addQueryTemplate("albumFilteredQuery", getClass().getResourceAsStream("albumFilteredQuery.xsl"));
qtm.addQueryTemplate("albumLuceneClassicQuery", getClass().getResourceAsStream("albumLuceneClassicQuery.xsl"));
//Run all of our test queries
for (int i = 0; i < queryForms.length; i++)
{
Properties queryFormProperties=getPropsFromString(queryForms[i]);
//Get the required query XSL template for this test
// Templates template=getTemplate(queryFormProperties.getProperty("template"));
//Transform the queryFormProperties into a Lucene XML query
Document doc=qtm.getQueryAsDOM(queryFormProperties,queryFormProperties.getProperty("template"));
//Parse the XML query using the XML parser
Query q=builder.getQuery(doc.getDocumentElement());
//Run the query
Hits h=searcher.search(q);
//Check we have the expected number of results
int expectedHits=Integer.parseInt(queryFormProperties.getProperty("expectedMatches"));
assertEquals("Number of results should match for query "+queryForms[i],expectedHits,h.length());
}
|