Dynamically sortable search results
Posted: 11 January 2007 10:41 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  98
Joined  07-06-2006

A particular client seems to be enjoying asking me for the impossible this week. I’m clueless as to the possibility of this, but I’ll ask in case anyone can point me in the right direction, or even rule it out.

You’d get a page of search results as usual, but could then sort the delivered results, a bit like dynamic weblog parameters. Ideally the ability to sort by weblog, date, author, title etc. I know Robin went a little way towards this in this thread

Or as a worst-case scenario, is it poss for me to use furthr templates or segments to adjust the orderby parameters do you think?
I’m properly stressed about this project, so any help or advice would be gratefully received…

 Signature 

Erskine Design: http://www.erskinedesign.com
“Grad student”? - we’ve been here since the start!

Profile
 
 
Posted: 11 January 2007 11:03 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32861
Joined  05-14-2004

Page is way out of date, but do you mean like this or this?

 Signature 
Profile
MSG
 
 
Posted: 11 January 2007 11:09 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  98
Joined  07-06-2006

Oh blimey Lisa. Nice. Erm, first of your links if poss - a simple dropdown would work perfectly.

I see that uses custom fields too, although I only need to sort by title, author, date - and possibly weblog (the latter would be a huge bonus)...

 Signature 

Erskine Design: http://www.erskinedesign.com
“Grad student”? - we’ve been here since the start!

Profile
 
 
Posted: 11 January 2007 11:12 AM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32861
Joined  05-14-2004

All I’m doing is passing the parameters I need to change via segments:

{exp:weblog:entries weblog="{bootlist_blog}" orderby="{segment_3}" sort="{segment_4}" limit="40" show_future_entries="yes"}

and

<form name="sortmenu" action="">
<
select name="menu">
<
option value=""> Sort by... </option>
<
option value="{path=bootlist/index}">Date ascending</option>
<
option value="{path=bootlist/index}desc">Date descending</option>
<
option value="{path=bootlist/sort}artist/asc">Artist ascending</option>
<
option value="{path=bootlist/sort}artist/desc">Artist descending</option>
<
option value="{path=bootlist/sort}venue/asc">Venue ascending</option>
<
option value="{path=bootlist/sort}venue/desc">Venue descending</option>
<
option value="{path=bootlist/sort}media/asc">Media ascending</option>
<
option value="{path=bootlist/sort}media/desc">Media descending</option>
</
select>
<
input type="button" onclick="location=this.form.menu.options[this.form.menu.selectedIndex].value;" value="Sort" id="sortbutton" />
</
form>
</
div>

This isn’t on search results, though.  So it depends what you need, really.  You can change anything you have as a parameter, really.  I just didn’t need to.

 Signature 
Profile
MSG
 
 
Posted: 11 January 2007 11:19 AM   [ Ignore ]   [ # 4 ]  
Grad Student
Avatar
Rank
Total Posts:  98
Joined  07-06-2006

Ah, I see. You are using weblog tags. I gotta do this with search results. Given me some ideas though. Thanks for sharing…

 Signature 

Erskine Design: http://www.erskinedesign.com
“Grad student”? - we’ve been here since the start!

Profile
 
 
Posted: 11 January 2007 03:26 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Avatar
Rank
Total Posts:  98
Joined  07-06-2006

I kind of found a way, basically using some source code from the advanced search template (not EE tags as I wanted control over a few bits and pieces, but I’m sure most people could do what they wanted with teh EE tags) at the top of my results template, pulling in the keyword(s) into the hidden keywords field.

Thus, the user gets to use a few advanced search features to refine an existing search.

<h2>{exp:search:total_results} results for <em>{exp:search:keywords}</em></h2>

<
form id='searchform' method="post" action="http://www.newconsumer.com/"  >
<
div>
<
input type="hidden" name="ACT" value="19" />
<
input type="hidden" name="XID" value="" />
<
input type="hidden" name="RP" value="search/results" />
<
input type="hidden" name="NRP" value="" />
<
input type="hidden" name="RES" value="" />
<
input type="hidden" name="status" value="" />
<
input type="hidden" name="search_in" value="" />
</
div>    

<
div class="sort">
<
h3>Refine your search for <em>{exp:search:keywords}</em><h3>
<
input type="hidden" name="keywords" value="{exp:search:keywords}" />
<
select name="weblog_id[]">
<
option value="" >Section...</option>
<
option value="2" >News</option>
<
option value="5" >Views</option>
<
option value="4" >Interviews</option>
<
option value="6" >Our Friends</option>
<
option value="all" >Whole site</option>
</
select>
<
select name="search_in">
<
option value="entries" selected="selected">Titles and Entries</option>
<
option value="titles">Search in Titles</option>
<
option value="everywhere" >Titles, Entries, Comments</option>
</
select>
<
select name="orderby">
<
option value="" >Sort by...</option>
<
option value="title" >Title</option>
<
option value="date" >Date</option>
</
select>
<
select name="where">
<
option value="all" selected="selected">All Words</option>
<
option value="any">Any Word</option>
<
option value="word" >Exact Word</option>
<
option value="exact">Phrase Match</option>
</
select>
<
input type='hidden' name='sort_order' value='asc' />
<
input type='submit' value='Refresh' class='submit' />
</
div>
</
form>

<
table>
<
tr>
<
th>{lang:title}</th>
<
th>{lang:excerpt}</th>
<
th>{lang:author}</th>
<
th>{lang:date}</th>
</
tr>

{exp:search:search_results switch="resultRowOne|resultRowTwo"}

<tr>
<
td class="{switch}" width="30%" valign="top"><b><a href="{auto_path}">{title}</a></b></td>
<
td class="{switch}" width="50%" valign="top">{excerpt}</td>
<
td class="{switch}" width="10%" valign="top">{author}</td>
<
td class="{switch}" width="10%" valign="top">{entry_date format="%d/%m/%y"}</td>
</
tr>

{/exp:search:search_results}

</table>

You can see it at New Consumer which just launched.

 Signature 

Erskine Design: http://www.erskinedesign.com
“Grad student”? - we’ve been here since the start!

Profile
 
 
Posted: 11 January 2007 03:51 PM   [ Ignore ]   [ # 6 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32861
Joined  05-14-2004

Now that is just pretty damn cool.  You’re going to write this up somewhere right? Like ... the wiki? *ducks*

 Signature 
Profile
MSG
 
 
Posted: 11 January 2007 04:00 PM   [ Ignore ]   [ # 7 ]  
Grad Student
Avatar
Rank
Total Posts:  98
Joined  07-06-2006

When I get a chance, I sure will… probably by 2009!!!

 Signature 

Erskine Design: http://www.erskinedesign.com
“Grad student”? - we’ve been here since the start!

Profile
 
 
Posted: 11 January 2007 04:03 PM   [ Ignore ]   [ # 8 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32861
Joined  05-14-2004

*grins* At least it’s here to be found now. Thank you for posting it. =)

Short note at the wiki for now:

http://expressionengine.com/wiki/Dynamically_Sortable_Search_Results/

 Signature 
Profile
MSG
 
 
Posted: 12 April 2007 12:54 PM   [ Ignore ]   [ # 9 ]  
Summer Student
Avatar
Total Posts:  17
Joined  09-14-2006

So Lisa, any chance you’ll share the code for the 2nd option that you alluded to here in the post above?

I want to be able to have a dropdown for sorting the list by category and even using a few of the custom fields in the entries. For instance, if this is my results table:

title | author | series
——————————
one | steve | fall
two | steve | fall
red | john | fall
blue | john | spring
grey | ana | spring

i want to have several dropdowns where the user can select to show posts by: author or series. So if they select author > john it shows this:

———————-
red | john | fall
blue | john | spring

The series would actually be done using categories and the author would probably be a custom field in the entry. I’m assuming I can do that with your second example but am at a loss on how to set it up. Please save me!!!! smile

Profile
 
 
Posted: 12 April 2007 02:07 PM   [ Ignore ]   [ # 10 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32861
Joined  05-14-2004

That page just uses dynamic parameters almost cut and pasted from the docs. =)

 Signature 
Profile
MSG
 
 
Posted: 31 January 2008 12:27 AM   [ Ignore ]   [ # 11 ]  
Summer Student
Avatar
Total Posts:  1
Joined  04-10-2007

Yes! Thank you for this, it works great and is really easy to tweak and abuse for whatever you need. Colly/Pittock - how is your sausage so strong?

 Signature 

Derek Balmer
Hold Fast Creative

Profile
 
 
Posted: 30 April 2008 08:16 AM   [ Ignore ]   [ # 12 ]  
Grad Student
Avatar
Rank
Total Posts:  99
Joined  03-08-2006

At long last, a refound article I had earmarked yonks ago.

Next: how would I go about filtering search results by custom_field. Please don’t say custom sql queries and a smattering of php…

EDIT: Doh, hadn’t scrolled fully. Ignore smile

 Signature 

Seb Neerman

Profile
 
 
Posted: 30 April 2008 02:24 PM   [ Ignore ]   [ # 13 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32861
Joined  05-14-2004

Well, use the search: parameter - that didn’t exist back when this post was written though.  And again, that uses the weblog entries tag, not the search results themselves.

 Signature 
Profile
MSG
 
 
Posted: 01 May 2008 07:53 AM   [ Ignore ]   [ # 14 ]  
Grad Student
Avatar
Rank
Total Posts:  99
Joined  03-08-2006

I think I need a bit of guidance. My current search/results page is already a little complicated to start with. Basically, I have surrounded each weblog’s results with “if” statements in order to output a whole range of information (custom_fields), relative category urls and custom entry paths. Broadly it looks like this:


<h2>Search Results<span>{exp:search:total_results} results found for <em>"{exp:search:keywords}"</em></span></h2>


<
form id='searchform' method="post" action="http://www.website.com/"  >
    <
div>
    <
input type="hidden" name="ACT" value="19" />
    <
input type="hidden" name="XID" value="" />
    <
input type="hidden" name="RP" value="search/results" />
    <
input type="hidden" name="NRP" value="" />
    <
input type="hidden" name="RES" value="" />
    <
input type="hidden" name="status" value="" />
    <
input type="hidden" name="search_in" value="" />
    </
div>   


<
div class="sort">
    <
h3>Refine your search for "<em>{exp:search:keywords}</em>"<h3>
    <
input type="hidden" name="keywords" value="{exp:search:keywords}" />

    <
select name="weblog_id[]">
    <
option value="" >Choose a site section...</option>
    <
option value="2" >Venues</option>
    <
option value="3" >Catering</option>
    <
option value="15" >Entertainment</option>
    <
option value="4" >Suppliers</option>
    <
option value="all" >Whole site</option>
    </
select>

    <
select name="custom_fields">
    <
option value="" selected="selected">Select the Venue Max Capacity</option>
    <
option value="venue-capacity-stand" >Standing Capacity</option>
    <
option value="venue-capacity-meet" >Meeting Capacity</option>
    <
option value="venue-capacity-sit" >Seated Capacity</option>
    </
select>

    <
div>
        <
input type='hidden' name='sort_order' value='asc' /><input type='submit' value='Filter Results' class='submit' />
    </
div>


</
div>
</
form>

<
table border="0" cellpadding="6" cellspacing="1" width="100%" id="results-table">
<
tbody>
{exp:search:search_results switch="resultRowOne|resultRowTwo"}
    
<tr class="search-tr-title">
        <
td class="{switch}" width="100%" valign="top" colspan="2">
        
{if weblog_id == '2'}
        {exp
:weblog:entries weblog="venues" dynamic_parameters="orderby|limit|sort|custom_fields"}

            
<table>
            <
tr>
                <
td width="460px"><p class="foundin">Found in: <a href="{homepage}/venues/">Venues</a> / <a href="{homepage}/venues/for-hire/{venue-primary-category}/">{venue-primary-category}</a></p></td>
                    <
td width="200px" align="right"></td>
            </
tr>
            <
tr>
                <
td colspan="2"><h3><a href="{homepage}/venues/for-hire/{venue-primary-category}/{url_title}">{title}</a></h3></td>
            </
tr>
            <
tr>
                <
td width="460px"><p>{venue-address-street}, {venue-address-city}{if venue-address-county}, {venue-address-county},{/if} {venue-postcode}<p></td>
                <
td width="200px" align="right"><p>Standing Capacity: {venue-capacity-stand}&nbsp;&nbsp;</p></td>
            </
tr>

            </
table>
        
{/exp:weblog:entries}
        {
/if}


        {if weblog_id
== '3'}
        {exp
:weblog:entries weblog="catering" dynamic_parameters="orderby|limit|sort|custom_fields"}


            
<table>Relative Entry Content</table>

        
{/exp:weblog:entries}
        {
/if}



        {if weblog_id
== '4'}
        {exp
:weblog:entries weblog="suppliers"dynamic_parameters="orderby|limit|sort|custom_fields"}

            
<table>Relative Entry Content</table>

        
{/exp:weblog:entries}
        {
/if}


        {if weblog_id
== '15'}
        {exp
:weblog:entries weblog="entertainment" dynamic_parameters="orderby|limit|sort|custom_fields"}

            
<table>Relative Entry Content</table>

        
{/exp:weblog:entries}
        {
/if}
        
</td>
    </
tr>
    <
tr class="search-tr-body">
    <
td colspan="2" class="{switch}" width="100%">
        
{if weblog_id == '2'}
        
<p>{excerpt}<br /><a class="linkcontinue" href="{homepage}/venues/custom/url">Read more</a></p>
        
{/if}
        {if weblog_id
== '3'}
        
<p>{excerpt}<br /><a class="linkcontinue" href="{homepage}/catering/custom/url">Read more</a></p>
        
{/if}
        {if weblog_id
== '4'}
        
<p>{excerpt}<br /><a class="linkcontinue" href="{homepage}/suppliers/custom/url">Read more</a></p>
        
{/if}
        {if weblog_id
== '15'}
        
<p>{excerpt}<br /><a class="linkcontinue" href="{homepage}/entertainmen/tcustom/url">Read more</a></p>
        
{/if}
        
</td>
    </
tr>
{/exp:search:search_results}

As you can see, I’ve added in vain the custom_fields option in the dynamic parameter for each outputted weblog tag. Where / how would you suggest I add the search:parameter and link that to the select drop down menu in the Filtering Form. Obviously I’ve also been aimlessly stabbing around at the select options for “venue-standing-capacity” custom field. I’ve ignored the fact that this is only applicable to the “Venues” site section for now. And of course there are 3 kinds of Capacity types (standing, meeting, sitting). As long as one of them works I’ll be halfway there.

I’m also weary that I may have to create new custom fields for the Capacity types: dropdown selections with pre-formatted ranges (0-100, 101-500, etc). At the moment the client manually inputs a number for each type. Then again a search:venue-capacity-standing=“00” may do the trick. Since all values end in “00”.

 Signature 

Seb Neerman

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64939 Total Logged-in Users: 65
Total Topics: 81914 Total Anonymous Users: 38
Total Replies: 440332 Total Guests: 301
Total Posts: 522246    
Members ( View Memberlist )