Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-09-22 19:43:34

tennapel
Member
Registered: 2009-05-31
Posts: 62

Grouping search results on section

The workings of search escape me.

I want to group the search results on section and order the sections on the search result page according to whatever order I choose.

I’ve tried several approaces, but <txp:if_section> and <txp:article_custom> do not seem to be working within the search results. How to group search results?

Also, I’m curious how search works, because more often than not articles that have a title that matches the search terms exactly are either not shown or somewhere down the results list.

Offline

#2 2009-09-22 19:57:18

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Grouping search results on section

tennapel wrote:

group the search results on section

You can do that by using sort="section asc, posted desc" in the article tag, and using if_different in the search_results form.

and order the sections on the search result page according to whatever order I choose.

Hmm… that may be a bit harder. I think you can do it by using if_article_section tags in the search_results form, as long as you don’t mind needing as many of them as you have sections.

Also, I’m curious how search works, because more often than not articles that have a title that matches the search terms exactly are either not shown or somewhere down the results list.

Not shown at all? Don’t know how that could happen. I’ll leave it to one of the devs to explain how the search works… ;)

There are two plugins to extend the search (in case you hadn’t found them yet): wet_haystack and smd_fuzzy_find.

Offline

#3 2009-09-22 20:34:29

tennapel
Member
Registered: 2009-05-31
Posts: 62

Re: Grouping search results on section

Els, THANK YOU! I’ve been staring all night at the <txp:section> where I should use <txp:if_article_section>, now all my results are popping up, grouped on section :-)

Offline

#4 2009-09-22 20:51:59

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Grouping search results on section

Hmm… that may be a bit harder. I think you can do it by using if_article_section tags in the search_results form, as long as you don’t mind needing as many of them as you have sections.

Els, curious about this proposed solution. How would you use if_article_section to determine the order of sections?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#5 2009-09-22 21:18:18

tennapel
Member
Registered: 2009-05-31
Posts: 62

Re: Grouping search results on section

It is not very simple, but in the end this works:

I’ve set up a section and separate page for search. In the page I have added:

<txp:article sort="section,score" limit="1000">
    <txp:if_article_section name="section_a, section_b">
        <txp:output_form form="search_results" />
    </txp:if_article_section>
</txp:article>
<txp:article sort="section,score" limit="1000">
    <txp:if_article_section name="section_c, section_d">
        <txp:output_form form="search_results" />
    </txp:if_article_section>
</txp:article>

repeat and rinse for every section. This groups the results in the order of inclusion in the template, sorting on section is not necessary.

Do not look at the amount of queries this generates, for large or heavy traffic sites I would certainly not recommend this.

Offline

#6 2009-09-22 21:24:17

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Grouping search results on section

Yep, that’s what I had in mind. Not an ideal solution at all, but the only one I can think of at the moment.

Offline

#7 2009-09-22 21:28:54

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Grouping search results on section

Ah, ok, now I get it. Thanks tennapel and Els.

BTW, what is the “score” value on sort attribute? Is it anything customized on your installation?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#8 2009-09-22 21:46:39

tennapel
Member
Registered: 2009-05-31
Posts: 62

Re: Grouping search results on section

maniqui wrote:

Ah, ok, now I get it. Thanks tennapel and Els.

BTW, what is the “score” value on sort attribute? Is it anything customized on your installation?

Score is a search result attribute that is part of the <txp:article> tag, see the tag reference

Offline

#9 2009-09-22 21:57:44

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Grouping search results on section

Thanks again, tennapel.
I’ve totally forgot about it.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#10 2009-09-25 18:40:32

nabrown78
Member
From: Northampton, MA, USA
Registered: 2006-10-04
Posts: 294
Website

Re: Grouping search results on section

Hm…couldn’t you sort results by section and then use <txp:if_different /> to separate them with headings if you wanted? Would that result in fewer queries?

Offline

#11 2009-09-27 14:34:57

tennapel
Member
Registered: 2009-05-31
Posts: 62

Re: Grouping search results on section

I don’t think so, because the order of sections is important too

Offline

Board footer

Powered by FluxBB