Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-10-08 16:01:19

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

etc_search: when the default search is not enough

Description

This plugin is based on cbs_live_search, but adds enough new features to deserve a new name. It displays a search box similarly to <txp:search_input />. If Javascript is enabled, a results list will fade in and resize in real time below the search box with a nice animation effect as the user types his query. When the search box is empty, the results list shrinks and fades out. When the user hits the Enter key he gets redirected to a traditional search results page, so the plugin also degrades nicely in non-Javascript browsers.

The search is advanced, i.e. jaguar speed !car will display the results containing the strings “jaguar” and “speed”, but not “car”. The syntax is customizable by modifying etc_search_ops preference. Moreover, you can create advanced search forms, instruct the plugin to do faceted searches and query any fields in your txp database.

Requirements

Javascript

jQuery 1.2 or more recent is required.

You can use the jquery.js javascript file which is bundled with Textpattern and you need to upload the provided livesearch.jquery.js file to your web server (for example in a folder called “/js/”) and include both of these files in the header of the web pages where you want to use the plugin:

<script type="text/javascript" src="/textpattern/jquery.js"></script>
<script type="text/javascript" src="/js/livesearch.jquery.js"></script>
PHP

Version 5.3 or newer is required, see this post otherwise.

Syntax

Search form
<txp:etc_search />

or as container:

<txp:etc_search>
  <input name="q" />
  ...
</txp:etc_search>
Search results
<txp:etc_search_results />

or as container:

<txp:etc_search_results>
  output form
</txp:etc_search_results>

Examples

By default, etc_search acts like the built-in Textpattern search, querying articles Title and Body. The following query form will make searchable also Keywords and Excerpt:

{Title,Body,Keywords,Excerpt}

Suppose now that you wish to enhance the default search with faceted search for some text in images caption attribute, and display the titles of the articles which are associated (via Article image) with the matching images. To indicate that you are searching in captions, you decide to prefix terms by cap:. Then you can create a etc_search query like this:

SELECT txp.ID,txp.Title,img.caption FROM textpattern txp JOIN txp_image img ON FIND_IN_SET(img.id,txp.Image) WHERE {img.caption::/^cap:(.+)$/::{*} LIKE '%$1%'}

History

  • Version 0.8.1: beta release.
  • Version 0.8.3: small syntax modification to enable more general queries.
  • Version 0.8.9: new <txp:etc_search_results /> tag, to (partially) replace the default search. Forms enhanced with txp tags, some attributes depreciated.
  • Version 0.9: sensible attributes move to a dedicated tab and require admin privileges. Fully customizable input/output/animation. Can be used for internal queries too, i.e. without user interaction.

Download from the homepage.

Last edited by etc (2014-02-23 16:31:39)

Offline

#2 2012-10-08 19:44:21

zero
Member
From: Lancashire
Registered: 2004-04-19
Posts: 1,470
Website

Re: etc_search: when the default search is not enough

Very welcome plugin, Oleg! I seem to be having a problem. The search results are displaying article titles correctly but the link is going to a 404. It seems to be linking to site/section/page_title rather than the correct url. (both with basic etc_search and using your long query example above)


BB6 Band My band
Gud One My blog

Offline

#3 2012-10-08 19:51:48

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

Re: etc_search: when the default search is not enough

Thank you, Peter. That’s weird, it uses Textpattern permlinkurl() function to generate the links. What is your permlink mode, and what the correct urls should be?

Offline

#4 2012-10-08 20:15:45

zero
Member
From: Lancashire
Registered: 2004-04-19
Posts: 1,470
Website

Re: etc_search: when the default search is not enough

I am using section/title and I have changed the url-only titles of many articles when they were written. If I hadn’t changed them, the links would have been correct.


BB6 Band My band
Gud One My blog

Offline

#5 2012-10-08 21:21:03

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

Re: etc_search: when the default search is not enough

Uploaded a corrected version, thanks to Peter for testing and report.

Offline

#6 2012-10-11 08:58:49

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

Re: etc_search: when the default search is not enough

Version 0.8.3 is out: small syntax modifications to allow more general queries, and appending query string to url to enable logging.

Offline

#7 2012-11-09 20:51:13

photonomad
Member
Registered: 2005-09-10
Posts: 290
Website

Re: etc_search: when the default search is not enough

Hi Oleg,

I’ve been experimenting with using etc_search to include a custom field in searches. It is working great with live search enabled and results from the custom field show up in the list. However, when I hit return after typing a search term, results from the custom field do not show up on the dedicated search results page. Not sure if this is a bug, or maybe I’m using it wrong? Should I use tags that are etc_search specific in my search results page?

Thanks!
Stacey

Offline

#8 2012-11-09 21:55:18

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

Re: etc_search: when the default search is not enough

Hi Stacey,

hitting return simply sends you on the default search page, etc_search intervenes only in live mode. Textpattern search is so tightly integrated with <txp:article /> that I can not see a natural way to replace it with plugins output. This certainly can be done, but meanwhile, if you only need to search in custom fields, wet_haystack should do the job.

Offline

#9 2012-11-14 05:48:21

whaleen
Member
From: Portland
Registered: 2006-05-11
Posts: 373
Website

Re: etc_search: when the default search is not enough

I was using:

<txp:etc_search form="search_results" />

with search_results form containing regular txp:article tags:

<txp:title />, <txp:posted />, <txp:permlink />, etc...

and I discovered that tags within that form need to be wrapped in a txp:article container in order to work in the results. Like so:

<txp:article>
<txp:title />, <txp:posted />, <txp:permlink />, etc...
</txp:article>

Wanted to share this point in case any others make the same mistake I made in assuming that the results form would behave like an article form. Might be a good thing to add to the docs in the form of an example of a search results form.

Thanks a lot for releasing this one. It’s a beauty.


txtstrap (Textpattern + Twitter Bootstrap + etc…)

Offline

#10 2012-11-14 10:46:34

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

Re: etc_search: when the default search is not enough

whaleen wrote:

I discovered that tags within that form need to be wrapped in a txp:article container in order to work in the results.

You mean it works?! Wow, <txp:article /> is then really smart, this opens new possibilities, I must do some investigation. Many thanks for the report!

Wanted to share this point in case any others make the same mistake I made in assuming that the results form would behave like an article form. Might be a good thing to add to the docs in the form of an example of a search results form.

Since etc_search can search in any table(s), article context is not always relevant. But we could probably assert it for the default search, that’s a good point.

Thanks a lot for releasing this one. It’s a beauty.

The beauty comes from cbs_live_search, the bloat is mine. :) Thank you for the very inspiring feedback!

Offline

#11 2012-11-14 16:02:21

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

Re: etc_search: when the default search is not enough

Version 0.8.4 enables <txp:title />, <txp:posted />, etc in default search form. No wrapping in <txp:article /> is needed anymore. Quickly tested, seems to work, but more testers the merrier.

Offline

#12 2012-11-14 16:10:04

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 329
Website

Re: etc_search: when the default search is not enough

Very nice work – I’m a fan of cbs_live_search – it is great to know the plugin has new life going forward.

I’ll be testing this in coming weeks.

Offline

Board footer

Powered by FluxBB