Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.geocoding / src-test / org / gvsig / geocoding / dataaccess / LuceneDataAccessDBFTest.java @ 32479

History | View | Annotate | Download (8.33 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 Prodevelop S.L  vsanjaime   programador
26
 */
27

    
28
package org.gvsig.geocoding.dataaccess;
29

    
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

    
33

    
34
/**
35
 * Test
36
 * 
37
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
38
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicent Sanjaime Calvet</a>
39
 */
40
public class LuceneDataAccessDBFTest extends
41
org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase {
42
        private static final Logger log = LoggerFactory
43
         .getLogger(LuceneDataAccessDBFTest.class);
44
        //
45
        // private static final float SENSIBILITY = 0.8f;
46
        //
47
        // private static final String SEARCH_TERM = "Ishulli";
48
        // private static final String TEST_FILE = "test/AL.dbf";
49
        //
50
        // // private static final String TEST_FILE = "test/AF.dbf";
51
        // // private static final String SEARCH_TERM = "Beranehgak";
52
        //
53
        // String INDEX_DIRPATH = new File("test/dbf").getAbsolutePath();
54
        //
55
        // DBFDriver driverdbf = null;
56
        // int nFields;
57
        // int nRows;
58
        //
59
        // int indID = 0;
60
        // int indNAME = 2;
61
        // int indTIMEZONE = 17;
62
        //
63
        // String strID, strNAME, strTIMEZONE;
64
        //
65
        // private FieldDescription[] descs;
66
        //
67
        // public void setUp() {
68
        // File f = new File(TEST_FILE);
69
        //
70
        // driverdbf = new DBFDriver();
71
        //
72
        // try {
73
        // driverdbf.open(f);
74
        // nFields = driverdbf.getFieldCount();
75
        // nRows = (int) driverdbf.getRowCount();
76
        //
77
        // strID = driverdbf.getFieldName(indID);
78
        // strNAME = driverdbf.getFieldName(indNAME);
79
        // strTIMEZONE = driverdbf.getFieldName(indTIMEZONE);
80
        //
81
        // } catch (Exception e) {
82
        // e.printStackTrace();
83
        // }
84
        //
85
        // log.info("Fichero DBF abierto (" + nRows + " filas)");
86
        // }
87
        //
88
        // /* Este test crea los indices */
89
        // public void testGenerateIndex() {
90
        // log.info("Creando ?ndice...");
91
        //
92
        // long t1 = System.currentTimeMillis();
93
        //
94
        // IndexWriter indexWriter = null;
95
        // try {
96
        // indexWriter = new IndexWriter(INDEX_DIRPATH,
97
        // new StandardAnalyzer(), true);
98
        // createIndex(indexWriter);
99
        // indexWriter.optimize();
100
        // } catch (Exception e) {
101
        //
102
        // }
103
        // log.info("?ndice creado en " + (System.currentTimeMillis() - t1)
104
        // + " msecs");
105
        //
106
        // }
107
        //
108
        // private void createIndex(IndexWriter indexWriter)
109
        // throws CorruptIndexException, ReadDriverException, IOException {
110
        // for (int i = 0; i < nRows; i++) {
111
        //
112
        // if (i % (nRows / 4 + 1) == 0)
113
        // log.info(i * 1.0 / nRows * 100 + "%");
114
        //
115
        // indexWriter.addDocument(createDoc(i));
116
        // }
117
        // }
118
        //
119
        // /* Busqueda de cadenas */
120
        // public void testLuceneRAMDirectorySearch() throws CorruptIndexException,
121
        // LockObtainFailedException, IOException, ReadDriverException {
122
        // Analyzer an = null;
123
        //
124
        // ArrayList<String> cadenas = new ArrayList<String>();
125
        //
126
        // cadenas.add(SEARCH_TERM);
127
        // log
128
        // .info("--------------TEST DE B?SQUEDA LUCENE CON RAMDirectory--------------");
129
        // IndexWriter indexWriter = null;
130
        // Directory dir = null;
131
        // log.info("----Crear ?ndice----");
132
        // long id1 = System.currentTimeMillis();
133
        // dir = new RAMDirectory();
134
        // indexWriter = new IndexWriter(dir, new StandardAnalyzer(), true);
135
        // createIndex(indexWriter);
136
        // indexWriter.optimize();
137
        // log.info("?ndice creado en " + (System.currentTimeMillis() - id1)
138
        // + " msecs");
139
        //
140
        // log.info("----Buscando...----\n");
141
        // id1 = System.currentTimeMillis();
142
        // an = new StandardAnalyzer();
143
        // buscar(new IndexSearcher(dir), an, cadenas);
144
        // long id2 = System.currentTimeMillis();
145
        //
146
        // log.info("B?squeda realizada en " + (id2 - id1) + "msecs");
147
        // log
148
        // .info("--------------TEST DE B?SQUEDA LUCENE CON RAMDirectory--------------");
149
        // }
150
        //
151
        // /* Busqueda de cadenas */
152
        // public void testLuceneSearch() throws CorruptIndexException, IOException
153
        // {
154
        // Analyzer an = null;
155
        //
156
        // ArrayList<String> cadenas = new ArrayList<String>();
157
        //
158
        // cadenas.add(SEARCH_TERM);
159
        // log.info("--------------TEST DE B?SQUEDA LUCENE--------------");
160
        // long id1 = System.currentTimeMillis();
161
        // an = new StandardAnalyzer();
162
        // buscar(new IndexSearcher(INDEX_DIRPATH), an, cadenas);
163
        // long id2 = System.currentTimeMillis();
164
        //
165
        // log.info("B?squeda realizada en " + (id2 - id1) + "msecs");
166
        //
167
        // log.info("--------------TEST DE B?SQUEDA LUCENE--------------");
168
        // }
169
        //
170
        // public void testDBFSearch() throws ReadDriverException {
171
        // log.info("--------------TEST DE B?SQUEDA ITERANDO--------------");
172
        // long id1 = System.currentTimeMillis();
173
        // int results = 0;
174
        // String fieldValue;
175
        // for (int i = 0; i < nRows; i++) {
176
        // fieldValue = driverdbf.getFieldValue(i, indNAME).toString();
177
        // if (fieldValue.toLowerCase().indexOf(SEARCH_TERM.toLowerCase()) > -1) {
178
        // log.info(driverdbf.getFieldValue(i, indID) + "\t" + fieldValue);
179
        // results++;
180
        // }
181
        // }
182
        //
183
        // long id2 = System.currentTimeMillis();
184
        //
185
        // log.info(results + " resultados");
186
        // log.info("B?squeda realizada en " + (id2 - id1) + "msecs");
187
        //
188
        // log.info("--------------TEST DE B?SQUEDA ITERANDO--------------");
189
        // }
190
        //
191
        // private void testDataAccessFilters() {
192
        // log.info("--------------TEST DE B?SQUEDA FILTROS--------------");
193
        // // TODO
194
        // log.info("--------------TEST DE B?SQUEDA FILTROS--------------");
195
        // }
196
        //
197
        // private void buscar(IndexSearcher indexSearcher, Analyzer an,
198
        // List<String> cadenas) {
199
        // int results = 0;
200
        // try {
201
        // for (String cadena : cadenas) {
202
        // log.info("Buscando ``" + cadena + "`` con el analizador "
203
        // + an.getClass().getName());
204
        // // Se crear la consulta indicando el nombre del campo donde
205
        // // estan
206
        // // las cadenas del indices
207
        // // junto con el analizador
208
        // Query consulta = null;
209
        //
210
        // // consulta = new QueryParser(strNAME, an).parse(cadena);
211
        // consulta = new FuzzyQuery(new Term(strNAME, cadena),
212
        // SENSIBILITY);
213
        //
214
        // // se realiza la busqueda de una cadena y se obtinen los
215
        // // resultados
216
        // Hits hits = indexSearcher.search(consulta);
217
        //
218
        // results = hits.length();
219
        // for (int i = 0; i < hits.length(); i++) {
220
        // Document docu = hits.doc(i);
221
        //
222
        // log.info(docu.get(strID) + "\t " + docu.get(strNAME) + "("
223
        // + hits.score(i) + ")");
224
        // }
225
        // }
226
        //
227
        // log.info(results + " resultados");
228
        // } catch (Exception e) {
229
        // e.printStackTrace();
230
        // } finally {
231
        // try {
232
        // indexSearcher.close();
233
        // } catch (IOException e) {
234
        // log.error("Error cerrando ?ndice", e);
235
        // }
236
        //
237
        // }
238
        // }
239
        //
240
        // private Document createDoc(int i) throws ReadDriverException {
241
        // Document doc = new Document();
242
        //
243
        // // Add ID
244
        // Field fi;
245
        // String fieldValue = driverdbf.getFieldValue(i, indID).toString();
246
        // fi = new Field(strID, fieldValue, Field.Store.YES,
247
        // Field.Index.UN_TOKENIZED);
248
        // doc.add(fi);
249
        //
250
        // // Add NANME
251
        // fieldValue = driverdbf.getFieldValue(i, indNAME).toString();
252
        // fi = new Field(strNAME, fieldValue, Field.Store.YES,
253
        // Field.Index.TOKENIZED);
254
        // doc.add(fi);
255
        //
256
        // // Add TIMEZONE
257
        // fieldValue = driverdbf.getFieldValue(i, indTIMEZONE).toString();
258
        // fi = new Field(strTIMEZONE, fieldValue, Field.Store.YES,
259
        // Field.Index.TOKENIZED);
260
        // doc.add(fi);
261
        //
262
        // return doc;
263
        // }
264
        //
265
        // public void tearDown() {
266
        // try {
267
        // driverdbf.close();
268
        // } catch (CloseDriverException e) {
269
        // // TODO Auto-generated catch block
270
        // e.printStackTrace();
271
        // }
272
        // }
273

    
274
        @Override
275
        protected void doSetUp() throws Exception {
276
                // TODO Auto-generated method stub
277
                
278
        }
279

    
280
}