Exemplo n.º 1
0
        public Term(string TermTxt, int Hits, string FileId)
        {
            DBAccessor db = new DBAccessor();

            this.TermTxt = TermTxt;
            this.Hits    = Hits;
            this.FileId  = FileId;

            int tmpId = db.GetTermId(TermTxt);

            if (tmpId.CompareTo(-1) == 0)
            {
                db.AddNewTerm(TermTxt);
                this.Term_id = db.GetTermId(TermTxt);
            }
            else
            {
                this.Term_id = tmpId;
            }
        }
Exemplo n.º 2
0
        /** send files to Parsing to array of words + num of hits
         * insert values to the terms table at the DB
         * moving the files to the stored file directory  */
        public void InsertNewDocuments(List <Document> docs)
        {
            Dictionary <string, int> indexWords = new Dictionary <string, int>();
            List <string>            words      = new List <string>();
            int wordId = -1;

            TransferInvertedDocs(ref docs);
            foreach (Document doc in docs)
            {
                doc.Path   = doc.Path.Replace(@"\", @"\\");
                doc.Id     = da.AddDocument(doc);
                words      = PrepareDoc(doc.Path);
                indexWords = SortingWords(words);

                KeyValuePair <string, int> cuurWord;

                foreach (KeyValuePair <string, int> word in indexWords)
                {
                    try
                    {
                        cuurWord = word;
                        string key = cuurWord.Key.Replace("'", "''");
                        wordId = da.GetTermId(key);

                        if (wordId == -1)
                        {
                            da.AddNewTerm(key);
                        }

                        Term term = new Term(key, cuurWord.Value, doc.Id.ToString());
                        da.AddTermToPostingfile(term);
                    }
                    catch (Exception ex)
                    {
                        int i = 5;
                        i++;
                        //do nothing
                        // throw;
                    }
                }
                DelSourceFile(docs);
                UpdatePostingFileToDictionary();
            }
        }