/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This class illustrates how form input (such as from a web page or Swing gui) can be
* turned into Lucene queries using a choice of XSL templates for different styles of queries.
*/
//A collection of documents' field values for use in our tests
{
"artist=Jeff Buckley \talbum=Grace \treleaseDate=1999 \tgenre=rock",
"artist=Fugazi \talbum=Repeater \treleaseDate=1990 \tgenre=alternative",
"artist=Fugazi \talbum=Red Medicine \treleaseDate=1995 \tgenre=alternative",
"artist=Peeping Tom \talbum=Peeping Tom \treleaseDate=2006 \tgenre=rock",
"artist=Red Snapper \talbum=Prince Blimey \treleaseDate=1996 \tgenre=electronic"
};
// a choice of query style template to use in the test, with expected number of hits
{
"artist=Fugazi \texpectedMatches=2 \ttemplate=albumBooleanQuery",
"artist=Fugazi \treleaseDate=1990 \texpectedMatches=1 \ttemplate=albumBooleanQuery",
"artist=Buckley \tgenre=rock \texpectedMatches=1 \ttemplate=albumFilteredQuery",
"artist=Buckley \tgenre=electronic \texpectedMatches=0 \ttemplate=albumFilteredQuery",
"queryString=artist:buckly~ NOT genre:electronic \texpectedMatches=1 \ttemplate=albumLuceneClassicQuery"
};
public void testFormTransforms() throws SAXException, IOException, ParserConfigurationException, TransformerException, ParserException
{
// Sun 1.5 suffers from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6240963
assumeFalse("Sun JRE 1.5 suffers from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6240963 under Turkish locale", defLang.equals("tr") || defLang.equals("az"));
}
//Cache all the query templates we will be referring to.
qtm.addQueryTemplate("albumFilteredQuery", getClass().getResourceAsStream("albumFilteredQuery.xsl"));
qtm.addQueryTemplate("albumLuceneClassicQuery", getClass().getResourceAsStream("albumLuceneClassicQuery.xsl"));
//Run all of our test queries
{
//Get the required query XSL template for this test
// Templates template=getTemplate(queryFormProperties.getProperty("template"));
//Transform the queryFormProperties into a Lucene XML query
//Parse the XML query using the XML parser
//Run the query
//Check we have the expected number of results
}
}
//Helper method to construct Lucene query forms used in our test
{
while(st.hasMoreTokens())
{
if(st.hasMoreTokens())
{
}
}
return result;
}
//Helper method to construct Lucene documents used in our tests
{
while(st.hasMoreTokens())
{
if(st.hasMoreTokens())
{
}
}
return result;
}
/*
* @see TestCase#setUp()
*/
super.setUp();
//Create an index
dir=newDirectory();
{
}
w.optimize();
w.close();
//initialize the parser
}
super.tearDown();
}
}