Exemplo n.º 1
0
        // update an existing index
        static void threadproc_update(object obj)
        {
            // just to be safe, make the worker threads wait for each other
            //System.Console.Beep(540, 20);
            lock (my_lock) // prevent contention between searching and writing?
            {
                //System.Console.Beep(840, 20);
                try
                {
                    if (searcher != null)
                    {
                        try
                        {
                            searcher.Close();
                        }
                        catch (Exception e)
                        {
                            btnet.Util.write_to_log("Exception closing lucene searcher:" + e.Message);
                        }
                        searcher = null;
                    }

                    Lucene.Net.Index.IndexModifier modifier = new Lucene.Net.Index.IndexModifier(index_path, anal, false);

                    // same as buid, but uses "modifier" instead of write.
                    // uses additional "where" clause for bugid

                    int bug_id = (int)obj;

                    btnet.Util.write_to_log("started updating Lucene index using folder " + MyLucene.index_path);

                    modifier.DeleteDocuments(new Lucene.Net.Index.Term("bg_id", Convert.ToString(bug_id)));

                    string sql = @"
select bg_id, 
$custom_cols
isnull(bg_tags,'') bg_tags,
bg_short_desc    
from bugs where bg_id = $bugid";

                    sql = sql.Replace("$bugid", Convert.ToString(bug_id));

                    DataSet ds_text_custom_cols = get_text_custom_cols();

                    sql = sql.Replace("$custom_cols", get_text_custom_cols_names(ds_text_custom_cols));

                    // index the bugs
                    DataRow dr = btnet.DbUtil.get_datarow(sql);

                    modifier.AddDocument(MyLucene.create_doc(
                                             (int)dr["bg_id"],
                                             0,
                                             "desc",
                                             (string)dr["bg_short_desc"]));

                    // tags
                    string tags = (string)dr["bg_tags"];
                    if (tags != "")
                    {
                        modifier.AddDocument(MyLucene.create_doc(
                                                 (int)dr["bg_id"],
                                                 0,
                                                 "tags",
                                                 tags));
                    }

                    // custom text fields
                    foreach (DataRow dr_custom_col in ds_text_custom_cols.Tables[0].Rows)
                    {
                        string name = (string)dr_custom_col["name"];
                        string val  = Convert.ToString(dr[name]);
                        if (val != "")
                        {
                            modifier.AddDocument(MyLucene.create_doc(
                                                     (int)dr["bg_id"],
                                                     0,
                                                     name.Replace("'", "''"),
                                                     val));
                        }
                    }


                    // index the bug posts
                    DataSet ds = btnet.DbUtil.get_dataset(@"
select bp_bug, bp_id, 
isnull(bp_comment_search,bp_comment) [text] 
from bug_posts 
where bp_type <> 'update'
and bp_hidden_from_external_users = 0
and bp_bug = " + Convert.ToString(bug_id));

                    foreach (DataRow dr2 in ds.Tables[0].Rows)
                    {
                        modifier.AddDocument(MyLucene.create_doc(
                                                 (int)dr2["bp_bug"],
                                                 (int)dr2["bp_id"],
                                                 "post",
                                                 (string)dr2["text"]));
                    }

                    modifier.Flush();
                    modifier.Close();
                    btnet.Util.write_to_log("done updating Lucene index");
                }
                catch (Exception e)
                {
                    btnet.Util.write_to_log("exception updating Lucene index: " + e.Message);
                }
            }
        }
Exemplo n.º 2
0
        ///////////////////////////////////////////////////////////////////////
        // create a new index
        static void threadproc_build(object obj)
        {
            lock (my_lock)
            {
                try
                {
                    System.Web.HttpApplicationState app = (System.Web.HttpApplicationState)obj;

                    btnet.Util.write_to_log("started creating Lucene index using folder " + MyLucene.index_path);
                    Lucene.Net.Index.IndexWriter writer = new Lucene.Net.Index.IndexWriter(index_path, anal, true);



                    string  sql = @"
select bg_id,   
$custom_cols
isnull(bg_tags,'') bg_tags,
bg_short_desc
from bugs";
                    DataSet ds_text_custom_cols = get_text_custom_cols();

                    sql = sql.Replace("$custom_cols", get_text_custom_cols_names(ds_text_custom_cols));

                    // index the bugs
                    DataSet ds = btnet.DbUtil.get_dataset(sql);

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        // desc
                        writer.AddDocument(MyLucene.create_doc(
                                               (int)dr["bg_id"],
                                               0,
                                               "desc",
                                               (string)dr["bg_short_desc"]));

                        // tags
                        string tags = (string)dr["bg_tags"];
                        if (tags != "")
                        {
                            writer.AddDocument(MyLucene.create_doc(
                                                   (int)dr["bg_id"],
                                                   0,
                                                   "tags",
                                                   tags));
                        }

                        // custom text fields
                        foreach (DataRow dr_custom_col in ds_text_custom_cols.Tables[0].Rows)
                        {
                            string name = (string)dr_custom_col["name"];
                            string val  = Convert.ToString(dr[name]);
                            if (val != "")
                            {
                                writer.AddDocument(MyLucene.create_doc(
                                                       (int)dr["bg_id"],
                                                       0,
                                                       name.Replace("'", "''"),
                                                       val));
                            }
                        }
                    }

                    // index the bug posts
                    ds = btnet.DbUtil.get_dataset(@"
select bp_bug, bp_id, 
isnull(bp_comment_search,bp_comment) [text] 
from bug_posts 
where bp_type <> 'update'
and bp_hidden_from_external_users = 0");

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        writer.AddDocument(MyLucene.create_doc(
                                               (int)dr["bp_bug"],
                                               (int)dr["bp_id"],
                                               "post",
                                               (string)dr["text"]));
                    }

                    writer.Optimize();
                    writer.Close();
                    btnet.Util.write_to_log("done creating Lucene index");
                }
                catch (Exception e)
                {
                    btnet.Util.write_to_log("exception building Lucene index: " + e.Message);
                }
            }
        }