Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#97 2017-03-10 00:43:51

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: etc_search: when the default search is not enough

etc wrote #302588:

The response comes from etc_search, so the redirection should be ok. Could you test the modified version, please?
# Name: etc_search v0.9.5...

This modified version made the difference for me too! Thanks!


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#98 2018-06-11 12:59:07

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

Re: etc_search: when the default search is not enough

Hi Oleg, forgive me if I’m raising something you’ve already resolved. My plugin version says 0.9.5 and your site also says 0.9.5 but maybe I don’t have all the most recent edits you’ve made above.

My search results were dramatically shorter after upgrading from 4.5.7 (dev) to 4.7, so I went in search of why and tried your debug-query output directly on the database.

I’m sure you’ll know why right away: for txp 4.7, the following lines need modifying from Expires ='0000-00-00 00:00:00' to Expires IS NULL:

			$count = "SELECT COUNT(*) FROM $table WHERE Status >= 4 AND Posted <= '$ts' AND (Expires ='0000-00-00 00:00:00' OR Expires>='$ts') $s_filter AND $query";
			$query = "SELECT *".($order ? '' : ", MATCH ($safe_search_fields) AGAINST ('$q') AS score")." FROM $table WHERE Status >= 4 AND Posted <= '$ts' AND (Expires='0000-00-00 00:00:00' OR Expires>='$ts') $s_filter AND $query";

need changing to:

			$count = "SELECT COUNT(*) FROM $table WHERE Status >= 4 AND Posted <= '$ts' AND (Expires IS NULL OR Expires>='$ts') $s_filter AND $query";
			$query = "SELECT *".($order ? '' : ", MATCH ($safe_search_fields) AGAINST ('$q') AS score")." FROM $table WHERE Status >= 4 AND Posted <= '$ts' AND (Expires IS NULL OR Expires>='$ts') $s_filter AND $query";

If I’m wrong or my syntax is wrong, do let me know.

EDIT: Just wanted to say, this really is a very powerful plugin. If you need to do anything a bit more complex than a regular search, then it’s an absolute GodOlegsend.


TXP Builders – finely-crafted code, design and txp

Offline

#99 2018-06-11 13:25:24

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

Re: etc_search: when the default search is not enough

jakob wrote #312508:

Hi Oleg, forgive me if I’m raising something you’ve already resolved. My plugin version says 0.9.5 and your site also says 0.9.5 but maybe I don’t have all the most recent edits you’ve made above.

Oops, hi Julian, frankly, I don’t remember how, but 0.9.5 available on my site seems to be patched a good while ago. Sorry if I have forgotten or missed to change the version number, I guess 0.9.6 (still unreleased) was already a work in progress at that time.

Sorry for the trouble and thanks for the reminder and the appreciation. Please anyone using it on txp 4.6+ and (only if) facing this problem redownload the latest version.

Offline

#100 2018-07-17 05:54:09

lazlo
Member
Registered: 2004-02-24
Posts: 110

Re: etc_search: when the default search is not enough

Hi Oleg

I have a custom search fill form for search and want to incorporate etc_search with it but I can’t seem to do a live search. This is my first time doing a live search with etc_search, so passing the query seems opaque to me.

<!-- Search Block -->
                     <li>
                     <i class="search fa fa-search search-btn"></i>
                     <div class="search-open">
                     <form action="./index.php" method="get">
                     <div class="input-group animated fadeInDown">
                     <input type="hidden" name="s" value="search" />
                     <input name="q" type="text" class="form-control" placeholder="Search">
                     <span class="input-group-btn">                                    
                     <button type="submit" class="btn-u" type="button">Go</button>                                
                     </span>                               
                     </div></form> 
                     </div>
                     </li>
<!-- End Search Block --> 

My results code looks this this:

<!--=== etc_search ===-->
<txp:etc_search_results id="10" form="newslistHeadlines">
<txp:else />
<txp:variable name="no_news" value="NULL" />
</txp:etc_search_results>

If I manually put the query in the code above it works but doesn’t pick up query from the search form.
The default textpattern search code picks up the query.

Thanks
Les

Last edited by lazlo (2018-07-17 05:56:07)

Offline

#101 2018-07-18 10:46:30

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

Re: etc_search: when the default search is not enough

Hi Leslie,

can not test right now, sorry, but try to replace

                     <form action="./index.php" method="get">
                     ...</form> 

with

                     <txp:etc_search id="10" action="./index.php" method="get">
                     ...</txp:etc_search>

Offline

#102 2018-07-24 16:07:34

lazlo
Member
Registered: 2004-02-24
Posts: 110

Re: etc_search: when the default search is not enough

etc wrote #313060:

<form action="./index.php" method="get">...

with

<txp:etc_search id="10" action="./index.php" method="get">...

That worked perfectly, thank you.

Another question:
Is there a way to can combine “ORDER BY section Desc” and “ORDER BY posted Desc” into a single call?
I want to separate the search results into Section results then list them by date.

Offline

#103 2018-07-24 17:07:54

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

Re: etc_search: when the default search is not enough

lazlo wrote #313124:

Is there a way to can combine “ORDER BY section Desc” and “ORDER BY posted Desc” into a single call?
I want to separate the search results into Section results then list them by date.

Yes, the standard SQL syntax applies:

ORDER BY Section DESC, Posted DESC

Combined with <txp:if_different /> this should allow you to section the presentation if needed.

Offline

#104 2018-08-19 22:22:37

lazlo
Member
Registered: 2004-02-24
Posts: 110

Re: etc_search: when the default search is not enough

I get the following error when I used the code above, everything seems to work but is there a way to fix the error?

Tag error: <txp:etc_search id="10" action="./index.php" method="get"> ->  Textpattern Notice: Unknown tag attribute: method. while parsing form master_page_header_unity on page front

- L

Offline

#105 2018-08-20 07:39:09

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

Re: etc_search: when the default search is not enough

lazlo wrote #313512:

I get the following error when I used the code above, everything seems to work but is there a way to fix the error?

Tag error: <txp:etc_search id="10" action="./index.php" method="get"> -> Textpattern Notice: Unknown tag attribute: method. while parsing form master_page_header_unity on page front...

It looks like method isn’t actually an attribute of etc_search so you can just remove it.


TXP Builders – finely-crafted code, design and txp

Offline

#106 2023-10-15 10:25:27

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

Re: etc_search: when the default search is not enough

Returning to this phenomenal plugin after a longish hiatus … and, of course, I have a question: how can I combine search results from different contexts?

Background: I have a largish archive of PDFs each with details of their contents in the description field. I’ve managed to create a file-only search quite easily:

  • Add a new search form
  • Site context to file context.
  • Set query to {description} (add other fields as desired).
  • In the Static Search box enter the results code, and Save. A quick proof of concept is:
<txp:file_download_name wraptag="p" />
<txp:etc_search_result_excerpt type="file" field="description" />

Embellish as required.

  • Add a <txp:etc_search id="1" /> tag to you page template (the id number equals the number in the plugin search settings pane).
  • Add <txp:etc_search_results /> in the <txp:if_search>… block of your template where the results should appear.

—-

My question(s):

  1. How might I create a single site-wide search form that also includes these results? Presumably I need to set a custom context and create some kind of custom query that JOINs the results?
    Or is there a way to do {file: description}, {article: Title, Body} or {file:description, article:Title, article:Body} or similar?
  1. And connected to that, is there a way in which I can identify a result by context, e.g. the file results excerpt and permlink will be different for files and articles?
    I guess one way might be to use txp:evaluate to test for file-related excerpt results… but maybe there’s a better way?

Thanks for any advice!


TXP Builders – finely-crafted code, design and txp

Offline

#107 2023-10-15 12:29:50

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

Re: etc_search: when the default search is not enough

jakob wrote #335788:

Returning to this phenomenal plugin after a longish hiatus …

Hi Julian, same for me :-)

How might I create a single site-wide search form that also includes these results? Presumably I need to set a custom context and create some kind of custom query that JOINs the results?

If I understand correctly, you rather need UNION here. A custom search query like

SELECT Excerpt AS description FROM textpattern WHERE {Excerpt}
UNION ALL
SELECT description FROM txp_file WHERE {description}

would work if etc_search was not trying to be too smart with pagination (a quirk I should fix). But, unless you need to mix data (e.g. sort by posted), you can create two (or more) forms, one per content type, and output

<txp:etc_search_results id="1,2" />

Or is there a way to do {file: description}, {article: Title, Body} or {file:description, article:Title, article:Body} or similar?

Interesting idea, but this would rather fit for JOIN. You can already do it, e.g.

SELECT txp.ID, txp.Title, img.alt, img.id im FROM textpattern txp JOIN txp_image img ON FIND_IN_SET(img.id, txp.Image) WHERE {img.alt}

And connected to that, is there a way in which I can identify a result by context, e.g. the file results excerpt and permlink will be different for files and articles?

If this query worked, you would be able to access to {type} field and call appropriate output forms:

SELECT 'article' AS type, Excerpt AS description FROM textpattern WHERE {Excerpt}
UNION ALL
SELECT 'file' AS type, description FROM txp_file WHERE {description}

But I need to fix it, as said above.

Offline

#108 2023-10-15 14:32:27

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

Re: etc_search: when the default search is not enough

Brilliant! That’s a great help. I’m never quite sure how to put together these more complex queries so I’ll explore and get back with any questions if I have them. I presume the id="1,2" attribute just chains the output from two search queries one behind the other. That may even suffice if the site owner decides it would make more sense not to interleave search results from mixed sources.

The next step after this will also be including tags in the search, but step by step :-)


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB