Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-03-31 14:36:35

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,597
Website

Overriding the score-based order of search results? [resolved]

(This is with the current v4.9.0 dev)

I thought it would it be as simple as adding the sort="Posted desc" attribute to the tag, but the search results still get output according to “score desc”. Weirdly, I can use sort="score asc" or even sort="rand()" to change the output but sort="Posted desc" and sort="Lastmod desc" have no effect on the order of the search results.

The tag trace shows:

<txp:article[1] form="search_results_article" sort="Posted desc" />
…
[SQL: SELECT *, MATCH (`Title`,`Body`) AGAINST ('searchterm') AS score FROM textpattern WHERE Status >= 4 AND Posted <= from_unixtime(2147483647) AND (Expires IS NULL OR Expires>=from_unixtime(2147483647))  AND ( (Title LIKE '%searchterm%') OR (Body LIKE '%searchterm%') ) ORDER BY score DESC LIMIT 0, 10 ]

Interestingly the trace show ORDER BY score DESC for the sort attribute settings that do have an effect on the output.

In etc_search I can add ORDER BY posted DESC (or ORDER BY created desc for file searches) to the end of my query to get the most recent matches first, but not with the standard search.

Am I doing something wrong, or is this a bug, or how it’s designed (match as score)?


TXP Builders – finely-crafted code, design and txp

Offline

#2 2024-03-31 18:06:55

etc
Developer
Registered: 2010-11-11
Posts: 5,054
Website GitHub

Re: Overriding the score-based order of search results? [resolved]

It’s certainly etc_search interfering, sorry. Try disabling it to be sure.

Offline

#3 2024-03-31 20:11:52

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,597
Website

Re: Overriding the score-based order of search results? [resolved]

I think you’re right.

Interestingly the txp:article tag behaves differently with etc_search activated. I’m using etc_search for searching files, but for the regular (i.e. non etc_search) site search, I’m just using txp:tags.

With etc_search activated, this tag sufficed (note I have my search results in a dedicated section, so the txp:article tag only does search duties, no other article handling):

<txp:article[1] form="search_results_article" sort="Posted desc" />

but the results come out with score desc sort order regardless.

When etc_search is deactivated, I need:

<txp:article[1] searchform="search_results_article" searchall="1" sort="Posted desc" />

to get results, but they are then sorted in recent->earliest order.

For the moment, I shall live with it, because I need the file search capability.

—-

BTW: I received an Enum data truncated for column 'type' error when reactivating the plugin. I tracked it down to the following line in function etc_search_install:

safe_alter('etc_search', "MODIFY `type` enum('article','image','file','link','category','section') NOT NULL");

which needs 'custom' adding to the list to match the table

safe_alter('etc_search', "MODIFY `type` enum('article','image','file','link','category','section','custom') NOT NULL");

I’m guessing this was a special version you updated recently and that was designed to bring earlier installs up to scratch, and ‘custom’ was just missing. I do happen to have a custom search type in use.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2024-03-31 22:15:57

etc
Developer
Registered: 2010-11-11
Posts: 5,054
Website GitHub

Re: Overriding the score-based order of search results? [resolved]

The reason is very simple: etc_search substitutes itself to article tag. It was ok at the moment of the last update, but <txp:article /> has evolved since. I need to take a closer look, meanwhile just comment out this line at the top of the plugins code:

		->register('etc_search_results', 'article')

Offline

#5 2024-03-31 22:44:26

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,597
Website

Re: Overriding the score-based order of search results? [resolved]

etc wrote #337001:

The reason is very simple: etc_search substitutes itself to article tag … just comment out this line at the top of the plugins code:

->register('etc_search_results', 'article')...

That does indeed resolve it. So glad I asked – and that you answered, and that it was straightforward enough to resolve. I would have spent a long time trying to find that on my own.

I think I’ve only touched on the power of this plugin, but it is has been extremely useful on more than one occasion.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB