Hi folks, I am using a MultiSearcher object which uses 4 months indexes. I have a requirement for which i need to cache one field for documents which are less then one month old. So for that i am first creating a date query(for last one month) and using HitCollector.collect() for collecting Document ids for all those documents who matched the criteria and save those ids in a Bitset. And then i created an array of size equal to the number of documents collected as a result. Now i iterate through the Bitset, and read that particular field from each document and storing it the position which matches with its document ids. Here is the code snippet for that :
private ArrayList[] compIdCache = null; public void warmUpFieldCache(MultiSearcher searcher, Query query) { ArrayList list = null; Document document = null; String[] mappedCompanies = null; try { final BitSet bitSet = new BitSet(searcher.maxDoc()); searcher.search(query, new HitCollector() { public void collect(int id, float score) { bitSet.set(id); } }); compIdCache = new ArrayList [bitSet.cardinality()]; MapFieldSelector selector = new MapFieldSelector(new String[] {COMPANY_ID}); for(int i=bitSet.nextSetBit(0); i>=0 && i < compIdCache.length; i=bitSet.nextSetBit(i+1)) { document = searcher.doc(i, selector); mappedCompanies = document.getValues(COMPANY_ID); compIdCache [i] = mappedCompanies ; } } catch (IOException e) { logger.info("searcher.maxDoc() throws exception :" +e.getMessage()); } } I have another method which queries for last month documents and uses their document ids(collected using hitCollector.collect()) to extract field value from the compIdCache. So here i have a confusion : Is this way of solving the problem is fine ? or are their some other ways to solve this problem.