Search in sources :

Example 1 with SKOSStandardQueryParser

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());
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) Query(org.apache.lucene.search.Query) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Document(org.apache.lucene.document.Document) SKOSStandardQueryParser(at.ac.univie.mminf.luceneSKOS.queryparser.flexible.standard.SKOSStandardQueryParser) StandardQueryParser(org.apache.lucene.queryparser.flexible.standard.StandardQueryParser) SKOSStandardQueryParser(at.ac.univie.mminf.luceneSKOS.queryparser.flexible.standard.SKOSStandardQueryParser) Test(org.junit.Test)

Example 2 with SKOSStandardQueryParser

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());
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) Query(org.apache.lucene.search.Query) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Document(org.apache.lucene.document.Document) SKOSStandardQueryParser(at.ac.univie.mminf.luceneSKOS.queryparser.flexible.standard.SKOSStandardQueryParser) Test(org.junit.Test)

Aggregations

SKOSStandardQueryParser (at.ac.univie.mminf.luceneSKOS.queryparser.flexible.standard.SKOSStandardQueryParser)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 Document (org.apache.lucene.document.Document)2 Field (org.apache.lucene.document.Field)2 TextField (org.apache.lucene.document.TextField)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 Query (org.apache.lucene.search.Query)2 Test (org.junit.Test)2 StandardQueryParser (org.apache.lucene.queryparser.flexible.standard.StandardQueryParser)1