Java is telling you the issue there. You're trying to cast a StandardDirectoryReader to an AtomicReader. I think AtomicReaders are per segment readers and in this case you actually want to get a view of all the terms in the index (i.e. over all segments), so I think you could wrap the reader you have in a SlowCompositeReaderWrapper to do what you want, i.e.:
import org.apache.lucene.index.SlowCompositeReaderWrapper; SlowCompositeReaderWrapper ar = SlowCompositeReaderWrapper.wrap(readre); etc Brendan On Sat, May 25, 2013 at 4:33 PM, mary meriem <mel-mer...@hotmail.fr> wrote: > there is my code for getting in position for all term index and I'm stuck > on this problem!!!! anyone has an idea about this error??ar = > (AtomicReader)readre; System.out.print(ar); boolean withOffsets = > false; Fields fields = MultiFields.getFields(readre); Term t= new > Term("contents"); DocsAndPositionsEnum td = > ar.termPositionsEnum(ar.getLiveDocs(), t.field(), t.bytes(), withOffsets); > int freq = td.freq(); for (int i = 0; i < freq; i++) { > int pos= td.nextPosition(); > System.out.println(String.valueOf(pos)); } > > Exception in thread "main" java.lang.ClassCastException: > org.apache.lucene.index.StandardDirectoryReader cannot be cast to > org.apache.lucene.index.AtomicReader at > Searcher.searchIndex(Searcher.java:59) at > Searcher.main(Searcher.java:143) > PS: i work with lucene 4.0.0 et sorry for my bad english :) > -- Brendan Grainger www.kuripai.com