1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.api.service.search;
|
10
|
|
11
|
import java.io.FileNotFoundException;
|
12
|
|
13
|
import org.apache.lucene.search.BooleanQuery;
|
14
|
import org.apache.lucene.search.PhraseQuery;
|
15
|
import org.apache.lucene.search.PrefixQuery;
|
16
|
import org.apache.lucene.search.TermQuery;
|
17
|
import org.junit.Assert;
|
18
|
import org.junit.Test;
|
19
|
import org.unitils.spring.annotation.SpringBeanByType;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
22
|
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
|
23
|
|
24
|
/**
|
25
|
* @author a.kohlbecker
|
26
|
\* @since Jan 13, 2017
|
27
|
*
|
28
|
*/
|
29
|
public class QueryFactoryTest extends CdmIntegrationTest {
|
30
|
|
31
|
@SpringBeanByType
|
32
|
private ILuceneIndexToolProvider luceneIndexToolProvider;
|
33
|
|
34
|
@Test
|
35
|
public void testNewTermQuery_textfield_simple(){
|
36
|
|
37
|
QueryFactory qf = new QueryFactory(luceneIndexToolProvider, Taxon.class);
|
38
|
Assert.assertEquals(TermQuery.class, qf.newTermQuery("titleCache", "Lactuca", true).getClass());
|
39
|
Assert.assertEquals(BooleanQuery.class, qf.newTermQuery("titleCache", "Lactuca perennis", true).getClass());
|
40
|
Assert.assertEquals(PrefixQuery.class, qf.newTermQuery("titleCache", "Lactu*", true).getClass());
|
41
|
Assert.assertEquals(PhraseQuery.class, qf.newTermQuery("titleCache", "\"Lactuca perennis\"", true).getClass());
|
42
|
}
|
43
|
|
44
|
@Test
|
45
|
public void testNewTermQuery_textfield_complex(){
|
46
|
|
47
|
QueryFactory qf = new QueryFactory(luceneIndexToolProvider, Taxon.class);
|
48
|
Assert.assertEquals("ComplexPhraseQuery", qf.newTermQuery("titleCache", "\"Lactuca per*\"", true).getClass().getSimpleName());
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* {@inheritDoc}
|
53
|
*/
|
54
|
@Override
|
55
|
public void createTestDataSet() throws FileNotFoundException {
|
56
|
// TODO Auto-generated method stub
|
57
|
|
58
|
}
|
59
|
|
60
|
}
|