Gossamer Forum
Home : General : Databases and SQL :

SQL for search

Quote Reply
SQL for search
Just sit here and try to program the search for LSQL in php;
to find just one word i will do:

select word_id from word_list,
select item_id from score_list where word_id=word_id from word_list order by score DESC

(in one query :)

But i have no clue how to make sorting the query for two words

select where word_id = 1 or word_id = 2

The sort should be again score, but for every item_id with both words i should add the score.

Maybe query for:
1. where word 1 and word 2
2. where word1 or word 2


Then i limit everytime to 10, so i have maybe 20, put them in an array, make the sum of score, sort the array, spit out 10?
Quote Reply
Re: [Robert] SQL for search In reply to
Now i set "debugging enabled" and watch my error_log.
As it seems, the search in LSQL does the following (i dont think about cats)

Search in all fields with a value for search weight for my keyword.
Do this for every keyword.

Then look for the word_ids.

Then get the scores, make sums.

Then sort, then spite out.


But this means that with every search i have to select all links with my keywords, then i got the scores, then i go on.
So what will happen if i choose keywords like "the", "and" ... i will have thousands of links to select, calculate and work with.

I am shure Alex is a programer and i am not, so maybe i understand something wrong.
If not i should choose another way.

But the only thing i can image now, is to get some more values than needed from the score table, sum the scores and spite out.
On page one with ten (LIMIT 10 for every word or some more), on page two Limit 10,10 and so on.

I am not shure now if this will produce a correct search-result, but i am afraid of some tenthousand visitors every day making queries with thousands of rows.
Quote Reply
Re: [Robert] SQL for search In reply to
Now i have the following problem:

Peter > BMW
Peter > Audi
Andreas > BMW

Get all with BMW OR Audi
> Select from ... where car = BMW or car = Audi

But how to query:
1. Select all with BMW, but not Audi
2. Select all with BMW AND Audi

I can do this only with two queries?