INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Boolean Full Text Match searches - how to give preference to exact phrases without requiring them?

Boolean Full Text Match searches - how to give preference to exact phrases without requiring them?

Boolean Full Text Match searches - how to give preference to exact phrases without requiring them?

(OP)
Hi,
So, I've got a table with a fulltext index, and my client wants search terms to be exclusive (that is, all search terms MUST be included in the record, or the record should not appear in the search results). So I've got the query set up as a boolean-type query (because, AFAIK, that's the only way to have all search terms be required), where a search for, say, calcium oxide translates as a search for +calcium* +oxide* (they want to allow partial word matches).

So far, so good.

Now, in addition to that, my client would like sort preference given to exact phrase matches, without requiring exact phrase matches. So, for example, a search for:
acetate solution
should, again, only return search results with both "acetate" and "solution" somewhere in the results. Partial words are ok. It can also return LEAD ACETATE AQUEOUS SOLUTION... but that result should appear below all of the results that have the exact phrase, acetate solution. So it might return:
AMMONIUM ACETATE SOLUTION
CALCIUM ACETATE SOLUTION
MAGNESIUM ACETATE SOLUTION
SODIUM ACETATE SOLUTION
COPPER II ACETATE 3% AQUEOUS SOLUTION CUPRIC ACETATE
LEAD ACETATE AQUEOUS SOLUTION
SODIUM ACETATE BUFFER SOLUTION PH 5.2 +/- 0.05 AT 25 C MOLECULAR BIOLOGY REAGENT S7899
SODIUM ACETATE BUFFER SOLUTION PH 7.0 +/- 0.05 AT 250C MOLECULAR BIOLOGY REAGENT S2404


...in that order (that is, in order of whether there's an exact phrase match, and then in alphabetical order).

According to https://dev.mysql.com/doc/refman/5.5/en/fulltext-b..., enclosing a search term in double-quotes makes an exact phrase required, not optional. So is this even possible, to require all search terms be present in the results, and allow partial word matches, and make exact phrases optional, and sort exact phrases first?

Thanks! smile

Katie

RE: Boolean Full Text Match searches - how to give preference to exact phrases without requiring them?

Quote:

...(that is, all search terms MUST be included in the record,

Surely that would be inclusive rather than exclusive, unless your usage of 'exclusive' is different to the normal usage, and if it is we need a definition of your usage.

Quote:

Now, in addition to that, my client would like sort preference given to exact phrase matches, without requiring exact phrase matches.

That would be a contradiction in terms.

What it sounds like what you are really asking for is a Google type search, where results are weighted by relevance to the user search term.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.

RE: Boolean Full Text Match searches - how to give preference to exact phrases without requiring them?

(OP)
Unfortunately, no. That would be simpler.

Using the above "acetate solution" example:

A search for acetate solution can only return records where both "acetate" and "solution" appear in the name. If only one of those words appears in the name, then it should not return the record at all. They're very insistent on this point. They want the number of records returned to be strictly limited as much as humanly possible.

At the same time, they want records with the exact phrase, acetate solution to be given preference over records that have both words, but not in that exact order (or those words but with words in between).

Is there a way to do this?

Thanks. smile

Katie

RE: Boolean Full Text Match searches - how to give preference to exact phrases without requiring them?

Quote:

A search for acetate solution can only return records where both "acetate" and "solution" appear in the name. If only one of those words appears in the name, then it should not return the record at all.

Use a wildcard search

CODE --> MySQL

SELECT 'fields' FROM 'table' WHERE 'field' LIKE '%word1%' AND field LIKE '%word2%'; 

https://dev.mysql.com/doc/refman/5.7/en/string-com...

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.

RE: Boolean Full Text Match searches - how to give preference to exact phrases without requiring them?

(OP)
Thanks. That part's already done, though. The question is whether it's possible to rank exact phrase matches as more relevant (while at the same time requiring all words be present in the returned records, and without limiting to exact phrase matches only).

Katie

RE: Boolean Full Text Match searches - how to give preference to exact phrases without requiring them?

Quote:

The question is whether it's possible to rank exact phrase matches as more relevant

Yes, but that is much easier with an inverted index (how Google works) as I suggested in my first post. you have to 'score' the words in a document and calculate a 'relevance weighting'

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.

RE: Boolean Full Text Match searches - how to give preference to exact phrases without requiring them?

You could UNION your data

SELECT 1 as rank , 'fields' FROM 'table' WHERE 'field' = '%word1%'
union all
SELECT 2 as rank , 'fields' FROM 'table' WHERE 'field' LIKE '%word1%' AND field LIKE '%word2%';

Ian

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close