Bonjour,

j'aimerai indexer une table avec Lucène. Les enregistrements de cette table sont transformés en object grâce à hibernate et sont ensuite stockés dans une liste. Cette table étant immense (plus de 2 millions d'enregistrements), j'ai du découpé la sélection en plusieurs, sinon j'avais le droit à un OutOfMemoryException.

Voici à quoi ressemble ma fonction d'indexation (simplifiée pour les tests) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
34
35
36
37
38
39
40
41
public void indexerFiches(){
	String directoryIndex = parametreDAO.getCheminIndexationLucene();
	List listFiches;  
	IndexWriter writer;
	Analyzer analyzer = new FrenchAnalyzer();
	boolean createFlag = true;
 
	try {
		writer = new IndexWriter(directoryIndex, analyzer,createFlag);
 
		int min, max=1;
		Iterator itFiche;
		Fiche fiche;
 
		do{
			min=max;
			max=max+10000;
 
			listFiches = ficheDAO.find(min,max);
			itFiche = listFiches.iterator();
 
			while (itFiche.hasNext()) {
				fiche = (Fiche) itFiche.next();
				ajouterFiche(fiche,writer);
			}
		}
		while (listFiches.size()==10000);
 
		Writer.optimize();
		Writer.close();
 
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
private void ajouterFiche(Fiche fiche,IndexWriter writer) throws IOException {
	Document documentFiche = new Document();
	documentFiche.add(new Field(LuceneTools.NUM_FICHE, fiche.getNumEnregistrement().toString(), Field.Store.YES,Field.Index.UN_TOKENIZED));
	writer.addDocument(documentFiche);
}
Maintenant le traitement s'effectue bien, mais au bout d'un moment, un nouvel OutOfMemoryException apparait (lors du stockage d'une nouvelle sélection dans la liste) ... Celà fait maintenant deux jours que je suis dessus et je ne vois vraiment pas ce qui se passe. Pouvez vous m'aider s'il vous plaît ?