ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Search Results: Custom Order

January 21, 2010 7:11am

Subscribe [3]
  • #1 / Jan 21, 2010 7:11am

    juro

    118 posts

    Hi,
    in an Expression Engine site I am maintaining we have various weblogs (news, people, articles, etc). When using the simple search, I need to order the results by weblog to get this kind of display:

    News

    - news 1 (title, link and excerpt)
    - news 2 (title, link and excerpt)
    - etc

    People

    - person 1 (name, link and custom weblog fields)
    - person 2 (name, link and custom weblog fields)
    - etc

    Articles

    - article 1 (title, link and excerpt)
    - article 2 (title, link and excerpt)
    - etc

    Currently, the search results are sorted by entry_id (as much as I know). How can I order the search results by weblog_id? Obviously iterating over the search results for every weblog does not make sense from a performance point of view!

    Also, it would be great to sort results of one weblog on the basis of a custom field (e.g. ordering the people alphabetical) - is this possible?

    Warm regards
    Roland

    Moved to HowTo by Moderator

  • #2 / Jan 21, 2010 9:34am

    Sue Crocker

    26054 posts

    What do you have as your simple search tab?

  • #3 / Jan 21, 2010 3:42pm

    juro

    118 posts

    Hi Sue,

    this is the simple search we use:

    {exp:search:simple_form weblog="news|people|active_services|events" result_page="search" no_result_page='search/no_results' search_in="entries"}  
    <label for="keywords">SEARCH</label>
      <input type="text" name="keywords" id="keywords" value="search field text" size="30" maxlength="80">
      <select name="area" id="area">
          <option value="">-- Select an Area (optional) --</option>
        {exp:weblog:entries weblog="active_services" sort="asc" orderby="title" dynamic="off"}
          <option value="{entry_id}">{title}</option>
        {/exp:weblog:entries}
      </select>
      <input type="submit" value="GO" class="submit" />
    {/exp:search:simple_form}
  • #4 / Jan 21, 2010 7:34pm

    Adam Dorsey

    1439 posts

    Can you post your “results” page code please?

    Thanks!

  • #5 / Jan 22, 2010 10:39am

    juro

    118 posts

    Adam, I am not sure why that is important but here you go. I have simplified it a bit though, as a lot of code is not necessary for my question.

    <div class="main-content search clearfix">
    Your search for <b><i>{exp:search:keywords}</i></b> found {exp:search:total_results}{total_results}{/exp:search:total_results} results.<hr >
    {if paginate}
    <div class='paginate'>
    <span class='pagecount'>{page_count}</span>  {paginate}
    </div>
    {/if}
    {embed="search/result-embed" entry_id="{exp:search:search_results}{entry_id}|{/exp:search:search_results}"}
    {if paginate}
    <div class='paginate'>
    <span class='pagecount'>{page_count}</span>  {paginate}
    </div>
    {/if}
    </div>

    and the embedded template:

    {exp:weblog:entries weblog="people" entry_id="{embed:entry_id}" disable="member_data|trackbacks|pagination" limit="500"}
    
    {if 'yes' == '{people_searchable}'}
    {if count==1}<h1>People</h1>{/if}
                <div class="search-result">
                    <div class="left">
                      <a href="http://{url_title_path=profiles/index}">_                    {people_image_small}_                  </a>
                    </div>
                    <div class="details">
                      <div class="row"><h1><a href="http://{url_title_path=profiles}">{title}</a></h1></div>       
                      <div class="row"><a href="http://{url_title_path=profiles/index}">Contact {title}</a></div>
                    </div>
                </div>
    {/if}
    
    {/exp:weblog:entries}
    {exp:weblog:entries weblog="news" entry_id="{embed:entry_id}" disable="member_data|trackbacks|pagination" category="97|98|104|99|115|103|100"  limit="500"}
    {if count==1}<h1>News</h1>{/if}
                <div class="search-result">
                    <div class="details noimage">
                      <div class="row"><h1><a href="http://{url_title_path=news}">{title}</a></h1></div>
                      <div class="row">Categories: {categories backspace="2"}{category_name} | {/categories}</div>
                      <div class="row">Excerpt: {exp:eexcerpt if_exceeds="500" the_link="…"}{news_summary}{/exp:eexcerpt}</div>
                    </div>
                </div>
    {/exp:weblog:entries}
    {exp:weblog:entries weblog="news" entry_id="{embed:entry_id}" disable="member_data|trackbacks|pagination" category="105|107|121|109"  limit="500"}
    {if count==1}<h1>Publications</h1>{/if}
                <div class="search-result">
                    <div class="details noimage">
                      <div class="row"><h1><a href="http://{url_title_path=news}">{title}</a></h1></div>
                      <div class="row">Categories: {categories backspace="2"}{category_name} | {/categories}</div>
                      <div class="row">Excerpt: {exp:eexcerpt if_exceeds="500" the_link="…"}{news_summary}{/exp:eexcerpt}</div>
                    </div>
                </div>
    {/exp:weblog:entries}

    Currently the only way I have found to get anything similar is using an embedded page.

  • #6 / Jan 22, 2010 1:18pm

    Sue Crocker

    26054 posts

    juro, unfortunately there isn’t anything built into EE to do exactly what you want, but an embedded page sounds like a possibility. Moving to Howto for additional community support.

    (We asked you about your template code just to make sure that the basics were OK.)

  • #7 / Jan 22, 2010 2:30pm

    juro

    118 posts

    Hmm, damn, that is a big minus. Seems I’ll have to do some PHP magic again.

  • #8 / Feb 15, 2010 11:56am

    trenchard

    128 posts

    Juro -

    Good news! We are in the last stages of testing a module that will give you this type of control over your search results.  Shoot me a PM and I’ll make sure you get an announcement.

  • #9 / Mar 07, 2010 7:55am

    juro

    118 posts

    Thank you trenchard, looking forward to it.

    In the meantime, I have adapted /system/modules/search/mod.search.php to make this possible.

    How-To:

    in the function build_standard_query() around line 963, replace the order functionality with this:

    switch ($orderby)
        {
          case 'most_comments'  :  $end .= " ORDER BY comment_total ";
            break;
          case 'recent_comment'  :  $end .= " ORDER BY recent_comment_date ";
            break;
          case 'title'      :  $end .= " ORDER BY title ";
            break;
          case 'date'       :
          case 'entry_date' :
            $end .= " ORDER BY entry_date ";
            break;
          case 'weblog_id'  :
          case 'weblog'     :
          default           :
            $end .= ' ORDER BY field(t.weblog_id, 23, 10, 5)';
            break;
        }
      
        $order = ( ! isset($_POST['sort_order'])) ? 'asc' : $_POST['sort_order'];
        
        if ($order != 'asc' AND $order != 'desc')
          $order = 'asc';
          
        $end .= " ".$order;

    This hack does - obviously - not come with ANY gaurantees whatsoever!

  • #10 / Mar 08, 2010 1:55am

    trenchard

    128 posts

    We’ve complete the module that does this and more.  Check it out at http://www.planet-ee.com.

  • #11 / Mar 12, 2010 1:56pm

    trenchard

    128 posts

    Hi Juro,
    Does the Search Results module look like it will meet your requirements? 

    Best,
    Mark

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases