opensubscriber
   Find in this group all groups
 
Unknown more information…

j : java-user@lucene.apache.org 9 March 2005 • 12:04AM -0500

Re: Document lazy-loading WAS [Re: Fast access to a random page of the search results.]
by mark harwood

REPLY TO AUTHOR
 
REPLY TO GROUP



Your requirement was clear but I guess my suggested
solution wasn't.
Here it is in detail:


public class CountTest
{

    public static void main(String[] args) throws
Exception
    {
RAMDirectory tempDir = new RAMDirectory();
Analyzer analyzer=new WhitespaceAnalyzer();

IndexWriter writer = new IndexWriter(tempDir,
analyzer, true);
addDoc(writer,"1 1 1", "a");
addDoc(writer,"2 1 2", "b 2");
addDoc(writer,"3 3 3", "b 3");
writer.close();
class DocCount
{
            int count=0;
            private String term;
            public DocCount(String term)
            {
                this.term=term;
            }
            public String toString()
            {
                return term+": "+count;
            }
}
HashMap aDocTermCounts=new HashMap();
IndexReader reader = IndexReader.open(tempDir);
for(int i=0;i<reader.maxDoc();i++)
{
    TermFreqVector
tfv=reader.getTermFreqVector(i,"fieldA");
    String[] terms=tfv.getTerms();
    //here we use just the list of terms and ignore
the frequencies..
//     int freqs[]=tfv.getTermFrequencies();
    for (int j = 0; j < terms.length; j++)
            {
                DocCount docCount=(DocCount)
aDocTermCounts.get(terms[j]);
                if(docCount==null)
                {
                    docCount=new DocCount(terms[j]);
                  
aDocTermCounts.put(terms[j],docCount);                
                }
                docCount.count++;                
            }     
}
for (Iterator iter =
aDocTermCounts.values().iterator(); iter.hasNext();)
        {
            DocCount docCount = (DocCount)
iter.next();
            System.out.println(docCount);
            
        }
reader.close();
    }
    static void addDoc(IndexWriter writer, String
fieldA, String fieldB) throws IOException
    {
        Document doc=new Document();
doc.add( new Field("fieldA", fieldA,
        Field.Store.YES, Field.Index.TOKENIZED,
        Field.TermVector.YES));
        writer.addDocument(doc);
    }
    
}


Send instant messages to your online friends http://uk.messenger.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@luce...
For additional commands, e-mail: java-user-help@luce...

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.