Search

We are currently updating the website of a film festival that will feature a login area for participating teams. Each team should be able to login with their team name and I'd like to display a list of similar team names when the login failed due to a misspelled team name.

Is there a way to return similar items using core Data Source filtering?
So if someone entered Tst, I'd like to display something like "Did you mean Test?".

There is not. This requires an element of fuzzy logic which Symphony doesn't include. Your best bet will be to use a custom data source for this task.

SELECT `value` FROM `sym_entries_data_123` WHERE levenshtein('$word', `value`) BETWEEN 0 AND 3

(Swap 123 for the field ID of your "team name" field.)

This uses the Levenshtein algorithm which returns the difference between two strings, i.e. the number of changes required to go from one string to another. Increase 3 to make the match more "fuzzy". You'll need to add this function to MySQL directly (here) as it's not included as standard.

You might not be able to do this if on a shared host. If so, you can do it in PHP instead. Select all team names from Symphony (as above, without the levenshtein method), loop over them and use PHP's levenshtein to the same effect.

I do something similar on the Symphony Extensions site by comparing the extension handle publish_tabs with its full name Publish Tabs. If they are significantly different then I flag this to the user and suggest that they rename for consistency.

You might find you need to lowercase and remove punctuation too, for more accuracy.

Thanks for your explanations, Nick!
Never heard of Levenshtein before – will check that out.

@Nils did you venture to Castle Levenshtein? Or have you found another solution?

I think we just used a select box with autocomplete (Select2?).

Ok, thanks!

@nickdunn this is cool.

I'm looking at trying to make a 'recommended posts' type thing. I considered using my tags and a random display of related posts... With something like that levenshtein method can I use titles instead? Could I combine both methods together?

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