Search

I'm going to be building a website soon that requires a rather advanced search system. I've seen the Google Custom Search Plugin but I'm very unfamiliar with it so I thought I would ask some questions before I dove in and got completely lost.

The site is for a real estate agent and I'll need to be able to search based on a text string, location, price, whether it's rent or buy... So this means at least one text thread, two check boxes and two lists. I also need it to be an integrated part of my site so I can style it just like everything else.

Can anyone make any recommendations?

I can not make recommendations but I am going to be in need of a similar system very soon. I need to be able to search on a text string in several attributes and for a price too.

I am going to try and create an extension myself but it is probably going to be customized for this project. Maybe we can try and adapt it to make it more general?

This might be a starting point: http://symphony21.com/forum/discussions/570/1/.

There are two interesting discussions on this topic in the forum:

If you read the mentioned discussions, you get the impression that a simple string-based search (plus any filtering that you mentioned) should be quite easy to achieve. The problem will be combining search strings using AND/OR logic. If your website waits for this Google-like stuff, you'd probably implement Google search.

I did some experiments with the Google Custom Search extension and found some minor bugs (which I will post there as soon as I find the time). The the biggest questions here will be: How good is the Google index of your site? And how often does Google re-visit your site?

Hmm... I'm taking a look at this and I'm afraid much of it is over my head. But after playing around with Symphony a bit I have some more questions, ones that might lead to a solution.

Before I start, let me just propose a hypothetical situation so we're all on the same page. Let's say we have a list of articles. Each article has been provided a title, a main category, some sub-groups based on selections from a multibox, and a few tags. OK bearing that in mind...

First, is it possible to filter a list of articles, likely from one single data source, by multiple parameters on the fly based on the formation of a URL? My logic would be I could create a form that in the end generates a URL based on the criteria entered. This might result in URLs that looked like the following:

http://www.mywebsite.com/articles/category01/group01/
http://www.mywebsite.com/articles/category01/group01/group02/
http://www.mywebsite.com/articles/category02/
http://www.mywebsite.com/articles/group01/

Would it be possible for Symphony to filter the results based on those URLs?

Second, would it be possible to filter results of an article based on parameters from a string? Let's say I had one of the following for URLs:

http://www.mywebsite.com/articles/?="1-1"
http://www.mywebsite.com/articles/?="1-1,2"
http://www.mywebsite.com/articles/?="2"
http://www.mywebsite.com/articles/?="0-1"

Where I would take some logic in the XSLT based on if statements that would say something along the lines of if the first character was a 0 then use all categories, if it's a one only Category-X... And so forth.

The first situation would be preferable to me as it could rely more on Symphony and bypass the need for a more complex and/or logic. I'm sure some of that will be required either way but if I only have to considered preset parameters things would be much simpler.

My thinking is that if I can get to this point I can then look into further filtering the results a second time based on a string from a text field.

Any tips on this would be extremely useful as there's yet another site I'm working on that needs this sort of functionality. If I can't provide it in some form I'll have to pass on the project.

Doug, I did receive your email about this off-forum, but have been pulling 12+hour days to meet deadlines so haven't had a chance to reply. I'll try and get some thoughts down in this thread shortly. I expect you'll need to use a little custom PHP, but what you require sounds doable.

I'll need to be able to search based on a text string, location, price, whether it's rent or buy

I'll use this example. You can get something basic together without any customisation.

Create a Section (Properties) with the fields:

  • Postcode (text)
  • Property Type (select box: House, Flat, Commercial)
  • Sale Type (select box: House, Flat)

Add filters:

  • Postcode {$url-postcode}
  • Property Type {$url-property-type}
  • Sale Type {$url-sale-type}

Include these fields in the Included Elements and attach to a page. By default this should pull out all properties. But you can begin to filter by appending URL parameters on the querystring. A querystring variable is appended with a url- prefix and becomes a parameter in the Params list when you debug. Working URLs to add filters would look like:

/properties/?postcode=wd3+1hh
/properties/?property-type=house
/properties/?sale-type=buy

Or multiple parameters:

/properties/?property-type=flat&sale-type=rent

Additional filters could be added to checkboxes (passing yes/no in the URL), and perhaps a regular expression match for keywords within a Description field.

You would build your HTML form like this. By specifying "get" as the method ype, the field names will be added with their values to the URL.

<form method="get" action="/properties/">
    <select name="property-type">
        <option value="house">House</option>
        <option value="flat">Flat</option>
    </select>
    <input type="submit" value="Search" />
</form>

When you've got unknown number or types of parameters, it's best to use querystring parameters instead of forward-slash-separated URL parameters.

Does that help?

In terms of multiple values, I think you can pass comma-separated values to filter by. Say you had a Select Box, you can add multiple values into your filter by clicking on them in the DS Editor. In the above example you could add this as a filter for Property Type:

House, Flat, Commercial

This would act as an OR. Therefore your querystring parameter might work as:

?property-type=house,flat,commercial

(I think this would work.)

In the same way, when you set an Output Parameter from a data source (e.g. System ID from a data source called Properties) it will create parameter named $ds-properties with a comma-delimeted array of System IDs. Therefore if you wanted to filter an Articles index by specific IDs you could set your Articles DS to filter System ID on a parameter named $url-id and pass a querystring as:

/articles/?id=1,2,3,4

This would return articles 1, 2 3 and 4.

OK, this has given me a lot to work with. I'm going to create a test site locally so I have something to test with. I'll let you know how it turns out.

Hmm... I don't think I'm doing this right. I only created the fields for the contract type and housing type ("contract" and "type") respectively. Now in my data source, which I've called the sections "Timeshares" because anything named "Properties" wasn't showing up, I've added a filter for the contract field called {$url-contract} and one for type as well, but this doesn't seem to work when I add "?type=condo" without the quotes to the end of the URL.

Am I doing this wrong?

What doesn't seem to work exactly? Is the DS just returning all entries, and not applying the filter?

  • double check you've attached your Timeshares DS to the page
  • do you see the <timeshares> node in your page XML when using ?debug, and does it return any entries?
  • when viewing the Params list (?type=condo&debug click on Params) is Symphony successfully creating a parameter named $url-type with a value of "condo" and do you definitely have entries with a value of "condo" or "Condo"?)

If you still can't figure it out, send me an email with your login details and I'll take a closer look on Monday/Tuesday,

No worries, I got it to work. I'm not sure this alone will be enough but it's definitely worth a look. Maybe with some clever use of XSLT and a spritz of PHP I can pass something off.

My last question is, when using multiple parameters, does the "&" mean it must have both options or any or either of them? If it means both is it possible to do an or statement? For instance "?category01=option01[or]option_02"?

Another thought I just had, with this method, is it possible to return partial matches? Or instance is a paragraph contained the word "trumpet" and I had a variable set up to search "?instrument=trumpet"?

Is there any documentation on this anywhere that I can look at? I've been doing some Googling as well as looking around here and can't seem to find anything.

This is probably because my skills aren't with back-end development.

Doug, not entirely sure what documentation you're after.

A filter on a DS for, say, a Select Box, can accept comma delimeted values. These are treated as OR. So if you had a select box named Category then filtering this field by "Category1, Category2" will return entries with the Category1 and Category2 values.

In the same way, this filter could instead be $url-category. When attached to a page you could then call the page as so:

 /page/?category=Category1,Category2

It will have the same effect.

Partial matches on text fields (and perhaps even Select Boxes) can be achieved using MySQL regular expression syntax. Here are a few threads:

What this means is that you can create a filter that contains a regular expression. Therefore you could alter the above category filter to be:

regexp:^{$url-category}

This will perform a partial match on the beginning of the category word. The ^ means "start at the beginning of the string". If you have three entries with different categories chosen ("cricket", "croquet", "squash") then this:

 /page/?category=cr

Should match the entries with Cricket and Croquet selected.

Does that help?

Yes, it definitely gives me more to look into. Thanks for the help! I'll let you know if I get stuck. If, however, I figure out a system that allows you to do advanced searches I'll also post it up in the forum for everyone else.

REGEXP is fantastic! I still have some details to work out but it seems like the best option for me is to create a data source that uses a series of URL parameters, the body text utilizing a regular expression to define it's param, and having the all searches run off that source.

It's not a perfect solution, at least not how I understand it, but as I get more comfortable with Symphony I'm sure I'll improve it somehow.

Now I just need to write a PHP form that pulls this all together.

REGEXP is fantastic!

That's a first ;)

Well, handy maybe is a better way to put it. Still, handy.

For anyone who's curious you can manipulate a URL with PHP like this:

<?php
   $name = $_GET['name'];
   $location = $_GET['location'];
   $location = str_replace(" ", ",", $location );
   header("Location: /phpsearch/?name={$name}&location={$location}");
?>

You send it from a form with a GET method.

Would it be possible to manipulate how a parameter is added to the url?

Now I am getting ?parameter1=somevalue&parameter1=othervalue (AND logic), but how to get ?parameter1=somevalue,othervalue (OR logic)?

I am filtering by {$url-parameter1}. Since the field is a select box link, values are sometimes changed and more are added occasionally, so I don't think it's appropriate to build the filter with these values, separated by commas... Or this is the only possible approach to get the values of the parameter separated by commas?

PS. In the front-end form, values for this parameter are passed through checkboxes.

@ellie

I am filtering by {$url-parameter1}. Since the field is a select box link ...

The filtering is related with this thread?

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