1
|
/**
|
2
|
* Copyright (C) 2009 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
|
|
10
|
package eu.etaxonomy.cdm.persistence.dao.hibernate;
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertNotNull;
|
13
|
import static org.junit.Assert.assertTrue;
|
14
|
|
15
|
import java.io.FileNotFoundException;
|
16
|
import java.util.ArrayList;
|
17
|
import java.util.List;
|
18
|
|
19
|
import org.apache.commons.logging.Log;
|
20
|
import org.apache.commons.logging.LogFactory;
|
21
|
import org.hibernate.Hibernate;
|
22
|
import org.junit.Ignore;
|
23
|
import org.junit.Test;
|
24
|
import org.unitils.dbunit.annotation.DataSet;
|
25
|
import org.unitils.spring.annotation.SpringBeanByType;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
28
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
29
|
import eu.etaxonomy.cdm.model.description.TextData;
|
30
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
31
|
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionElementDao;
|
32
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
|
33
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
34
|
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
|
35
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
36
|
|
37
|
@DataSet
|
38
|
@Ignore //TODO indexing does not work at all, even before the unitils upgrade
|
39
|
public class FreeTextSearchIntegration extends CdmTransactionalIntegrationTest {
|
40
|
|
41
|
@SuppressWarnings("unused")
|
42
|
private static Log log = LogFactory.getLog(FreeTextSearchIntegration.class);
|
43
|
|
44
|
@SpringBeanByType
|
45
|
ITaxonDao taxonDao;
|
46
|
|
47
|
@SpringBeanByType
|
48
|
IDescriptionElementDao descriptionElementDao;
|
49
|
|
50
|
// @SpringBeanByType
|
51
|
// TaxonAlternativeSpellingSuggestionParser alternativeSpellingSuggestionParser;
|
52
|
//
|
53
|
// @Test
|
54
|
// public void test() {
|
55
|
// taxonDao.rebuildIndex();
|
56
|
// taxonDao.optimizeIndex();
|
57
|
//
|
58
|
// descriptionElementDao.rebuildIndex();
|
59
|
// descriptionElementDao.optimizeIndex();
|
60
|
// setComplete();
|
61
|
// endTransaction();
|
62
|
// taxonDao.countTaxa("Arum",null); // For some reason this flushes the indexes and allows the next method to create the spellings index
|
63
|
// }
|
64
|
//
|
65
|
// @Test
|
66
|
// public void test1() {
|
67
|
// alternativeSpellingSuggestionParser.refresh();
|
68
|
// }
|
69
|
|
70
|
@Test
|
71
|
public void testSearchTextData() {
|
72
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
73
|
orderHints.add(new OrderHint("inDescription.titleCache",SortOrder.ASCENDING));
|
74
|
|
75
|
List<String> propertyPaths = new ArrayList<String>();
|
76
|
propertyPaths.add("inDescription");
|
77
|
propertyPaths.add("inDescription.taxon");
|
78
|
List<DescriptionElementBase> results = descriptionElementDao.search(TextData.class,"Lorem",null,null,orderHints,propertyPaths);
|
79
|
|
80
|
assertNotNull("searchTextData should return a List",results);
|
81
|
assertEquals("there should be 4 TextData entities in the list",4,results.size());
|
82
|
|
83
|
assertTrue("DescriptionElementBase.feature should be initialized",Hibernate.isInitialized(results.get(0).getFeature()));
|
84
|
assertTrue("DescriptionElementBase.inDescription should be initialized",Hibernate.isInitialized(results.get(0).getInDescription()));
|
85
|
assertTrue("inDescription should be an instance of TaxonDescription",results.get(0).getInDescription() instanceof TaxonDescription);
|
86
|
TaxonDescription taxonDescription = (TaxonDescription)results.get(0).getInDescription();
|
87
|
assertTrue("TaxonDescription.taxon should be initialized",Hibernate.isInitialized(taxonDescription.getTaxon()));
|
88
|
assertEquals("The results should be sorted alphabetically","Aglaodorum Schott sec. cate-araceae.org",taxonDescription.getTaxon().getTitleCache());
|
89
|
}
|
90
|
|
91
|
@Test
|
92
|
public void testCountTextData() {
|
93
|
int matches = descriptionElementDao.count(TextData.class,"Lorem");
|
94
|
assertEquals("countTextData should return 4",4,matches);
|
95
|
}
|
96
|
|
97
|
@Test
|
98
|
public void testSearchWord() {
|
99
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
100
|
orderHints.add(new OrderHint("name.titleCache",SortOrder.ASCENDING));
|
101
|
List<String> propertyPaths = new ArrayList<String>();
|
102
|
propertyPaths.add("name");
|
103
|
|
104
|
List<TaxonBase> results = taxonDao.search(null,"Arum", null, null, orderHints, propertyPaths);
|
105
|
assertEquals("searchTaxa should return 463 results",46,results.size());
|
106
|
assertTrue("TaxonBase.name should be initialized",Hibernate.isInitialized(results.get(0).getName()));
|
107
|
}
|
108
|
|
109
|
@Test
|
110
|
public void testSearchCount() {
|
111
|
int numberOfResults = taxonDao.count(null,"Arum");
|
112
|
assertEquals("countTaxa should return 46",46,numberOfResults);
|
113
|
|
114
|
}
|
115
|
|
116
|
@Test
|
117
|
public void testSearchPaged() {
|
118
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
119
|
orderHints.add(new OrderHint("name.titleCache",SortOrder.ASCENDING));
|
120
|
List<String> propertyPaths = new ArrayList<String>();
|
121
|
propertyPaths.add("name");
|
122
|
List<TaxonBase> page1 = taxonDao.search(null,"Arum", 30, 0,orderHints,propertyPaths);
|
123
|
List<TaxonBase> page2 = taxonDao.search(null,"Arum", 30, 1,orderHints,propertyPaths);
|
124
|
|
125
|
assertEquals("page 1 should contain 30 taxa",30,page1.size());
|
126
|
assertEquals("page 1 should be sorted alphabetically","Arum L.",page1.get(0).getName().getTitleCache());
|
127
|
assertEquals("page 1 should be sorted alphabetically","Arum lucanum Cavara & Grande",page1.get(29).getName().getTitleCache());
|
128
|
assertEquals("page 2 should contain 16 taxa",16,page2.size());
|
129
|
assertEquals("page 2 should be sorted alphabetically","Arum maculatum L.",page2.get(0).getName().getTitleCache());
|
130
|
assertEquals("page 2 should be sorted alphabetically","Arum x sooi TerpĆ³",page2.get(15).getName().getTitleCache());
|
131
|
}
|
132
|
|
133
|
@Test
|
134
|
public void testSearchPhrase() {
|
135
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
136
|
orderHints.add(new OrderHint("name.titleCache",SortOrder.ASCENDING));
|
137
|
List<String> propertyPaths = new ArrayList<String>();
|
138
|
propertyPaths.add("name");
|
139
|
|
140
|
List<TaxonBase> results = taxonDao.search(null,"\"Arum italicum\"", null, null,orderHints,propertyPaths);
|
141
|
assertEquals("searchTaxa should return 5 taxa",5,results.size());
|
142
|
}
|
143
|
|
144
|
@Test
|
145
|
public void testSearchWildcard() {
|
146
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
147
|
orderHints.add(new OrderHint("name.titleCache",SortOrder.ASCENDING));
|
148
|
List<String> propertyPaths = new ArrayList<String>();
|
149
|
propertyPaths.add("name");
|
150
|
|
151
|
List<TaxonBase> results = taxonDao.search(null,"Aroph*", null, null,orderHints,propertyPaths);
|
152
|
assertEquals("searchTaxa should return 6 taxa",7,results.size());
|
153
|
}
|
154
|
|
155
|
@Test
|
156
|
@Ignore //we currently don't use suggest anymore
|
157
|
public void testSuggestSingleTerm() {
|
158
|
String suggestion = taxonDao.suggestQuery("Aram");
|
159
|
assertNotNull("suggestQuery should return a String",suggestion);
|
160
|
assertEquals("The spelling suggestion for \"Aram\" should be \"arum\"","arum",suggestion);
|
161
|
}
|
162
|
|
163
|
@Test
|
164
|
@Ignore //we currently don't use suggest anymore
|
165
|
public void testSuggestSingleTermInCompositeQuery() {
|
166
|
String suggestion = taxonDao.suggestQuery("Aram italicum");
|
167
|
assertNotNull("suggestQuery should return a String",suggestion);
|
168
|
assertEquals("The spelling suggestion for \"Aram italicum\" should be \"arum italicum\"","arum italicum",suggestion);
|
169
|
}
|
170
|
|
171
|
@Test
|
172
|
@Ignore //we currently don't use suggest anymore
|
173
|
public void testSuggestMultipleTermsInCompositeQuery() {
|
174
|
String suggestion = taxonDao.suggestQuery("Aram italocum");
|
175
|
assertNotNull("suggestQuery should return a String",suggestion);
|
176
|
assertEquals("The spelling suggestion for \"Aram italocum\" should be \"arum italicum\"","arum italicum",suggestion);
|
177
|
}
|
178
|
|
179
|
@Test
|
180
|
@Ignore //we currently don't use suggest anymore
|
181
|
public void testSuggestMultipleTermsInCompositeQueryWithAnd() {
|
182
|
String suggestion = taxonDao.suggestQuery("Aram AND italocum");
|
183
|
assertNotNull("suggestQuery should return a String",suggestion);
|
184
|
assertEquals("The spelling suggestion for \"Aram AND italocum\" should be \"+arum +italicum\"","+arum +italicum",suggestion);
|
185
|
}
|
186
|
|
187
|
/* (non-Javadoc)
|
188
|
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
|
189
|
*/
|
190
|
@Override
|
191
|
public void createTestDataSet() throws FileNotFoundException {
|
192
|
// TODO Auto-generated method stub
|
193
|
|
194
|
}
|
195
|
}
|