adding variable to pager

May 5, 2013 at 12:15 PM
Hey. I have created a sql based way to search instead of the norm. Its using pager as normal. This is page is /search/?q=thequery then page 2 becomes /search/1 . Is there any way to add the q variable to the pagetr so its /search/1?q=thequery which works when entered directly into address bar

thanks :)
Coordinator
May 5, 2013 at 8:41 PM
Hi,
I don't understand what you mean...
Currently the route is built using the page and q route values, like this http://sample.nearforums.com/search?page=1&q=test
If you are trying to override the behaviour, maybe you are wrongly configuring the routes.config file....but I don't know...
Could you provide more detail?

Kind regards,
Jorge
May 6, 2013 at 1:55 AM
i have wrote my own. i didnt like lucane. By using my own version it allows for more functionality. ranked results, latest results, results sorted by ... etc etc

<add url="search/{page}" controller="Search" action="SearchPageDetail">
  <constraints>
    <add key="page" value="\d+" />
  </constraints>
  <defaults>
    <add key="page" value="0" />
    </defaults>
</add>
#region Search page detail
    [ValidateReadAccess]
    [HttpGet]
    public ActionResult SearchPageDetail(string q, int page, string query)
    {
        Forum f = _service.GetAll();
        if (f == null)
        {
            return ResultHelper.NotFoundResult(this);
        }

        f.Search = _topicService.GetSearchByTag("'"+q+"'", Role);

        string q2 = q.Replace(" ", "+");

        ViewData["Page"] = page;
        ViewData["q"] = q;
        ViewData["q2"] = q2;
        ViewData["query"] = query;
        return View(f);
    }

  public List<Search> GetSearchByTag(string q, UserRole? role)
   {
       DbCommand comm = this.GetCommand("SPGetSearchByTag");
       comm.AddParameter<string>(this.Factory, "searchquery", q);
       comm.AddParameter(Factory, "UserGroupId", DbType.Int16, (short?)role);

       var list = ParseSearchForFullList(comm);
       return list;
   }
etc etc. This all works but I have used the pager to page the results using IPagedList but now the pager makes the second page /search/1 and i need /search/1?q=thequery it basiacly works like topics results but for a search using FullTextTable to return most relevent results.
May 6, 2013 at 2:00 AM
ignore the GetSearchByTag name as I was originally going to make searches either for the whole forum or within topics posted with x tag. this has changed but I havnt changed the name
May 6, 2013 at 2:09 AM
i tried every variation of this and it didnt work. should have looked what you used. @Html.Pager(search, new { q = ViewBag.q }, S(" "), S(" ")) made it work perfectly in the view