Exemple #1
0
        public void DeleteIndex(MongoObjectId id)
        {
            Lucene.Net.Index.IndexModifier modifier = null;

            try
            {
                if (searcher != null)
                {
                    try
                    {
                        searcher.Close();
                    }
                    catch (Exception e)
                    {
                        logger.Error("Exception closing lucene searcher:" + e.Message, e);
                        throw;
                    }
                    searcher = null;
                }

                modifier =
                    new Lucene.Net.Index.IndexModifier(CustomAppSettings.SearchIndexFolder, analyzer, false);

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

                modifier.DeleteDocuments(new Lucene.Net.Index.Term("id", id.ToString()));
            }
            catch (Exception e)
            {
                logger.Error("Exception closing lucene searcher:" + e.Message, e);
            }
            finally
            {
                if (modifier != null)
                {
                    modifier.Flush();
                    modifier.Close();
                }
            }
        }
Exemple #2
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);
                }
            }
        }