App.Core.Controllers.PostsController.Search C# (CSharp) Method

Search() public method

public Search ( string query ) : System.Web.Mvc.ViewResult
query string
return System.Web.Mvc.ViewResult
        public ViewResult Search(string query)
        {
            if (!string.IsNullOrEmpty(query)) {
                ViewBag.Query = query;
                var wildCardSearch = string.Format("%{0}%", query);

                var matchTitle = Restrictions.On<Post>(p => p.Title).IsLike(wildCardSearch);
                var matchBody = Restrictions.On<Post>(p => p.Body).IsLike(wildCardSearch);

                var posts = repository
                    .Session
                    .QueryOver<Post>()
                    .Where(matchTitle || matchBody)
                    .List();
                return View(posts);
            }
            return View(new List<Post>());
        }