예제 #1
0
        //made public ONLY for testing purposes!
        public Hashtable GetRelevantDocs(ArrayList queryTerms)
        {
            short     docId;
            Hashtable prevDocTermWeights = new Hashtable(); //key = docId, value = term weights per document accumulator
            Hashtable nextDocTermWeights;

            TermDocItem[] termDocs = index.TermDocs(queryTerms[0].ToString()); //get first termDocs
            for (int i = 0; i < termDocs.Length; i++)
            {
                docId = termDocs[i].DocId;
                prevDocTermWeights.Add(docId, termDocs[i].TermWeight); //Add doc and term weight to relevant docs list
            }
            //continue if query has more terms, continue with i=1
            if (queryTerms.Count > 1)
            {
                for (int j = 1; j < queryTerms.Count; j++)
                {
                    nextDocTermWeights = new Hashtable();
                    termDocs           = index.TermDocs(queryTerms[j].ToString());
                    for (int i = 0; i < termDocs.Length; i++)
                    {
                        docId = termDocs[i].DocId;
                        if (prevDocTermWeights.Contains(docId))
                        {
                            nextDocTermWeights.Add(docId, Convert.ToSingle(prevDocTermWeights[docId]) + termDocs[i].TermWeight); //update
                        }
                    }
                    prevDocTermWeights = nextDocTermWeights;
                }
            }
            return(prevDocTermWeights);
        }