lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shailendra Mudgal" <>
Subject need a better way of caching the value of a field ???
Date Thu, 17 Apr 2008 06:54:29 GMT
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());
  , new HitCollector() {
                public void collect(int id, float score) {

            compIdCache = new ArrayList [bitSet.cardinality()];
            MapFieldSelector selector = new MapFieldSelector(new String[]

            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) {
  "searcher.maxDoc() throws exception :"

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.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message