D
D
doublench212014-11-11 20:53:14
PHP
doublench21, 2014-11-11 20:53:14

Is it possible to complete the SQL query?

$words = explode(" ", $search);
for ($i = 0; $i < count($words); $i++) {
    $if_clause .= "indexing_word.word='" . $words[$i] . "'";
    if ($i != count($words) - 1) {
        $if_clause .= " or ";
    }
}

$sql = "SELECT indexing_link.id, indexing_link.url, indexing_link.title, indexing_link.short
        FROM indexing_link, indexing_link_word, indexing_word
        WHERE (" . $if_clause . ")
        AND indexing_link_word.word_id=indexing_word.id
        AND indexing_link.id=indexing_link_word.link_id";

I read a line from input and write to an array separating each word. Further I execute request.
But another table indexing_stop_word (id word) appeared. Is it possible to somehow supplement the query so that it ignores the words that are in this table. (Table of stop words. That is, I simply did not search for these words.)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Shahelm, 2014-11-11
@doublench21

Something like this:

SELECT 
    indexing_link.id, 
    indexing_link.url, 
    indexing_link.title, 
    indexing_link.short
FROM indexing_link, indexing_link_word, indexing_word
WHERE 
    (:searchWords)
    AND indexing_word.word  not in (:stopWords)
    AND indexing_link_word.word_id=indexing_word.id
    AND indexing_link.id=indexing_link_word.link_id

M
Melkij, 2014-11-11
@melkij

and not exists (select 1 from indexing_stop_word where indexing_stop_word.word=indexing_word.word)

?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question