use of at.ac.univie.mminf.luceneSKOS.queryparser.flexible.standard.SKOSStandardQueryParser in project lucene-skos by behas.
the class SKOSStandardQueryParserTest method queryParserSearch.
@Test
public void queryParserSearch() throws IOException, QueryNodeException {
Document doc = new Document();
doc.add(new Field("content", "The quick brown fox jumps over the lazy dog", TextField.TYPE_STORED));
writer.addDocument(doc);
searcher = new IndexSearcher(DirectoryReader.open(writer, false));
Query query = new SKOSStandardQueryParser(skosAnalyzer).parse("\"fox jumps\"", "content");
assertEquals(1, searcher.search(query, 1).totalHits);
assertEquals("content:\"fox (jumps hops leaps)\"", query.toString());
assertEquals("org.apache.lucene.search.MultiPhraseQuery", query.getClass().getName());
query = new StandardQueryParser(new StandardAnalyzer()).parse("\"fox jumps\"", "content");
assertEquals(1, searcher.search(query, 1).totalHits);
assertEquals("content:\"fox jumps\"", query.toString());
assertEquals("org.apache.lucene.search.PhraseQuery", query.getClass().getName());
}
use of at.ac.univie.mminf.luceneSKOS.queryparser.flexible.standard.SKOSStandardQueryParser in project lucene-skos by behas.
the class SKOSStandardQueryParserTest method queryParserSearchWithBoosts.
@Test
public void queryParserSearchWithBoosts() throws IOException, QueryNodeException {
Document doc = new Document();
doc.add(new Field("content", "The quick brown fox jumps over the lazy dog", TextField.TYPE_STORED));
writer.addDocument(doc);
searcher = new IndexSearcher(DirectoryReader.open(writer, false));
SKOSStandardQueryParser parser = new SKOSStandardQueryParser(skosAnalyzer);
parser.setBoost(SKOSType.ALT, 0.5f);
Query query = parser.parse("\"fox jumps\"", "content");
assertEquals(1, searcher.search(query, 1).totalHits);
// boosts do not work in phrase queries
assertEquals("content:\"fox (jumps hops leaps)\"", query.toString());
assertEquals("org.apache.lucene.search.MultiPhraseQuery", query.getClass().getName());
query = parser.parse("fox jumps", "content");
assertEquals(1, searcher.search(query, 1).totalHits);
assertEquals("content:fox (content:jumps content:hops^0.5 content:leaps^0.5)", query.toString());
assertEquals("org.apache.lucene.search.BooleanQuery", query.getClass().getName());
query = new SKOSStandardQueryParser(new StandardAnalyzer()).parse("fox jumps", "content");
assertEquals(1, searcher.search(query, 1).totalHits);
assertEquals("content:fox content:jumps", query.toString());
assertEquals("org.apache.lucene.search.BooleanQuery", query.getClass().getName());
}
Aggregations