user-pic

Alphabetize Tag Search Results?

Vote 0 Votes

Is it possible to alphabetize the results of mt:searchresults?

Right now I use the MT tag function and search to display my recipe index here:

http://www.elise.com/recipes/subject-index.php

When you click on any of these tags however (take http://www.elise.com/recipes/tag/Chicken%20Breasts for example) the results are in order of when they first appeared on the blog, most recent first, rather than alpha.

It would make a lot more sense for the results to be in alpha order.

Possible?

Reported on Movable Type 4.2

10 Replies

| Add a Reply
  • What should the list of Entries tagged with Chicken Breasts be ordered by, if not by authored_on date? You say alpha (meaning alphabetically I guess) but what field/criteria do you want to order by? Entry title?

  • Yes, alphabetized by title. As if it were the index in a cookbook.

  • Yes that's possible.

    1. you could create 26 mt:If blocks each asking if EntryTitle starts with a given letter like="ˆ(A|a)", thus permitting only those Entries to pass that start with the given letter.

    2. Use mt:EntryIfTagged 26 times. This would require you to tag each Entry first, for example: @a, @b, or @alpha-a, @alpha-b, etc..

    3. Create an Entry template with an archive mapping that publishes entries to folders /a, /b, /c etc. based on your input into a custom field on the Edit Entry screen. Then try to create a loop with the mt:Folders tag .... all right. I'll stop here. This leads nowhere.

    Hm, what else...

  • Hmm. Number 1 seems doable, though it seem like it might slow down the rendering of the results. It's also rather clunky.

    There should be an attribute for the result listing.

  • Clunky, and trying way too hard, primarily by sticking with the core tags. And yes, there will be major impact on rendering time.

    Have you tried the Order plugin(as the sort's simple) or Collate? The search system is always a little weird, but assuming that doesn't come into play, Order will make this trivial.

    Also a sort attribute is entirely reasonable for search results. File a feature request?

  • Hi Su, just tried the Order plugin. Couldn't get it to do anything, but that could be because I don't really know how to implement the code properly in to mt:searchresults code. Really wish plugin authors would explain their examples better. I'll have Jesse take a look at it next week. Thanks!

    Given that a sort attribute is an entirely reasonable thing for search results, I was hoping that it was already in there somewhere. I'm sure someone has filed this as a feature request years ago, but can do so again. Thanks again!

  • Hi, Elise, trhis issue did come up in the old forums in 2006: Search Titles Only And Alphabetize Search Results, in the next to last post, by elf#3:

    In the template tags and the Widget: search, it looks like search is limited, but if you read the 3.2 manual section, apparently you can extend the search functionality WELL beyond what is on the basic template. (I had to laugh, because the template that I'm using offers up a "regex" search checkbox option to the user, as if anyone but geeks knew that that was ... chuckle).

    It appears there are parameters already built in to limit search to certain field and possibly to sort on more than create date:

    <b>Sort By:</b>
    <select name="SearchSortBy">
    <option value="created_on">Authored On Date</option>
    <option value="title">Title</option>
    </select><br />
    <b>Sort Order:</b>
    <select name="ResultDisplay">
    <option value="ascend">Ascending</option>
    <option value="descend">Descending</option>
    </select><br />


    Creating a Search Form -- the 3.2 docs page the poster references -- says,

    Most of the bells-and-whistles in this form may not be overridden by the reader. Here is an HTML form that exposes those options to the reader:


    [...code, including that cited above...]

    This form exposes all of the options to the reader for tailoring to their own liking. Optionally, these parameters can be passed to the search script via hidden input tags. A benefit of using this approach is that configured options are set only for the reader and won't alter parameters in the MT configuration file that may be used by the search elsewhere in the site.


    From the old docs,

    Chapter D: Configuration Directives SearchSortBy

    The sort column for the search results. Using created_on will sort the entries by the authored on date; using title will sort the entries by title. This can be used with ResultDisplay to sort in either ascending or descending order.

    Default value: created_on

    Example:

    SearchSortBy title


    It sounds doable, if you can change option values.

  • Hello shenews,

    Bingo, thank you! The following configuration directives worked!

    SearchSortBy title
    ResultDisplay ascend

    You have to include the "ResultDisplay ascend" or the "SearchSortBy title" will not work.

    Now http://www.elise.com/recipes/tag/Chicken%20Breasts is in alphabetical order.

    The downside of this technique for those who might be interested in it is that it affects all search results on your MT install, not just the specific instance of one search result. In my case, it doesn't matter as I use Google search for almost all other searches on the site, and in the case that I do use mt search, I want the results listed by title.

    The upside is that it is the easiest thing in the world to implement. No plugins. No messing with code on templates.

  • Excellent!

    I wonder if it could be restricted for use on just a specific blog and/or tag. Something like

    <select name="SearchSortBy">
    <mt:IfTagSearch tag="Chicken">
    <option value="title">Title</option>
    <mt:Else>
    <option value="created_on">Authored On Date</option>
    </mt:IfTagSearch>

    and the same for the sort order. (Not sure about syntax, if you'd need to use an mt:If tag="Chicken" and the same kind of conditional for "Include blogs" or if you can change that part of the form at all.)

    I've been a frequent visitor to your recipes, btw. Great cooking blog.

  • Hmm. Good question. In any case the code works for my site as is, so no more messin' with it for me! Thanks again.

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1195 3842

Last Topic: Comment form customization by anisa on Feb 8, 2010

60 184

Last Topic: Dynamic Publishing - Blank Screen by Sivaram M on Dec 15, 2009

955 2985

Last Topic: MT5 - Cookie Problems by Dave Cross on Feb 9, 2010

68 213

Last Topic: How to add Custom Fields by gregoryttp on Feb 5, 2010

19 67

Last Topic: Custom main index page by Richard on Feb 7, 2010

42 169

Last Topic: I want to write my own wordpress plugin by Xarzu on Jan 31, 2010

11 21

Last Topic: Monthly Calendars Help Needed by joe leblanc on Jan 19, 2010

91 326

Last Topic: SpamLookup Keyword Filter 2.1 not work by b.n09 on Nov 17, 2009

52 178

Last Topic: Assets - No options by Chelle on Feb 5, 2010

code.sixapart.com

128 444

Last Topic: ActionStream with Movable Type 5.01 by Parneix on Jan 24, 2010

154 468

Last Topic: URGENT! Help needed w/ Virus by PhilContrino on Feb 1, 2010