views:

68

answers:

2

Hello guys,

i really hope that someone can help me with my problem. I would like to realize a match against query with multiple searchstrings.

In the moment it looks like this:

SELECT result.* FROM 
        (
        SELECT A.TITLE AS title  
        MATCH(A.TITLE) AGAINST('$searchstring1' IN BOOLEAN MODE) AS REL, MATCH(A.TITLE) AGAINST('$searchstring2' IN BOOLEAN MODE) AS REL2, 
        FROM Data AS A) AS result
        WHERE result.REL >=
            (
            (SELECT Max(rel_max.RELA) FROM  
                (SELECT A.TITLE AS title  
                    MATCH(A.TITLE) AGAINST('$searchstring1' IN BOOLEAN MODE) AS RELA
                FROM Data AS A) AS rel_max)-1) 
                     OR
                 result.REL2 >=
            (
            (SELECT Max(rel_max2.RELA2) FROM    
                (SELECT A.TITLE AS title  
                    MATCH(A.TITLE) AGAINST('$searchstring2' IN BOOLEAN MODE) AS RELA2
                FROM Data AS A) AS rel_max2)-1)

As response I get all results with the tow highest relevances (max - 1). It works, but maybe there is another, much shorter and better way to realize the same, because in the example i only have two searchstrings but i search a solution with multiple n - searchstrings and i think that several OR combinations in the query for each searchstring are maybe not a good way to handle this.

So please help me, because in the moment i have no idea how i can solve this.

Thank you

A: 

Searching is hard.

I will advise you to use something like Lucene for this purpose.

NullUserException
No searching is not the problem, neither the used tecnology. So lucene is fine but not what i am looking for. So i hope to get some inspiration or tricks of somone who is better in mysql than me.
Ruven
@Ruven What I meant is that it's hard to implement a searching algorithm that will yield relevant results.
NullUserException
yeah i know, but i did not find another solution to the one above till now. I mean it works but i think with more than e.g. five strings it will be horrible slow. That´s why i am here to find with other programmers a better solution.
Ruven
@Ruven, it may come as a surprise to you, but we are other programmers with a better solution. Lucene and products that use it like [Solr](http://lucene.apache.org/solr/) and [ElasticSearch](http://www.elasticsearch.com/) are going to make your job easier. You should evaluate them seriously.
Charles
A: 

No it is not a surprise, i only thought that i can handle it with mysql queries as above. This means standard mysql is not "good" enough for this? I will try it out.

Ruven