1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
public class recherche {
public static void main(String arg[]) throws IOException {
BufferedReader sr = new BufferedReader(
new FileReader(arg[0]));
String line;
Vector<String> lignes = new Vector<String>();
while ( ( line = sr.readLine()) != null)
lignes.add(line);
String[] li = lignes.toArray(new String[0]);
for (int k = 0; k < li.length; ++k)
System.out.println(li[k]);
String rep_index = ".\\index\\"; // Répertoire de l'index
Analyzer analyzer = new EnglishAnalyzer(Version.LUCENE_46);
QueryParser parser = new MultiFieldQueryParser(Version.LUCENE_46, lignes, analyzer);
// Boucle pour faire plusieurs recherches
while (1 == 1) {
Query query = parser.parse(lignes);
IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(FSDirectory.open(new File(rep_index))));
TopDocs results = searcher.search(query,4096);
ScoreDoc[] hits = results.scoreDocs;
System.out.println("Résultat: " + hits.length);
for(int j = 0; j < hits.length; j++){
Document doc = searcher.doc(hits[j].doc);
String resultat = doc.get(lignes);
System.out.println("");
}
}
}
} |
Partager