Esempio n. 1
0
        public IActionResult Do(SearchFormViewModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.SearchKeyword))
                {
                    return(RedirectToAction("Index", "Home"));
                }

                var articlePrefix = _settingService.GetSettings().ArticlePrefix;
                if (!string.IsNullOrEmpty(articlePrefix))
                {
                    if (model.SearchKeyword.Length > articlePrefix.Length + 1 &&
                        model.SearchKeyword.Substring(0, articlePrefix.Length + 1) == articlePrefix + "-")
                    {
                        var articleId = model.SearchKeyword.Substring(articlePrefix.Length + 1);
                        model.ArticleId = Convert.ToInt32(articleId);
                    }

                    if (model.ArticleId > 0)
                    {
                        Article article = new Article();

                        article = PublishedArticles().FirstOrDefault(a => a.Id == model.ArticleId);


                        if (article != null)
                        {
                            return(RedirectToRoute("Default", new { controller = "Home", action = "Detail", id = article.SefName }));
                        }
                    }
                }

                if (model.CurrentPage == 0)
                {
                    model.CurrentPage++;
                }

                //model.Results = KbVaultLuceneHelper.DoSearch(_env, model.SearchKeyword, model.CurrentPage, 10);
                model.Results = _lucene.DoSearch(model.SearchKeyword, model.CurrentPage, 10);

                return(View(model));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
Esempio n. 2
0
        public ActionResult Do(SearchFormViewModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.SearchKeyword))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                string articlePrefix = Settings.ArticlePrefix;
                if (!string.IsNullOrEmpty(articlePrefix))
                {
                    if (model.SearchKeyword.Length > articlePrefix.Length + 1 &&
                        model.SearchKeyword.Substring(0, articlePrefix.Length + 1) == articlePrefix + "-")
                    {
                        string articleId = model.SearchKeyword.Substring(articlePrefix.Length + 1);
                        model.ArticleId = Convert.ToInt32(articleId);
                    }

                    if (model.ArticleId > 0)
                    {
                        Article article = null;
                        using (var db = new KbVaultContext())
                        {
                            article = db.PublishedArticles().FirstOrDefault(a => a.Id == model.ArticleId);
                        }
                        if (article != null)
                        {
                            return(RedirectToRoute("Default", new { controller = "Home", action = "Detail", id = article.SefName }));
                        }
                    }
                }
                if (model.CurrentPage == 0)
                {
                    model.CurrentPage++;
                }
                //TODO: Make result count configurable
                model.Results = KbVaultLuceneHelper.DoSearch(model.SearchKeyword, model.CurrentPage, 10);

                return(View(model));
            }catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
Esempio n. 3
0
        public JsonResult More(SearchFormViewModel model)
        {
            JsonOperationResponse result = new JsonOperationResponse();

            try
            {
                model.CurrentPage++;
                model.Results     = KbVaultLuceneHelper.DoSearch(model.SearchKeyword, model.CurrentPage, 1);
                result.Successful = true;
                result.Data       = model;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                result.ErrorMessage = ex.Message;
            }
            return(Json(result));
        }
Esempio n. 4
0
        public JsonResult Ajax(string id)
        {
            JsonOperationResponse result = new JsonOperationResponse();

            try
            {
                if (Request.IsAjaxRequest())
                {
                    List <KbSearchResultItemViewModel> items = KbVaultLuceneHelper.DoSearch(id, 1, 10); //Request.Form["txtSearch"]);
                    result.Data       = items;
                    result.Successful = true;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                result.ErrorMessage = ex.Message;
            }
            return(Json(result));
        }
Esempio n. 5
0
        public JsonResult Ajax(string id)
        {
            var result = new JsonOperationResponse();

            try
            {
                if (Request.IsAjaxRequest())
                {
                    var items = KbVaultLuceneHelper.DoSearch(id, 1, 10);
                    result.Data       = items;
                    result.Successful = true;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                result.ErrorMessage = ex.Message;
            }

            return(Json(result));
        }