Jump to content

Search with aliases


Robin S
 Share

Recommended Posts

I'm building a site where pages will include a field listing one or more plant species. The problem with plant species is that several different names can refer to the same plant. For example, all the following refer to one plant:

Spinifex sericieus, spinifex, kowhangatara, silvery sand grass

My client wants to avoid having to enter all the aliases for every species on every page and just use a single "master name", but wants a search for "kowhangatara" to return pages that include "Spinifex sericieus".

I'd be grateful for any suggestions on how I could achieve this kind of alias searching in ProcessWire.

Link to comment
Share on other sites

Don't know much about this but it seems there's one or two issues to consider here. First, the issue about making data entry as easy as possible for the client. They don't want to be 'typing' all those aliases with every page edit. Secondly, there's the main issue - how to create those aliases. In respect of the latter issue, the 'master name' will have to be related to its aliases in one way or another. A common way of relating things in ProcessWire (and you probably know this) is to use page fields. These are related to the first issue in that depending on the level of complexity, page field input such as auto-complete or asmSelect (plus the new tag select) can be quite handy. Is there a reason why you can't use such a system? Will the aliases be manually entered or imported into your (or maybe read from a custom) database?

For some really powerful searching, there is also the module Elastic Search. Maybe that could help? See this for instance. I haven't use the module (nor the tool it implements) so can't comment much further. Anyway, these are just initial thoughts...

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

Ok, I'm doing a little thinking on this and I have a couple ideas depending on how you would like to approach this. Searching for tags in processwire is actually quite simple. Tags, as Kongondo just said can be related using a page field on the tagged item. Currently the way that I manage tags is using the pageAutocomplete field. This module allows you to quickly add multiple page references based on a specific path. You tell the field the path of the pages that will be acting as tags. If the tag doesn't exist, I have the field set to automatically create a new one.

Ok. So that method will require that the user types in all of the tags individually, which would be pretty quick, but this is something that you would like to avoid. So what I am thinking is creating a little module that adds "subtags" based on a "master tag". So to do this you would most likely want to create 2 separate tag templates. One tag template will be a master, and the other will be a sub. So your master tag template will have a minimum of 2 fields. The first field will be a title and the second will be a page autocomplete field, this field will be pointed to your subtag path. So you will have your master plant and all of the other names that it would be related to. Then the subtag would just be a single title template that is also related to the page.

The module would just hook to page save, look to see if the page has a tag field, if the tag field contains master tag then add its subtags.

 If you want your search to turn up a search based on a tag you will need to run your search like this.

$matches = $pages->find("TagField.title|title|anotherFieldtoSearchBy*=$query");
Link to comment
Share on other sites

Thanks for the replies.

Maybe this is much easier than I thought it would be... not in a position to test right now but will check soon...

I create a "Page" type field (Multiple Page option) called "Species", and then pages for each species option, with fields "Master Name" (Title) and "Alias" (a text field that will contain aliases separated by commas). I then import all the species options with Master Name and Alias values separated. Now in the backend the client can select species using the Master Name only via asmSelect.

Then when it comes to searching (and this was the bit that I thought would be tricky) I can match pages by:

$pages->find("template=my_template, species.title|species.alias~=$q");

Is that right?

I'm still getting my head around the Page field type and how pages can be matched to it in a search. For some reason I thought I could only search a Page field by ID or Title but if I can match it like above then problem solved.

Link to comment
Share on other sites

Yeah man, I am not positive but that looks like it may do the trick. Just add an extra field to the "tag" field that holds aliases and then search for them. To be honest though I am no expert and I would recommend trying it out, you may have some issues locating items based on aliases. I am sure someone will chime in if I am pointing you down a dark path. :)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...