internal void Add(string line)
        {
            String key = line.Substring(0, line.IndexOf(':'));
            PositionalPostingList ppl = new PositionalPostingList(key, line.Substring(line.IndexOf(':')));

            dic.Add(key, ppl);
        }
        internal static Tuple <PositionalPostingList, PositionalPostingList> PositionalIntersect(PositionalPostingList ppList1, PositionalPostingList ppList2, int k)
        {
            PositionalPostingList      nPPList1 = new PositionalPostingList(ppList1.Word);
            PositionalPostingList      nPPList2 = new PositionalPostingList(ppList2.Word);
            List <DocWordPositionList> p1 = ppList1.DocWordPositions;
            List <DocWordPositionList> p2 = ppList2.DocWordPositions;
            int i = 0, j = 0;

            while (i < p1.Count && j < p2.Count)
            {
                if (p1.ElementAt(i).DocId == p2.ElementAt(i).DocId)
                {
                    Tuple <DocWordPositionList, DocWordPositionList> result = DocWordPositionList.PositionalIntersect(p1.ElementAt(i), p2.ElementAt(i), k);
                    nPPList1.AddDoc(result.Item1);
                    nPPList2.AddDoc(result.Item2);
                    i++;
                    j++;
                }
                else if (p1.ElementAt(i).DocId < p2.ElementAt(i).DocId)
                {
                    i++;
                }
                else
                {
                    j++;
                }
            }
            return(new Tuple <PositionalPostingList, PositionalPostingList>(nPPList1, nPPList2));
        }
Example #3
0
        public static PList FindDocsWithPhrase(SearchDictionary sd, String phrase)
        {
            PList result = new PList();

            String[] terms = phrase.Split(' ');
            PositionalPostingList[] pplArray = new PositionalPostingList[terms.Length];
            for (int i = 0; i < terms.Length; i++)
            {
                pplArray[i] = sd.GetPostingList(terms[i]);
            }
            for (int i = 0; i < terms.Length - 1; i++)
            {
                for (int j = i + 1; j < terms.Length; j++)
                {
                    Tuple <PositionalPostingList, PositionalPostingList> tppList = PositionalPostingList.PositionalIntersect(pplArray[i], pplArray[j], j - i);
                    pplArray[i] = tppList.Item1;
                    pplArray[j] = tppList.Item2;
                }
            }
            return(pplArray[0].GetDocPList());
        }