Пример #1
0
 public static void SearchWordOfQuery(string word, Query query)
 {
     lock (Quries)
     {
         string pathD;
         string pathP;
         if (!query.terms.ContainsKey(word))
         {
             TermOfQuery tq = new TermOfQuery(word);
             query.terms.Add(word, tq);
             if ((word[0] >= 'a') && (word[0] <= 'z'))
             {
                 pathD = pathPost + "D" + word[0] + ".txt"; //create the name of the word's file
                 pathP = pathPost + "P" + word[0] + ".txt"; //create the name of the word's file
             }
             else
             {
                 pathD = pathPost + "D" + "numAndRules.txt";
                 pathP = pathPost + "P" + "numAndRules.txt";
             }
             int numOfLine = GetInfoOfTerm(ref pathD, ref tq); //read the dictionary file
             GetDocsOfTerm(ref pathP, ref tq, numOfLine);      //read the posting file
         }
         else
         {
             query.terms[word].QFI++;
         }
     }
 }
Пример #2
0
        /// <summary>
        /// get the posting details of the term
        /// </summary>
        /// <param name="path"></param>
        /// <param name="word"></param>
        /// <param name="numOfLine"></param>
        private static void GetDocsOfTerm(ref string path, ref TermOfQuery word, int numOfLine)
        {
            int counter = 0; //counter of the line

            try
            {
                using (Stream s = new FileStream(path, FileMode.Open))
                {
                    using (BinaryReader br = new BinaryReader(s))
                    {
                        while (br.BaseStream.Position != br.BaseStream.Length)
                        {
                            if (counter == numOfLine)                                                                               //we get to the wanted line
                            {
                                string line = br.ReadString();                                                                      //read the line
                                                                                                                                    //to check if can insert to file the object TERM
                                string[] details = line.Split(new char[] { '¥', '€', '|' }, StringSplitOptions.RemoveEmptyEntries); //split the docs details
                                                                                                                                    //to check
                                for (int i = 1; i < details.Length; i += 2)
                                {
                                    int num;
                                    int.TryParse(details[i + 1], out num);
                                    if (!word.DocsOfTerm.ContainsKey(details[i]))
                                    {
                                        word.DocsOfTerm.Add(details[i], num);
                                    }
                                }
                                break;
                            }
                            else //move on to the next line
                            {
                                counter++;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #3
0
        /// <summary>
        /// get the dic terms of all the files
        /// </summary>
        /// <param name="path"> path the path to the file</param>
        private static int GetInfoOfTerm(ref string path, ref TermOfQuery word)
        {
            int numOfLine = 0;

            try
            {
                using (Stream s = new FileStream(path, FileMode.Open))
                {
                    using (BinaryReader br = new BinaryReader(s))
                    {
                        while (br.BaseStream.Position != br.BaseStream.Length)
                        {
                            string   line   = br.ReadString(); //read the line
                            string[] fields = line.Split(new char[] { '¥' });
                            if (fields[0] == word.Term)        //the term is the wanted term
                            {
                                string[] split = fields[1].Split(new char[] { '€' });
                                int      shows, docs;
                                if (int.TryParse(split[0], out shows)) //get the num of shows
                                {
                                    word.NumOfShows = shows;
                                }
                                if (int.TryParse(split[1], out docs)) //get the num of docs
                                {
                                    word.NumOfDocs = docs;
                                }
                                break;
                            }
                            else
                            {
                                numOfLine++; //move on to the next line
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(numOfLine);
        }