• Resolved blogdropper

    (@blogdropper)


    Hi,
    I’m creating a medicinal plants database and website and need to give the option to search for medicinal complaints treated, for example if the user searches for stomach pain I would also like to automatically search for abdominal pain and intestinal pain so what I need to do is create groups of related terms eg. stomach, abdominal, intestinal, if one of the words in the group appears, then all the words in the group will be searched for. Is this possible? If so how?
    Thanks

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Couple of approaches really:

    – You can do this in indexing, so that all posts that have the word “stomach” also get the word “abdominal” and “intestinal”.
    – You can do this in searching, so that all searches for “stomach” become searches for “stomach abdominal intestinal”.

    But the easiest way to deal with this is using synonyms. You can add this to your synonym settings:

    abdominal=intestinal stomach
    intestinal=abdominal stomach
    stomach=abdominal intestinal

    Then just make sure you’re using OR as the default operator and it should work fine.

    Thread Starter blogdropper

    (@blogdropper)

    Hi Mikko, thanks very much for this, would this also apply to phrases, so that if the search was “stomach pain” would this also return results for “abdominal pain” and “intestinal pain” – I don’t want to apply the fallback for individual words – so would the synonym be “stomach pain” rather than just “stomach”?
    Thanks

    Plugin Author Mikko Saari

    (@msaari)

    No, this does not work with phrases. Now what happens is that if you search for "stomach pain" with these synonyms, you get a search for "stomach pain" abdominal intestinal, which is not how this should work… Looks like something I need to fix.

    I’m not actually sure what the behaviour should be, should the search be for "stomach pain" "abdominal pain" "intestinal pain", or should the search be only for "stomach pain". I guess that’s something people will have different opinions about. In your case, the first case would probably be the desired outcome; in some other case the latter would be preferable. In any case the current result is not good.

    Anyway, this should work with synonyms, even with phrases, I just need to fix this. In the next version this will work well.

    Thread Starter blogdropper

    (@blogdropper)

    Thanks Mikko,
    Yes in my case I’d like to use phrases as synonyms – are you saying that at the moment synonyms can only be single words, but this will be fixed to include phrases in the next version?
    You also mention indexing and searching can either be used with phrases?
    Thanks

    Plugin Author Mikko Saari

    (@msaari)

    Synonyms can use phrases, but only on one end. This does not work:

    "stomach pain"="abdominal pain"

    This would work as expected:

    stomach="abdominal pain"

    What I’m changing in the next version is – probably – so that if you have a synonym

    stomach=abdominal

    and then search for "stomach pain", that would become a search for "stomach pain" "abdominal pain". But it’s a bit uncertain still, in case it gets too complicated.

    At the moment, if you want this to work with phrases, you need to do this in the searching manually, ie. look at the search phrase and fix it to match your synonyms. So, you’d have a function that looks at the search query and if it seems "stomach pain" in there, it’d replace it with "stomach pain" "abdominal pain" "intestinal pain" – but if you have lots of replacements like this, this gets complicated quick.

    Thread Starter blogdropper

    (@blogdropper)

    ok thanks Mikko,
    I could create a csv file with all related phrases/synonyms, would there be a way to upload to Relevanssi?

    Thanks for all your help, much appreciated

    Plugin Author Mikko Saari

    (@msaari)

    If you’re looking for the manual searching fix, that requires PHP code and having a CSV list is a good start for that.

    If you’re using just synonyms, you need the list in the specific format for Relevanssi.

    Thread Starter blogdropper

    (@blogdropper)

    I have around 2000 medical complaints (or at least the database does).
    So using a CSV file would simplify things for me, can you give me some pointers about the format and headings I need for a csv file if I want to use it for manual searching (for phrases).
    Are there any examples of PHP code that would give me an idea of what I need to do?

    Thanks

    Plugin Author Mikko Saari

    (@msaari)

    Ok, I changed my mind: with 2000 entries, you do need to do this in the indexing. It’s just too much for synonyms or search term modifications.

    How have you planned to implement these in the first place? Taxonomy terms, custom field, or just in the post content?

    One good way to do this would be to add a filter function on the post save that would pick up the medical complaints (that’s easier if the terms are listed in a custom field or in taxonomy terms) and write the alternate complaints to a custom field. That way the phrase matching would work fine.

    Thread Starter blogdropper

    (@blogdropper)

    OK Mikko, you’ve given me alot to digest, this is all still a work in progress, I’ll set things up as you suggest – taxonomy terms and custom fields. When that’s done I’ll get back to you for advice on uploading a CSV file.
    One question – you say

    write the alternate complaints to a custom field

    , is that 1 custom field per alternate complaint phrase or 1 custom field with all the alternate phrases comma separated?
    Thanks for all your help

    Plugin Author Mikko Saari

    (@msaari)

    For Relevanssi it does not matter, Relevanssi indexing and phrase matching will work just as well either way. Do whatever works best for you.

    Thread Starter blogdropper

    (@blogdropper)

    Hi Mikko,
    Is there any examples or documentation for using indexing and phrase matching?
    Can I use the free Relevanssi, or do I need the Premium version for this?

    Thanks

    Plugin Author Mikko Saari

    (@msaari)

    Free version is fine.

    This is something anyone hasn’t come up with before, so there are no examples ready.

    Phrase matching is fairly straightforward. Either wrap the phrase in quotes, or set the query variable sentence to a non-false value to make the whole search query a single phrase. If you have multiple phrases in a search query, they use AND or OR logic depending on your searching settings. Phrases are looked for inside post title, post content, post excerpt, taxonomy terms and custom fields, and require the exact literal match to be found.

    Relevanssi indexing process is too complicated to explain here. Either ask more specific questions or dive into the source code, it’s all here.

    Thread Starter blogdropper

    (@blogdropper)

    Hi Mikko,
    Finally arrived at a simple solution. Each medical complaint has a symptom and this is what I need to group the complaints by so “stomach pain”, “abdominal pain” and “intestinal pain” all have the common symptom “stomach pain” so I’ve added a symptom term to all medical complaints. Now search results contain all complaints with the same symptom.
    Thanks for helping me to think this through and arriving at a solution.

    Plugin Author Mikko Saari

    (@msaari)

    Yes, normalizing the content is a very good solution here. Glad to hear you have this figured out now.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘look for related terms’ is closed to new replies.