Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#49 2014-08-07 18:29:07
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
Yeah, two tags I’m missing right now is <txp:etc_search_term />
and also <txp:if_etc_search />
.
Offline
Re: etc_search: when the default search is not enough
Rather than introducing new tags, version 0.9.1 (download) fixes the behavior of <txp:if_search />
and <txp:search_term />
in these cases. You don’t need
<input name="q" type="hidden" value="1" /><!-- to trigger if_search -->
anymore, and <txp:search_term />
should output something like 2000..6000
. If you want to output 2000 and 6000
instead, change (admin-side) the search query
to
{custom_1::/^(\d+)\D+(\d+)$/::{*} BETWEEN $1 AND $2}
and format
attribute of <txp:etc_search />
to {min} and {max}
. Please try and comment if necessary.
Last edited by etc (2014-08-08 17:53:03)
Offline
#51 2014-08-11 13:42:40
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
Changing the search query yields no search results, on the positive side, the search term shows up correct.
Offline
Re: etc_search: when the default search is not enough
element wrote #282813:
Changing the search query yields no search results…
I’d bet it doesn’t, it sees spaces as logical AND
. Sorry about it, I should have tested it first. If you use etc_search
only in this form, try to replace the part "AND":" "
in Logical operators
(admin tab) with something else, e.g. "AND":"+"
(untested again).
Offline
#53 2014-08-12 09:49:43
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
That seems to do it. Thanks.
Offline
Re: etc_search: when the default search is not enough
Version 0.9.3 (both php and js) released:
- url variables (other that
q
) are easier to use in search queries; - individual (per search form) logical operators;
- more precise
<txp:etc_search_result_excerpt />
; - minor js and other tweaks.
Offline
Re: etc_search: when the default search is not enough
Version 0.9.5: minor php update to enable category/section data population.
Offline
Re: etc_search: when the default search is not enough
Hi Oleg,
Trying to wrap my head round this one and I think it should be possible with etc_search_results but I’m not sure about how to go about structuring the query (or perhaps several queries?). I need a simple (non-live) text string (?q=) search to match:
- {Title, Body} from the
textpattern
table as normal (I also need to know section, category and article_url_title), but:- exclude articles from the
aktuelles
section where the custom_fieldevent_end
(format: YYYY-MM-DD) is in the past. - exclude articles from certain sections (I’ve marked them as non-searchable in the presentation > sections panel. Is that sufficient?)
- exclude articles from the
- {linkname, description} from
txp_link
. I also need to retrieve the {category} field so that I can tailor the output link as necessary.
I don’t need any special prefixes in the search string. Ideally the user types their text query and are shown a structured set of search results, ideally grouped (or maybe just labelled) by type.
Background (if it helps): I have some sections that are not actual pages in themselves but show as part of another page in another section (i.e. for those articles the permalink will be overridden by /section/page#article-url-title
). Likewise the links are not in a section of their own but show as part of two other articles (hence the need to identify the link’s category). Here the permalink would be overridden by /section/page#sanitized-link-title
. I was going to do this with smd_multi_choice (which provides switch/case tags) to handle the output for these special cases on a case-by-case basis.
TXP Builders – finely-crafted code, design and txp
Offline
Re: etc_search: when the default search is not enough
Hi Jakob,
that seems doable, though I have not tested it. So:
I need a simple (non-live) text string (?q=) search to match:
- {Title, Body} from the
textpattern
table as normal (I also need to know section, category and article_url_title), but:
- exclude articles from the
aktuelles
section where the custom_fieldevent_end
(format: YYYY-MM-DD) is in the past.- exclude articles from certain sections (I’ve marked them as non-searchable in the presentation > sections panel. Is that sufficient?)
Create an article-context query (id=1
)
{Title, Body} AND (Section != 'aktuelles' OR custom_n > '<txp:php>echo date("Y-m-d");</txp:php>')
etc_search
will populate all article fields and automatically exclude future/expired and non-searchable articles.
- {linkname, description} from
txp_link
. I also need to retrieve the {category} field so that I can tailor the output link as necessary.
A simple link-context query (id=2
) then:
{linkname, description}
Define some appropriate static output forms for both search queries. You can use usual article/link fields tag therein.
I don’t need any special prefixes in the search string. Ideally the user types their text query and are shown a structured set of search results, ideally grouped (or maybe just labelled) by type.
Now, on the public side, create a search input:
<txp:etc_search id="1,2" live="0" />
and replace <txp:article />
by <txp:etc_search_results />
in the “if_search” part of your page form. This should give you a pagination-ready list of articles followed by links. Amend it with wraptag/break
if necessary. And don’t hesitate to shout if things go west. :)
Last edited by etc (2014-10-19 19:31:39)
Offline
Re: etc_search: when the default search is not enough
Excellent! That more or less did it. Thank you so much!
I tried something similar with the links but was using the normal search form not the etc_search tag so wasn’t getting the response I expected, and it took a while before I realised I needed to use link tags for the search results form. Now I have it working quite nicely, and it’s also nice and fast. The article query wasn’t quite as involved as I expected (having read the example caption query) – perhaps that would be a good (basis for an) example for the help docs.
TXP Builders – finely-crafted code, design and txp
Offline
Re: etc_search: when the default search is not enough
jakob wrote #284959:
Excellent! That more or less did it. Thank you so much!
You are welcome, and sorry for the fuzzy help. If etc_search
can somehow do more than less, just tell me what it lacks.
I tried something similar with the links but was using the normal search form not the etc_search tag so wasn’t getting the response I expected…
Well, given that <txp:etc_search_results />
can output the results of multiple search queries, we have to send it the ids of the ones we need (you don’t want to trigger 20 search queries from different tables at once). So, if you prefer to use the standard search form, you have to append etc_search=somesecurityhashstring.id1.id2
url parameter to trigger <txp:etc_search_results />
. On the other hand, its easy to customize the search input form using <txp:etc_search />
as container, where you can place other (i.e. not q
) inputs/buttons if necessary. I understand you not always have choice, though, especially with third-party forms.
and it took a while before I realised I needed to use link tags for the search results form.
Tags are not really needed, since you can also use {field}
placeholders in output forms, but the fields coming from txp_links
table, you naturally can not expect <txp:title />
or other article tags to produce anything.
Thanks for an example suggestion, I will include it in the next version.
Offline
Re: etc_search: when the default search is not enough
I’d like to add one further element to the first search query above:
{Title, Body} AND (Section != 'aktuelles' OR custom_n > '<txp:php>echo date("Y-m-d");</txp:php>')
and that is to also match articles that are tagged with the search term (using smd_tags). This is a good deal more complicated and I wonder if I can presume on you for further assistance. In case you’re not familiar with smd_tags, two tables are relevant:
smd_tags
which has the columnsid
,name
, andtitle
where the search term would match “name” or “title” (ideally with contains rather than an exact match).smd_tags_used
which has the columnsitem_id
which matches the article id in the textpattern table andtag_id
which matches the id in the smd_tags table.
TXP Builders – finely-crafted code, design and txp
Offline