コード例 #1
0
        // GET: Documents
        public ActionResult Index(string searchString)
        {
            ViewBag.Title   = "Документы";
            ViewBag.Message = searchString;
            var docs = db.Documents.ToList();

            foreach (var doc in docs)
            {
                doc.Text = doc.Text.Replace("\n", "</br>");
            }
            if (string.IsNullOrEmpty(searchString))
            {
                return(View(db.Documents.ToList()));
            }

            var bm25      = new Bm25(db.Documents.ToList());
            var foundDocs = bm25.RankDocsByQuery(searchString);

            foreach (var doc in foundDocs)
            {
                doc.Text = doc.Text.Replace($" {searchString}", $" <b><mark>{searchString}</mark></b>");
            }

            return(View(foundDocs.ToList()));
        }
コード例 #2
0
        // GET: Documents
        public ActionResult Index(string searchstring)
        {
            ViewBag.Message = searchstring;

            if (string.IsNullOrWhiteSpace(searchstring))
            {
                return(View(db.Documents.ToList()));
            }

            var bm25   = new Bm25(db.Documents.ToList());
            var search = bm25.RankDocsByQuery(searchstring ?? string.Empty).ToList();

            //
            foreach (var temp in search)
            {
                temp.Text = temp.Text.Replace($" {searchstring} ", $"<i><b><mark> {searchstring} </i></mark></b>");
            }

            return(View(search));
        }