hardy.ferentschik wrote:
Have you tried calling optimize prior to retrieving the list?
I tried running optimize while doing my testing, and it didn't help. I tried running optimize in Luke when these empty fields existed and it didn't help. If it helps anyone track down how to really solve this, I'm using JPA to persist things. As far as I can tell, these fields are never being removed from my index, regardless of whether the object was deleted or not. To be clear, everything appears to delete correctly up until the very last deletion.
I actually did find a workaround though. It's kind of messy, but it works. I essentially cobbled this together from Luke's source, actually.
Code:
SearchFactory sf = Search.getFullTextEntityManager(em).getSearchFactory();
IndexReader ir = sf.getIndexReaderAccessor().open(myClass.class);
Term currTerm;
Set<String> fieldsHaveTerms = new HashSet<String>();
TermEnum te = ir.terms();
while(te.next()) {
currTerm = te.term();
if(currTerm.field().charAt(0) != '_') {
fieldsHaveTerms.add(currTerm.field());
}
}
List<String> fields = new ArrayList<String>(fieldsHaveTerms);
Collections.sort(fields);
sf.getIndexReaderAccessor().close(ir);
return fields;
This gets me a list of all fields that have values.