Search

Just wondering - if I was going to try to implement a search feature, I'd be best off trying to develop that as an extension, correct? Or would it be just as easy to use a Data Source? At this point, I'd only want it to search title and tags for entries in one section.

Looking for the optimal approach. If someone feels like giving me a point to start at, I'm more than happy to try my hand at getting it going and sharing my result.

Cheers. -Ryan

I think you would be better off using an extension, rather than pulling every entry from a section and using xslt to find matches. In 1.7, you would use the Section Search CS by Alistair, but as far as I know it hasn't been updated for 2.0 yet. I'm sure it will be updated sometime in the future though. :)

Native to Symphony 2 is the ability to use MySQL's regexp on text input and textarea fields. If you are familiar with regexp, then good news!

A friendlier search extension will be a hot request, so I'm sure if we don't get to it, someone will :)

Native to Symphony 2 is the ability to use MySQL's regexp on text input and textarea fields. If you are familiar with regexp, then good news!

Now that is cool! That definitely opens the door for loads of search and filtering possibilities. :D

anyone want to take a shot at explaining (briefly of course) how exactly this might work?

By default Symphony performs exact matches. E.G. title = 'blah'. This is good because the result set is always precise. However, there are instances, like searching, where you need more flexibility.

In Symphony 2, any filter can be prefixed with regexp: to signify you are dealing with a MySQL regular expression match, rather than an exact match. E.G. title REGEXP 'blah'. An example of a simple search might be:

regexp:[[:<:]]{$url-query}[[:>:]]

This will match the query param surrounded by word boundaries. So, if your query string was bananaman than it would match something like "I like bananaman, he's my hero!" and "Bananaman is awesome" but it won't match "Bananamans pants need to be dry-cleaned"

Anyway, have a look at the documentation for more details on the syntax.

Oh, I should mention, it is not supported on the Textarea field since it does boolean keyword searching anyway rather than exact matches. It's more efficient, since the table maintains a keyword index. The syntax is similar to something like Google. E.G. +bananaman "is great"

The syntax is similar to something like Google. E.G.

I'm exploring the search capabilities using REGEX and data sources. Are you implying that Google like search function is possible without an event?

Searching using a single word is easy enough, but how might one go about searching for two words where each word on its own will match; currently only the phrase is matched. And something like [word1 word2] matches the whitespace, rendering it useless.

Are you trying to match data in a textarea or something else?

Are you trying to match data in a textarea or something else?

Right now I'm just trying to match a text input. I would like:

adult sail

To match:

Adult Beginner Sailing

The REGEX solution would be adult|sail but there's no way to alter the search (without utilizing an event).

Ah, I see. What you want is something like this as your filter:

regexp:REPLACE('adult sail',  ' ',  '|' )

The only problem is that the REGEXP filter in Symphony is automatically surrounded with quotes (line 80 of /symphony/lib/toolkit/fields/field.input.php):

$where .= " AND (`t$field_id`.value REGEXP '$pattern' OR `t$field_id`.handle REGEXP '$pattern') ";

The option is to hack the field class, removing the quotes, but that isn't terribly future proof.

Not sure what other options there are. I'll need to ponder.

regexp:REPLACE('adult sail', ' ', '|' )

I don't think the above is possible.

It is not possible since the SQL ends up as

... REGEXP 'REPLACE('adult sail', ' ', '|' )' ...

Notice the extra quotes. If those quote's weren't there, it would work fine.

Yes, I should have been more descriptive in my last post. Removing the ' as suggested seems to invalidate the REGEXP syntax. So, there seems to be two ways to proceed:

  1. Create an event that modifies the search query to an appropriate REGEXP and redirect the URL.
  2. Modify appropriate field type classes and mimic the REPLACE() function from mySQL in PHP prior to the SQL statement.

1 seems more robust but if 2 was implemented in such a way that you could use nested REPLACE() it would make that approach more appealing. I think the big question that needs to be asked in evaluating 2 approach is, how else might the REPLACE() be utilized in field filters?

Just thinking out loud, as I think 1 is a better approach for what I need at this point.

any news on this from anyone?

Not quite a the same as a proper search extension, but there's potential for using Yahoo! Search BOSS (Build your Own Search Service) as a customisable search engine for Symphony. It spits back XML, so a combination of a dynamic DS and some tricky XSLT and you could have it doing a lot of what you want.

More info here: http://developer.yahoo.com/search/boss/.

Google's Enterprise Search is also an alternative.

both of those seem out of scope for what i'm working on. the only way you can search the site is if you're logged in.

Trust me, GES is well suited to anything, it's also a plus because you can use Google syntax to search your site.

Not sure if this is relevent/helpful, but RC1 will provide direct support for regex filters in the DS editor, so I thought I'd add this tip: Sometimes /a|b|c/ style regexes are inadequate because they match either "a", "b" or "c"; an alternative regex style /^(?=.*?a)(?=.*?b)(?=.*?c)/s can be used to match only when "a", "b" and "c" are all substrings. (You can additionally enhance it with (?=.*?\ba\b) to make sure there are word boundaries before and after the search term "a".)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details