public override int GetHashCode()
 {
     unchecked
     {
         return(((FullForm != null ? FullForm.GetHashCode() : 0) * 397) ^ Abbreviation.GetHashCode());
     }
 }
    /* Author: Pratik Pramanik
     * Written for SCVMC LIS
     * contact: pratikpramanik at gmail dot com
     *
     * Indexes the items on a database for broader, less specific
     * searching of the website.
     */
    protected void IndexDocs(object sender, EventArgs e)
    {
        //status prompt
        IndexStatus.Text = "Indexing..." + System.Environment.NewLine;

        //acess DB with SELECT -> Gives DataView -> Convert View to Table
        DataView dvSql  = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        DataTable dtSql = dvSql.ToTable();

        //delimination symbols
        char[] delimCh =  { ' ', ',', '.', ':', '\t', '_', '\n',
                            '!','@','#','$','%','^','&','*','(',
                            ')','[',']',';','\'','{','}','\"',
                            '<','>','\\','/','+','-','`','\r',
                            '~'};

        //hashtable format <String "Keyword", List<Forms> that contain "Keyword">
        Hashtable wordmap    = new Hashtable();
        int dbSize           = dvSql.Count;
        const int DEF_ARR_SZ = 32;
        const int TITLESCORE = 3;
        const int SYNYMSCORE = 2;
        const int NUM_FIELDS = 8;

        IndexStatus.Text += "Processing DB [Active Size:"+ dbSize +"]..." + System.Environment.NewLine;

        #region DB Processing
        //LOGIC: for every entry in the database, add that entry's value for ID into the list/array
        foreach (DataRow r in dtSql.Rows)
        {
            FullForm temp = new FullForm();
            String[] fields = new String[NUM_FIELDS];
            int currentscore;

            //Store current DATAROW in a Struct for easy access
            temp.ID    = (int)r["ID"];
            fields[0] = temp.Title = (String)r["Title"];
            fields[1] = temp.Code = (String)r["Code"];
            fields[2] = temp.Desc = (String)r["Description"];
            fields[3] = temp.Syn1 = (String)r["Syn1"];
            fields[4] = temp.Syn2 = (String)r["Syn2"];
            fields[5] = temp.Syn3 = (String)r["Syn3"];
            fields[6] = temp.Syn4 = (String)r["Syn4"];
            fields[7] = temp.Syn5 = (String)r["Syn5"];

            IndexStatus.Text += "*DB Row Processing: " + temp.Title + "...";

            //parse through text fields
            for (int f = 0; f < NUM_FIELDS; f++)
            {
                String[] text;
                if (f != 1)                               //split the field, if not code
                { text = fields[f].Split(delimCh); }
                else
                { text = new String[1]; text[0] = fields[f]; }
                int n = 0;                                //set a counter

                //assign special scores
                if (f == 0)      { currentscore = TITLESCORE; }
                else if (f >= 3) { currentscore = SYNYMSCORE; }
                else             { currentscore = 1; }

                #region Word Processing
                //check each word in each field
                foreach (String s in text)
                {
                    string newS = s.ToLower();

                    //ignore stopwords
                    if(s.Equals("") || isStopword(newS))
                      continue;

                    //Hashtable key check, has keyword already
                    if (wordmap.ContainsKey(newS))
                    {
                        int x;
                        string[] oldArr = (string[])wordmap[newS];

                        //checks keyword already found on particular form
                        string tempName = temp.FormatName();
                        string tempID   = temp.ID.ToString();

                        //check keyword's current DB
                        for (x = 0; x < oldArr.Length; x++)
                        {
                            //end of data in array
                            if (oldArr[x] == null)
                                goto EMPTYSPACEARRAY;
                            if (oldArr[x].Equals(""))
                                goto EMPTYSPACEARRAY;

                            int oldScore = Convert.ToInt32(oldArr[x].Split(':')[0]);
                            string oldID    = oldArr[x].Split(':')[1];
                            string oldName  = oldArr[x].Split(':')[2];
                            //string oldNext = oldArr[x].Split(':')[3]; //vestigal

                            //ID shared, repeated word on page, increase relevance rating
                            if (tempID.Equals(oldArr[x].Split(':')[1]))
                            {
                                oldScore += currentscore;
                                wordmap.Remove(newS);
                                oldArr[x] = FormatForm(oldScore,
                                                       (int)Convert.ToInt32(oldID),
                                                       oldName);
                                wordmap.Add(newS, oldArr);
                                goto ENDFOREACH;
                            }
                        }
                    ARRAYTOOSMALL: //**reached the end of the array size, needs to be bigger
                        Array.Resize<string>(ref oldArr, oldArr.Length + 1);

                        //x should already be the index of the last space
                    EMPTYSPACEARRAY: //**insert form data at next space in array
                        oldArr[x] = FormatForm(currentscore, temp.ID, temp.FormatName());
                        wordmap.Remove(newS);
                        wordmap.Add(newS, oldArr);
                    }
                    //does not contain key, add new
                    else
                    {
                        string[] formArr = new string[DEF_ARR_SZ]; //set back to dbSize if too small
                        //assign score, place in array
                        formArr[0] = FormatForm(currentscore, temp.ID, temp.FormatName());
                        wordmap.Add(newS, formArr);
                    }
                ENDFOREACH: //**skipped to from for statment
                    n++;
                }
                #endregion
            }
            IndexStatus.Text += " Complete!" + System.Environment.NewLine;
        }
            #endregion

        //sort every array! for quicker lookup process

        #region Write Data File
        IndexStatus.Text += "Writing to file...";
        //open filestream
        FileStream fs = new FileStream
            (Server.MapPath("~/index.dat"), FileMode.OpenOrCreate, FileAccess.Write);

        //write to file close filestream
        try
        {
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(fs, wordmap);
        }
        finally
        {
            fs.Close();
        }
        //need a catch?
        #endregion

        //shows only if successful
        IndexStatus.Text += "Done!" + System.Environment.NewLine;
    }
Exemple #3
0
 bool SymbolEqual(string otherSymbol)
 {
     return(FullForm != null && otherSymbol != null &&
            FullForm.Equals(otherSymbol, StringComparison.OrdinalIgnoreCase));
 }