public ActionResult AddToIndex(Articles article) { LuceneSearch.AddUpdateLuceneIndex(article); TempData["Result"] = "Record was added to search index successfully!"; return RedirectToAction("Index"); }
private static void _addToLuceneIndex(Articles articles, IndexWriter writer) { //uklanjanje starog index unosa var searchQuery = new TermQuery(new Term("ArticleID", articles.ArticleID.ToString())); writer.DeleteDocuments(searchQuery); //dodavanje novog index unosa var doc = new Document(); //mapiranje db atributa doc.Add(new Field("ArticleID", articles.ArticleID.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); //NOT_ANALYZED se koristi za jedinstvene vrijednosti. doc.Add(new Field("Title", articles.Title, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Content", articles.Content, Field.Store.YES, Field.Index.ANALYZED)); //ANALYZED se koristi za text ili string. //dodavanje u index writer.AddDocument(doc); }
//Dodavanje samo jednog unosa u search index public static void AddUpdateLuceneIndex(Articles article) { AddUpdateLuceneIndex(new List<Articles> { article }); }
public ActionResult Edit(Articles article) { if (ModelState.IsValid) { article.DateModified = DateTime.Now; db.Entry(article).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.ArticleCategoryID = new SelectList(db.ArticleCategories, "ArticleCategoryID", "Name", article.ArticleCategoryID); return View(article); }