Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: etc_search: when the default search is not enough
Thanks oleg i will try the code.
Here is the result:
Before:
<!-- Runtime: 0,7800 -->
<!-- Query time: 0,324357 -->
<!-- Queries: 149 -->
After:
<!-- Runtime: 0,5686 -->
<!-- Query time: 0,128171 -->
<!-- Queries: 149 -->
Offline
Re: etc_search: when the default search is not enough
Not that way! :) Totally drop your <txp:article_custom /> block, it’s not needed anymore. Just replace it with <txp:variable ...><txp:php>...</txp:php></txp:variable>.
Last edited by etc (2014-02-25 10:26:41)
Offline
Re: etc_search: when the default search is not enough
etc wrote #279217:
Not that way! :) Totally drop your
<txp:article_custom />block, it’s not needed anymore. Just replace it with<txp:variable ...><txp:php>...</txp:php></txp:variable>.
I think it s not possible: the count is depending on article_custom not on txp:article (i put it there only to avoid the anoying message: the page havent a txp:article, but the counting is made using the article_custom itself cause there 4 variables that must be taken (keywords, category, custom_field)
Thanks for your effort to help me polish the website speed
Offline
Re: etc_search: when the default search is not enough
Dragondz wrote #279228:
I think it s not possible: the count is depending on article_custom not on txp:article (i put it there only to avoid the anoying message: the page havent a txp:article, but the counting is made using the article_custom itself cause there 4 variables that must be taken (keywords, category, custom_field)
ah, ok, my bad. But I still think using
<txp:etc_numpages pageby="1" keywords=".." category="..." cf="..." />
from etc_pagination, will be much faster (and cleaner). Actually, you won’t even need this variable, since etc_pagination will do all pagination work. You can also do it in pure <txp:php> with safe_count function.
The reason I insist is that <txp:article_custom /> retrieves the whole data (body, excerpt, …) of >400 articles from db just to count them, unnecessary consuming time and memory. But I leave it with you.
Offline
Re: etc_search: when the default search is not enough
Thanks to point me to that oleg I really appreciate your help.
If i have some time i will investigate further the pagination system but right now it s not possible due to time limit in the project.(and in my life too).
I understund that as a coder we try to make the most efficient code in each work we make and it s a good manner to work, but in the joblife sometimes we must make some compromise and think between the time consuming and result you need, i put in the code what i know right now, it s better than the code i did last year and i hope that my code next year will be better than today.
When i will understund how to use etc_query i think i can say that i have really improved my skills ;)
Really thanks Oleg for all your help again.
Offline
#36 2014-05-13 13:56:20
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
I need faceted search in articles with 2 <select>‘s, something like this:
<select name="q">
<option value="" selected="selected">Choose min value ...</option>
<option value="2000">< 2000</option>
<option value="4000">4000</option>
<option value="6000">6000</option>
<option value="8000">8000</option>
<option value="10000">10000</option>
</select>
<select name="q">
<option value="" selected="selected">Choose max value ...</option>
<option value="2000">< 2000</option>
<option value="4000">4000</option>
<option value="6000">6000</option>
<option value="8000">8000</option>
<option value="10000">10000</option>
</select>
<input value="Search" type="submit" />
The search result should show all results tween min and max value selected. The value is stored in custom_1. I tried but couldn’t find a solution.
Last edited by element (2014-05-13 14:19:34)
Offline
Re: etc_search: when the default search is not enough
Hello,
currently, it works like this:
- create (in admin
etc_searchtab) anarticle-type search form withquery
{custom_1::/^(\d+)\.\.(\d+)$/::{*} BETWEEN $1 AND $2}
- assuming the above form has
id=1, create (in your page form) the following search input form:
<txp:etc_search id="1" label="Custom_1 between" format="{min}..{max}">
<input name="q" type="hidden" value="1" /><!-- to trigger if_search -->
<select name="min">
<option value="0" selected="selected">Choose min value ...</option>
<option value="2000">2000</option>
<option value="4000">4000</option>
<option value="6000">6000</option>
<option value="8000">8000</option>
<option value="10000">10000</option>
</select>
<select name="max">
<option value="10000" selected="selected">Choose max value ...</option>
<option value="2000">2000</option>
<option value="4000">4000</option>
<option value="6000">6000</option>
<option value="8000">8000</option>
<option value="10000">10000</option>
</select>
<input type="submit" />
</txp:etc_search>
- replace
<txp:article />with<txp:etc_search_results />in theif_searchpart of your page form.
Quickly tested, it should work, but don’t hesitate about feedback/tuning.
Offline
#38 2014-05-13 15:53:31
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
Thanks for the help. It looks like it works :-)
One more question (hopefully), is there a way to sort the search results according to custom_1?
Offline
Re: etc_search: when the default search is not enough
element wrote #280779:
One more question (hopefully), is there a way to sort the search results according to custom_1?
Yes, by adding ORDER BY custom_1 (ASC or DESC) to query:
{custom_1::/^(\d+)\.\.(\d+)$/::{*} BETWEEN $1 AND $2} ORDER BY custom_1
You can also add additional WHERE conditions if necessary:
{custom_1::/^(\d+)\.\.(\d+)$/::{*} BETWEEN $1 AND $2} AND Section='products' ORDER BY custom_1
Last edited by etc (2014-05-13 16:02:30)
Offline
#40 2014-05-13 16:18:26
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
Right, didn’t think about it. Thanks.
I had to add +0 to sort them properly.
{custom_1::/^(\d+)\.\.(\d+)$/::{*} BETWEEN $1 AND $2} ORDER BY custom_1+0
Offline
Offline
#42 2014-05-13 16:51:36
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
It works on a PHP 5.3 server, not on a PHP 5.2 server.
Damn, I tried the solution in this post. I replaced the line 392, added the function and the plugin installs but the search on the website doesn’t work.
I get this when I use the search: Fatal error: Call to undefined function safe_escape() in /home/xxxx/public_html/textpattern/lib/txplib_misc.php(653) : eval()’d code on line 421
Offline
Re: etc_search: when the default search is not enough
Ah yes, sorry, safe_escape() has been introduced in 4.5.0. You can replace the line
$params['q'] = safe_escape($params['q']);
with
global $DB;
$params['q'] = mysql_real_escape_string($params['q'], $DB->link);
in the plugin code.
Edit: though this function will be depreciated in future PHP versions.
Last edited by etc (2014-05-13 17:26:55)
Offline
#44 2014-05-13 17:39:12
- element
- Member
- Registered: 2009-11-18
- Posts: 99
Re: etc_search: when the default search is not enough
Thanks, etc. You’re awesome. It works!
Offline
Re: etc_search: when the default search is not enough
Offline