
ers.c at bol
Oct 30, 2006, 6:38 PM
Post #1 of 3
(1304 views)
Permalink
|
|
Searching dates at Lucene 1.4.3 webindex
|
|
Hi all, First, thanks a lot Patrick and Grant, you were very very helpful in my last question! Here comes the final code. The file should have ":" as delimiters at the files to identify the fields, to work. e.g.: File.txt :Title: Web searching in Lucene :Description: This article presents the results of using a webservice running Lucene search :Author: Eder Reboucas :Content: bla bla bla... etc. e tal try { Scanner scanner = new Scanner(f); scanner.useDelimiter("\\s*:\\s*"); // whitespace and ":" String campo_nome = new String(); String campo_cont = new String(); while (scanner.hasNext()) { campo_nome = (campo_nome + scanner.next()); campo_cont = (campo_cont + scanner.next()); doc.add(new Field(campo_nome,campo_cont,true,true,true)); System.out.println("Field Name: " + campo_nome + "\nContent: " + campo_cont); campo_nome = ""; campo_cont = ""; } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } I tried to create a String field getting date, or a Date Field to search in the lucene 1.4.3 lucene web demo, by two ways: I) Using doc.add(Field.Keyword("modified", DateField.timeToString(f.lastModified()))); When I try to print it, it returns "0etut1c5k". II) Using Date Data = new Date ( f.lastModified() ); String arq_data = Data.toLocaleString(); arq_data = arq_data.replaceAll("/",""); arq_data = arq_data.substring(0,8); doc.add(new Field("Data", arq_data, true, true, true)); When I try to print it, it returns "28102006" - the date. But when I try to search it by the query "Data: 28102006", it doesn't return the file. So, I got the following questions: I - What does the Field.KeyWord method returns? II - Would somebody help me exaplining how to turn a date search / indexing reality in my job? Great hughes Eder
|