Jump to:

23377 Posts in 18296 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Search not working

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3 4
Go to End
Author Topic: 3451 Views
  • bettsaj
    Avatar
    Community Member
    46 Posts

    Re: Search not working Link to this post

    I'm using a custom template called wine... available from the silverstripe themes gallery.

    I was under the impression that the search function was already there, it just needed to be activated and to do that you had to place $SearchForm into the page.ss to make it work.

  • martimiz
    Avatar
    Forum Moderator
    1068 Posts

    Re: Search not working Link to this post

    I strongly advise you to follow invader_ zim's suggestion and visit the tutorial: http://doc.silverstripe.org/sapphire/en/tutorials/4-site-search

    It tells you exactly what you need to do to get elementary site search working.

    EDIT:
    OK, as long as you enable fulltextsearch (FulltextSearchable::enable();), you don't even have to add the SearchForm() and results() methods to your Page: FullTextSearchable automatically enables the ContentControllerSearchExtension on the Page_Controller for basic search functionality and I didn't know that - shame on me

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Search not working Link to this post

    Sorry to hyjack, i have the EXACT same problem. I am under SS 2.4.5

    Here is the URL :

    http://intranet.college-st-paul.qc.ca/dev

    I've followed the Search Tutorial and this is what it gives me (look at the URL) after i hit the results button. (More below pic).

    What i did:

    - add the code to the Page.php file

    - create a Page_results.ss and save it into the templates/layout/ folder

    - did a dev/build. It gives me this (not sign of Result Page)

    Any clue? Thanks!

  • martimiz
    Avatar
    Forum Moderator
    1068 Posts

    Re: Search not working Link to this post

    Hi,
    I don't think your problem is the same at all... Looking at your site's HTML, you can see there is an actual SearchForm generated, and pressing 'go' sends you to the correct URL. Only things missing on your page are the results...

    Looks to me SilverStripe hasn't found your template yet, and renders the second choice: the default Page template. You might want to do a flush=1, to refresh the template cache. Something like this:

    Note: as for dev/build: it's normal you wouldn't see any references to a Page_results page, because that pagetype class doesn't exist, there is only the template Page_results.ss.

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Search not working Link to this post

    http://intranet.college-st-paul.qc.ca/dev/home/SearchForm?Search=soccer&action_results=Go&flush=1

    Hi Martimiz, tried that too. Still nothing. And i have noticed that its not using the Page_results.ss template. I left some HTML comments in the template that i should see.

    Ive erased and redid the tutorial 2 times. Still nothing.

    SHOULD I HAVE PAGE_RESULTS.PHP page??????
    Because the renderWith function is into PAGE.PHP

    But one thing is puzzling me: the suggest content of Page_results.ss is different depending on which tutorial/source i am using.

    One is take at http://doc.silverstripe.org/sapphire/en/tutorials/4-site-search
    and begins with:
    <div id="Content" class="searchResults">
    <h2>$Title</h2>

    The other is at https://github.com/silverstripe-themes/silverstripe-blackcandy/blob/master/blackcandy/templates/Layout/Page_results.ss
    and begins with:
    <div class="typography">
       <% if Results %>
        <ul id="SearchResults">

    Which one is the right one. I am using SS 2.4.5

    Thanks!

  • martimiz
    Avatar
    Forum Moderator
    1068 Posts

    Re: Search not working Link to this post

    no, you don't need a Page_results.php page! As for the different templates: I don't know which one is the best in your situation, layout-wise, but they should both at least do something, even just ruin your layout... Anyway, I'd stick to the one in the tutorial for now...

    - You should only have one (1) Page_results.ss in your templates directory.

    - Also you could put an echo of some sort in your Page_Controllers results() function to see if it ever gets there.

    - Make sure there is no typo in the template name in your results() function.

    - You could try empty the silverstripe-cache directory (if you're using that) to force a refresh...

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: Search not working Link to this post

    Tried all that but the "cache" thing. Afraid to break something. It seems so fragile..... Here is the set-up and tell me looks/is wrong.

    I am using SS 2.4.5.

    The site is at http://intranet.college-st-paul.qc.ca/fr

    I am willing to give FTP access, CMS access and some money to help me with that! I NEED that to work.

    /***** FROM THE SOURCE CODE OF PAGES GENERATED BY PAGE.SS **********/

    <form id="SearchForm_SearchForm" action="/fr/services/autofinancement/SearchForm" method="get" enctype="application/x-www-form-urlencoded">
       <fieldset>
          <legend></legend>
          
             <div id="Search" class="field text nolabel"><div class="middleColumn"><input type="text" class="text nolabel" id="SearchForm_SearchForm_Search" name="Search" value="" /></div></div>
          
          
             <input class="action " id="SearchForm_SearchForm_action_results" type="submit" name="action_results" value="Go" title="Go" />
          
       </fieldset>
    </form>

    /***** FROM _CONFIG.PHP **********/

    FulltextSearchable::enable();

    /*************************************/

    Did a /dev/build after.

    /***** FROM PAGE.PHP **********/

    function results($data, $form){
    $data = array(
    'Results' => $form->getResults(),
    'Query' => $form->getSearchQuery(),
    'Title' => 'Search Results'
    );
    $this->Query = $form->getSearchQuery();

    return $this->customise($data)->renderWith(array('Page_results', 'Page'));
    }

    /*************************************/

    /***** FROM PAGE_RESULTS.SS INTO /LAYOUT **********/

    <div class="typography">
       <% if Results %>
        <ul id="SearchResults">
        <% control Results %>
        <li>
        <% if MenuTitle %>
        <h3><a class="searchResultHeader" href="$Link">$MenuTitle</a></h3>
        <% else %>
        <h3><a class="searchResultHeader" href="$Link">$Title</a></h3>
        <% end_if %>
              <% if Content %>
           $Content.FirstParagraph(html)
              <% end_if %>
        <a class="readMoreLink" href="$Link" title="Read more about &quot;{$Title}&quot;">Read more about &quot;{$Title}&quot;...</a>
        </li>
        <% end_control %>
        </ul>
        <% else %>
        <p>Sorry, your search query did not return any results.</p>
        <% end_if %>

        <% if Results.MoreThanOnePage %>
        <div id="PageNumbers">
        <% if Results.NotLastPage %>
        <a class="next" href="$Results.NextLink" title="View the next page">Next</a>
        <% end_if %>
        <% if Results.NotFirstPage %>
        <a class="prev" href="$Results.PrevLink" title="View the previous page">Prev</a>
        <% end_if %>
        <span>
        <% control Results.SummaryPagination(5) %>
        <% if CurrentBool %>
        $PageNum
        <% else %>
        <a href="$Link" title="View page number $PageNum">$PageNum</a>
        <% end_if %>
        <% end_control %>
        </span>

        </div>
        <% end_if %>
    </div>

    /*************************************/

    Am i missing something?

    Should that returns the results?

  • martimiz
    Avatar
    Forum Moderator
    1068 Posts

    Re: Search not working Link to this post

    We've all been there at some point, I guess...

    First of all: afaik you can definitely empty the silverstripe-cache directory, no problem, no instability, as long as it's writable, it will rebuild itself automatically.

    Now - I see your site definitely responding to your search request - just not the way you want it to... Go to your http://intranet.college-st-paul.qc.ca/fr/galerie url, then copy the underlying html. Then perform a search on that page, and you'll see your gallery going out of bounds. Copy that html and see if you recognize the different templates being used...

    3451 Views
Page: 1 2 3 4
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.