Boa tarde,
Estou usando o Lucene para criar indices de uma tabela, estou usando o seguinte código:
File indexDir = new File("C:/indice");
Directory diretorio = FSDirectory.open(indexDir);
Analyzer a = new StandardAnalyzer(Version.LUCENE_30);
IndexDeletionPolicy deletionPolicy = new KeepOnlyLastCommitDeletionPolicy();
IndexWriter writer = new IndexWriter(diretorio, a, true, deletionPolicy,IndexWriter.MaxFieldLength.UNLIMITED);
...
while (sta.fetch()) {
Document doc = new Document();
doc.add(new Field("assunto",sta.getField("assunto"),Field.Store.YES,Index.ANALYZED_NO_NORMS));
doc.add(new Field("id", sta.getField("id"), Field.Store.YES, Index.ANALYZED_NO_NORMS));
doc.add(new Field("titulo", sta.getField("titulo"), Field.Store.YES, Index.ANALYZED_NO_NORMS));
writer.addDocument(doc);
}
writer.close();
Até ai funciona, ele gera os indices tudo certo, mais o problema é que quando eu pesquiso nestes indices, o resultado da diferente se eu pesquisar usando LIKE procurando no campo assunto:
public static void procurar(String assunto) throws IOException{
File indexDir = new File("C:/indice");
Directory diretorio = FSDirectory.open(indexDir);
Searcher indexSeacher = new IndexSearcher(diretorio);
Term term = new Term("assunto", assunto);
Query q = new TermQuery(term);
TopDocs top = indexSeacher.search(q, 53000);
System.out.println("Total: " + top.totalHits);
ScoreDoc[] scoreArrays = top.scoreDocs;
for(ScoreDoc doc : scoreArrays){
Document document = indexSeacher.doc(doc.doc);
System.out.println("\nAssunto: "+document.getField("assunto").stringValue());
System.out.println("Titulo "+document.getField("titulo").stringValue());
System.out.println("ID: "+document.getField("id").stringValue());
}
}
Grato.