Problems, need help? Have a tip or advice? Post it here.
14 posts Page 2 of 2
Hi Trendoman

I have managed to get the page working without (I believe) removing that line of code. The documentation for the use of 'searchable' says only that it will exclude the tag from search results, not filtering or orderby. KK managed to copy my code and get it to work, and I have always been using searchable='0'

The code only seems to break after reintroducing the config_form_view code.

KK can you confirm that the code worked for you, with the searchable='0' tag?
KK can you confirm that the code worked for you, with the searchable='0' tag?

Yes, I can confirm that the code worked for me with searchable='0'.

That said, @trendoman is absolutely correct in his observation that with searchable='0', there should be nothing for Couch to sort on (or search).

So, what would explain this discrepancy in behavior?
A bug actually :(
As it happened, Couch ignored the searchable param of <cms:editable> the very first time a field is created; however, it corrects this the next time the template is accessed by the super-admin - which is why this bug remained hidden for so long.

So, in your case, the pages saved before the searchable gets the set value of 0 would have the text to sort on while the pages saved later will have blank values. This would explain what you have been experiencing.

I have committed a fix for this to GitHub.
Please use the revised tags.php file from there.

You'll need to set searchable='1' for the sorting to work correctly (making sure to access the template as super-admin for the change to get persisted).

I am sorry for this but additionally, you'll also need to access the edit screens of each individual page and press 'save' to cause the country codes to replace the blanks.

Hope this helps.
Well - at least we have solved the confusion!! :D

Thank you so much KK!

I do feel, sometimes, like important notes are missing from the documentation - I had no idea that "searchable='0'" would also mean that 'orderby' would not work. It doesn't seem crazy that this is the case, but it is just not what I would assume without it being explicitly mentioned. Perhaps a little note could be added to https://docs.couchcms.com/tags-reference/editable.html#searchable so that it reads:

Setting the searchable parameter to '0' for an editable region will exclude its contents from search results. This will also make the editable field unavailable to couch's internal search and filter functions, for example when called using the "orderby" parameter of pages.


Thanks both for your assistance - I have removed the "searchable='0'" from the code, all appears fine.

As another aside - I do think it would be nice to be able to have searchable='0' and retain the ability to orderby. I am sure I am not the only one who has fields that are helpful for ordering (such as a two-letter code) which would be unhelpful to trigger search results. Just a thought, that perhaps the two could in future be separated? I can't see a situation where someone would have a problem with wanting to exclude a field from orderby, since it only matters when explicitly called in the code, no?
Before I posted my previous reply I had confirmed that orderby clause in pages tag generates an SQL query with dependency on "search_value" column. Each editable field has both "value" and "search_value" with the latter used for filters and search and the former is the value verbatim. Code I used was simple, as always using return_sql='1' -
Code: Select all
<cms:pages masterpage='clonable-related-10.php' orderby='location' order='desc' return_sql='1' limit='5' /><hr>
=> ....sql query... ORDER BY t0.search_value desc

So, as KK correctly pinpoited that some pages were saved before that "searchable" setting was nullified hence the sorting worked with text from database.

Q: Why would there be 2 values for a field?
A: Because a field can have HTML - something like <b>WA</b> to highlight certain location. With this, Couch saves the HTML value verbatim into "value" column and "WA" to "search_value" for us to have only text without tags appearing in search results and also make filters with custom_field='' clause. Now you should see that if a field is set to be un-searchable, then it would lose the "search_value" content and it will still be impossible to filter on "value" content - because it can be anything, including tags.

As a result, with such tight coupling of both values and serious restrictions that designer might put as you said (both un-searchable but still filterable), we can use a custom query to get what asked. In fact, before the previous post I had already coded such query and it works just fine to order pages by "value" content - of course using this you now bear full responsibility over content - you must make sure the field holds what you need, because filters and orders will be performed on value verbatim (HTML will break the natural order!).
Code: Select all
<cms:query sql="
SELECT p.id, p.template_id, cdt.value AS `mylocation`
FROM couch_pages p
INNER JOIN couch_templates mytemplate ON mytemplate.id = p.template_id
INNER JOIN couch_data_text cdt ON cdt.page_id = p.id
INNER JOIN couch_fields myfield ON myfield.id = cdt.field_id
WHERE
#--- EDIT: ------------------#
mytemplate.name = 'clonable-related-10.php'
AND myfield.name = 'location'
#----------------------------#
AND p.publish_date < NOW()
AND NOT p.publish_date = '0000-00-00 00:00:00'
AND p.parent_id=0
" fetch_pages='1' orderby='mylocation DESC' limit='5' >
    <cms:show k_page_id /> - <cms:show location /><br>
</cms:query>
14 posts Page 2 of 2