private void addToIndex(LuceneQData sampleData) { LuceneQ.AddUpdateLuceneIndex(sampleData); bindData1(); }
private static void _addToLuceneIndex(LuceneQData sampleData, IndexWriter writer) { // remove older index entry var searchQuery = new TermQuery(new Term("Id", sampleData.Id.ToString())); writer.DeleteDocuments(searchQuery); // add new index entry var doc = new Document(); // add lucene fields mapped to db fields doc.Add(new Field("Id", sampleData.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Name", sampleData.Name, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Description", sampleData.Description, Field.Store.YES, Field.Index.ANALYZED)); // add entry to index writer.AddDocument(doc); }
// add/update/clear search index data public static void AddUpdateLuceneIndex(LuceneQData sampleData) { AddUpdateLuceneIndex(new List<LuceneQData> { sampleData }); }
//public static List<LuceneData> GetArticle() //{ // string connStr = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString; // SqlConnection connection = new SqlConnection(connStr); // List<LuceneData> obj1 = new List<LuceneData>(); // DataTable dt = new DataTable(); // SqlConnection con = new SqlConnection(connStr); // con.Open(); // SqlCommand cmd = new SqlCommand("select * from Article", con); // SqlDataAdapter da = new SqlDataAdapter(cmd); // da.Fill(dt); // if (dt.Rows.Count > 0) // { // for (int i = 0; i < dt.Rows.Count; i++) // { // LuceneData ga = new LuceneData(); // ga.Id = Convert.ToInt32(dt.Rows[i]["ArticleId"].ToString()); // ga.Name = dt.Rows[i]["Title"].ToString(); // ga.Description = dt.Rows[i]["Body"].ToString(); // obj1.Add(ga); // } // } // return obj1; //} public static List<LuceneQData> GetQuestion() { string connStr = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString; SqlConnection connection = new SqlConnection(connStr); List<LuceneQData> obj2 = new List<LuceneQData>(); DataTable dt = new DataTable(); SqlConnection con = new SqlConnection(connStr); con.Open(); SqlCommand cmd = new SqlCommand("select * from Question", con); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { LuceneQData gq = new LuceneQData(); gq.Id = Convert.ToInt32(dt.Rows[i]["QuestionId"].ToString()); gq.Name = dt.Rows[i]["QuestionTitle"].ToString(); gq.Description = dt.Rows[i]["QuestionBody"].ToString(); obj2.Add(gq); } } return obj2; }