public ActionResult GetList(int page, int rows, string sidx, string sord, int? CategoryId) { IQueryable<Models.Content> contents ; if (!CategoryId.HasValue) contents = new ContentService().All(); else contents = new ContentService().List(CategoryId.Value); bool searchOn = bool.Parse(Request.Form["_search"]); string searchExp = ""; if (searchOn) { searchExp = string.Format("{0}.ToString().Contains(@0)", getFormValue("searchField")); contents = contents.Where(searchExp, new string[] { getFormValue("searchString") }); } var model = from entity in contents.OrderBy(sidx + " " + sord) select new { Id = entity.ContentId, Title = entity.Title, Thumbnail = entity.ThumbnailUrl, Category= entity.ContentCategory.CategoryName, Featured = entity.IsFeatured, IsForcusing = entity.IsFocusing, PostedDate = entity.CreatedDate.ToShortDateString(), Status = entity.Status, Url = this.Url.Action("View",Models.Statics.Controllers.Article.ToString(), new {Area="", id=entity.ContentId}) }; return Json(model.ToJqGridData(page, rows, null, "", new[] { "Title" }), JsonRequestBehavior.AllowGet); }
public ActionResult GetOrphanArticles(int page, int rows, string sidx, string sord) { var contents = new ContentService().AllOrhanArticles(); bool searchOn = bool.Parse(Request.Form["_search"]); string searchExp = ""; if (searchOn) { searchExp = string.Format("{0}.ToString().Contains(@0)", getFormValue("searchField")); contents = contents.Where(searchExp, new string[] { getFormValue("searchString") }); } var model = from entity in contents.OrderBy(sidx + " " + sord) select new { Id = entity.ContentId, Title = entity.Title, Thumbnail = entity.ThumbnailUrl, Status = entity.Status, PostedDate = entity.CreatedDate.ToShortDateString(), Url= this.Url.Action("View",Models.Statics.Controllers.Article.ToString(), new {Area="", id=entity.ContentId}) }; return Json(model.ToJqGridData(page, rows, null, "", new[] { "Title" }), JsonRequestBehavior.AllowGet); }
public ActionResult Edit(int id) { var item = new ContentService().GetItem(id); if (item == null) return RedirectToAction("Index"); ViewData["Categories"] = CustomSelectList.CreateListCategories(false).SetSelectedValue(item.CategoryId.ToString()); return View(item); }
public ActionResult EditContent(int id) { var item = new ContentService().GetItem(id); if (item == null) return RedirectToAction("Index"); return View(item); }
public ActionResult DeleteByContent(int id) { Content content = new ContentService().GetContentById(id); return JsonDelete(content.CategoryId); }
public void BuildingIndex_Thread() { lock (indexing_locker) { string tempdir = DBNLConfigurationManager.LuceneElement.IndexingFolder + ".tempx"; if (Directory.Exists(tempdir)) Directory.Delete(tempdir, true); bool hasError = false; //try //{ Lucene.Net.Index.IndexWriter writer = new Lucene.Net.Index.IndexWriter(tempdir, analyzer, true); //int totalRecords = new ContentService().All().Count(); int offset = 0; ContentService service = new ContentService(); var items = service.All().Skip(offset).Take(100).AsEnumerable(); int itemcount = items.Count(); Debug.WriteLine(itemcount.ToString()); Debug.Flush(); while (itemcount > 0) { foreach (var item in items) { writer.AddDocument(create_doc( item.ContentId, item.Content1)); Debug.WriteLine(item.ContentId.ToString()); Debug.Flush(); } items = service.All().Skip(offset).Take(100).AsEnumerable(); itemcount = items.Count(); offset += 100; } writer.Optimize(); writer.Close(); //} //catch (Exception e) //{ // hasError = true; // throw e; //} //finally //{ if (!hasError) { lock (locker) { string[] files = System.IO.Directory.GetFiles(tempdir); foreach (string s in files) { string fileName = System.IO.Path.GetFileName(s); string destFile = System.IO.Path.Combine(DBNLConfigurationManager.LuceneElement.IndexingFolder, fileName); System.IO.File.Copy(s, destFile, true); } } } IndexingAfterComplete(); //} } }
public void threadproc_update(object obj) { lock (locker) // If a thread is updating the index, no other thread should be doing anything with it. { try { if (searcher != null) { try { searcher.Close(); } catch (Exception e) { } searcher = null; } Lucene.Net.Index.IndexModifier modifier = new Lucene.Net.Index.IndexModifier(DBNLConfigurationManager.LuceneElement.IndexingFolder, analyzer, false); // same as build, but uses "modifier" instead of write. // uses additional "where" clause for bugid int id = (int)obj; modifier.DeleteDocuments(new Lucene.Net.Index.Term("id", Convert.ToString(id))); var item = new ContentService().GetContentById(id); modifier.AddDocument(create_doc( item.ContentId, item.Content1)); modifier.Flush(); modifier.Close(); } catch (Exception e) { } } }
public IEnumerable<Content> Search(string keyword, int page, int pageSize, out int totals) { lock (locker) { List<Content> result = new List<Content>(); IndexReader reader = IndexReader.Open(DBNLConfigurationManager.LuceneElement.IndexingFolder); IndexSearcher searcher = new IndexSearcher(reader); TopDocCollector collector = new TopDocCollector((page + 1) * pageSize); PhraseQuery pquery = new PhraseQuery(); BooleanQuery myquery = new BooleanQuery(); PhraseQuery q2 = new PhraseQuery(); //grab the search terms from the query string string[] str = keyword.Split(' '); //build the query foreach (string word in str) { //brand is the field I'm searching in q2.Add(new Term("content", word.ToLower())); } //finally, add it to the BooleanQuery object myquery.Add(q2, BooleanClause.Occur.MUST); //foreach (string srt in keyword.Split(new char[] {' '})) //{ // pquery.Add(new Term("content", srt.ToLower())); //} //pquery.Add(q2, BooleanClause.Occur.MUST); TermQuery query = new TermQuery(new Term("content", keyword)); // TopDocs topDocs = searcher.Search(query, collector); //searcher.Search(query, collector); QueryParser qp = new QueryParser("content", new StandardAnalyzer()); //Contains a phrase such as "this is a phrase" Query q = qp.Parse(keyword); //Hits hits = searcher.Search(q); //Hits hits = searcher.Search(query); Hits hits = searcher.Search(myquery); //ScoreDoc[] hits = collector.TopDocs().scoreDocs; totals = hits.Length(); Lucene.Net.Highlight.Formatter formatter = new Lucene.Net.Highlight.SimpleHTMLFormatter( "<span class=\"Highlight\">", "</span>"); Lucene.Net.Highlight.SimpleFragmenter fragmenter = new Lucene.Net.Highlight.SimpleFragmenter(400); Lucene.Net.Highlight.QueryScorer scorer = new Lucene.Net.Highlight.QueryScorer(myquery); Lucene.Net.Highlight.Highlighter highlighter = new Lucene.Net.Highlight.Highlighter(formatter, scorer); highlighter.SetTextFragmenter(fragmenter); for (int i = (page - 1) * pageSize; i < Math.Min(page * pageSize, hits.Length()); i++) { Document doc = hits.Doc(i); string raw_text = doc.Get("content"); Lucene.Net.Analysis.TokenStream stream = analyzer.TokenStream("", new System.IO.StringReader(raw_text)); string highlighted_text = highlighter.GetBestFragments(stream, raw_text, 1, "...").Replace("'", "''"); if (highlighted_text == "") // someties the highlighter fails to emit text... { highlighted_text = raw_text.Replace("'", "''"); } if (highlighted_text.Length > 500) { highlighted_text = highlighted_text.Substring(0, 500); } Content content = new ContentService().GetItem(int.Parse(doc.Get("id"))); content.HighlightText = highlighted_text; result.Add(content); } reader.Close(); searcher.Close(); return result.AsEnumerable(); } }
public ActionResult View(int id) { DBNL.App.Models.Content content = new ContentService().GetContentById(id); if (content == null) return RedirectToAction("Index", "Http404"); content.Content1 = StringTemplateHelper.ReplaceVideoTag(content.Content1); ViewData.Model = new ViewContentDataView() { Content = content, FeaturedContents = new ContentService().GetFeaturedArtileByCategoryId(content.CategoryId), OtherNewses = new ContentService().GetOlderNews(content) }; return View(); }