Esempio n. 1
0
        public Form1()
        {
            InitializeComponent();
            MySqlConnection conn = sqlCommandManager.createConnection();

            sqlCommandManager.createDBdata();
            Robots.copyFileAndCreateIndex();
        }
 //return document from hidden to visible
 private void button6_Click(object sender, EventArgs e)
 {
     if (Robots.showDocument(comboBox2.SelectedValue.ToString()))
     {
         MessageBox.Show($@"document change visibility succesfully.");
     }
     else
     {
         MessageBox.Show($@"document change visibility not succesfully!!");
     }
 }
Esempio n. 3
0
        public static bool HandleUploadFile(string filePath)
        {
            int    fileIndex = checkStorageLength();
            string newFile   = copyFileToStorage(filePath, fileIndex);

            if (string.IsNullOrEmpty(newFile))
            {
                return(false);
            }
            //File.Delete(filePath);
            Robots.parseAndAddToDB(newFile);
            return(true);
        }
Esempio n. 4
0
        public static DataTable selectCommand(string data)
        {
            MySqlCommand command = new MySqlCommand(data, conn);
            DataTable    dt      = new DataTable();

            dt.Load(command.ExecuteReader());
            dt.Columns.Add("Summary");
            foreach (DataRow row in dt.Rows)
            {
                List <string> a     = new List <string>();
                string        index = row["doc_index"].ToString();
                a = Robots.addSummary(index);
                row["Summary"] = a[0];
            }
            return(dt);
        }
Esempio n. 5
0
 public static List <string> getHiddenDocList()
 {
     return(Robots.getHiddenDocsList());
 }
Esempio n. 6
0
        //parsing the serach command string
        public static DataTable parseSerachCommand(string searchCommand)
        {
            if (searchCommand.IndexOf(" ") == 0)      // removing whitespace from the beginning
            {
                int index = Regex.Match(searchCommand, "[a-zA-Z]").Index;
                searchCommand = searchCommand.Substring(index);
            }

            DataTable     dt      = new DataTable();
            List <string> queryOp = new List <string>();

            //List<string> patterns = new List<string>();
            //patterns.Add(@"(.)\w(.+?)\)");      // pattern for () inside ()
            //patterns.Add(@"\w(.+?)\&");
            //patterns.Add(@"\w(.+?)\&\s(.+?)\w(.*)");
            //patterns.Add(@"\w(.+?)\|\s(.+?)\w(.*)");
            //patterns.Add(@"!\s(.+?)\w(.*)");    // pattern for NOT
            //string NEARpattern = @"\bword1\W+(?:\w+\W+){dist1,dist2}?word2\b";
            string[] w;

            if (searchCommand.Contains('"'))        // for string include few words like: "and his wife"
            {
                w = searchCommand.Split(' ');
                if (w.Length > 1)
                {
                    Utilities.removeWhiteSpace(ref w);
                    w[0] = Regex.Match(w[0], @"[a-zA-Z]+").Value;
                    w[2] = Regex.Match(w[2], @"[a-zA-Z]+").Value;
                    dt   = sqlCommandManager.selectCommand($"SELECT a.word_name,b.word_name, a.doc_index FROM documents.word_index as a JOIN documents.word_index as b WHERE b.word_name ='{w[0]}' and a.word_name ='{w[1]}' and a.doc_index = b.doc_index");
                    foreach (DataRow row in dt.Rows)
                    {
                        if (row.RowState.ToString().Equals("Deleted"))
                        {
                            continue;
                        }
                        string docIndex = row["doc_index"].ToString();
                        if (!checkMultiWordsSearch(docIndex, w))
                        {
                            row.Delete();
                        }
                    }
                    isSentence = $"{w[0]} {w[1]} {w[2]}";
                }

                else
                {
                    searchCommand = Regex.Match(w[0], @"[a-zA-Z]\w*").Value;
                    if (checkStopList(searchCommand))
                    {
                        dt = sqlCommandManager.selectCommand($"select * from word_index WHERE word_name ='{searchCommand}'");
                    }
                    else
                    {
                        dt = sqlCommandManager.selectCommand($"select * from word_index WHERE word_name Like '%{searchCommand}%'");
                    }
                }
            }

            else if (searchCommand.Contains("["))   // For NEAR search
            {
                string[] w1    = { };
                string[] words = searchCommand.Split('[');
                if (words[0].Contains('&'))
                {
                    w1 = words[0].Split('&');
                    removeWhiteSpace(ref w1);
                }
                string[] indexes = words[1].Split(',');
                indexes[1] = indexes[1].Substring(0, indexes[1].Length - 1);
                dt         = runNearCommand(w1, indexes[0], indexes[1]);
            }

            else if (searchCommand.Contains("("))
            {
                Char[]   operands = new Char[2];
                string[] words    = Regex.Split(searchCommand, @"\)");
                for (int i = 0; i < words.Length; ++i)
                {
                    if (words[i].Contains('&'))
                    {
                        operands[i] = '&';
                    }
                    else if (words[i].Contains('|'))
                    {
                        operands[i] = '|';
                    }
                    else if (words[i].Contains('!'))
                    {
                        operands[i] = '!';
                    }
                    words[i] = Regex.Match(words[i], @"\w\w(.*)").Value;
                }

                string[] firstOp;
                if (operands[0].Equals('&'))
                {
                    firstOp = Regex.Split(words[0], @"\&");
                    removeWhiteSpace(ref firstOp);

                    if (operands[1].Equals('|'))
                    {
                        // AND + OR command
                    }

                    else if (operands[1].Equals('!'))
                    {
                        // AND + NOT command
                        dt = sqlCommandManager.selectCommand($"SELECT a.word_name,b.word_name, a.doc_index FROM documents.word_index as a JOIN documents.word_index as b WHERE b.word_name ='{firstOp[0]}' and a.word_name ='{firstOp[1]}' and a.doc_index = b.doc_index");
                        NotCommand(ref dt, words[1]);
                    }
                }

                else if (operands[0].Equals('|'))
                {
                    firstOp = Regex.Split(words[0], @"\|");
                    removeWhiteSpace(ref firstOp);

                    if (operands[1].Equals('|'))
                    {
                        // OR + OR command
                        dt = sqlCommandManager.selectCommand($"select * from word_index where word_name ='{firstOp[0]}' OR word_name ='{firstOp[1]}' OR word_name = '{words[1]}'");
                    }

                    else if (operands[1].Equals('!'))
                    {
                        // OR + NOT command
                        dt = sqlCommandManager.selectCommand($"select * from word_index where word_name ='{firstOp[0]}' OR word_name ='{firstOp[1]}'");
                        NotCommand(ref dt, words[1]);
                    }
                }

                return(dt);
            }

            else if (Utilities.checkStopList(searchCommand))   //checking if its "stopList" word
            {
                return(dt);
            }


            else if (searchCommand.Contains("&") || searchCommand.Contains("|"))  //operators
            {
                string[] words;
                if (searchCommand.Contains("&"))    // contains AND
                {
                    words = searchCommand.Split('&');
                    Utilities.removeWhiteSpace(ref words);
                    dt = sqlCommandManager.selectCommand($"SELECT a.word_name,b.word_name, a.doc_index FROM documents.word_index as a JOIN documents.word_index as b WHERE b.word_name ='{words[0]}' and a.word_name ='{words[1]}' and a.doc_index = b.doc_index");
                }

                else     // contains OR
                {
                    words = searchCommand.Split('|');
                    Utilities.removeWhiteSpace(ref words);
                    dt = sqlCommandManager.selectCommand($"select * from word_index where word_name ='{words[0]}' OR word_name ='{words[1]}' ");
                }
            }

            else
            {
                dt = sqlCommandManager.selectCommand($"select * from word_index WHERE word_name Like '%{searchCommand}%'");
            }

            Robots.checkHiddenDoc(ref dt);   //checking if dt includes hidden index

            return(dt);
        }
 //hide selected document
 private void button5_Click(object sender, EventArgs e)
 {
     Robots.HideDocument(comboBox1.SelectedValue.ToString());
     MessageBox.Show($@"Hide document {comboBox1.SelectedValue.ToString()} succesfully.");
 }