Mysql multiple queries to solve anagram

I have a simple but huge table called a dictionary that has 2 columns. ID and word. I have an anagram php algorithm that creates all possible combinations of a given word. I want to tag if this word exists in my dictionary, and if so, display it. But I have to use too many queries. For example, a 9-letter word - 362880 combinations. Any idea how to make fewer db calls?

+3
source share
4 answers

Try something similar for just one request, although I don’t know how effective such a request will be:

$possibilities = array( "at", "ta");
$sql = 'SELECT * FROM dictionary_table 
            WHERE word IN ("' . implode( '", "', $possibilities) . '")';

This will generate an SQL query:

SELECT * FROM dictionary_table 
            WHERE word IN ("at", "ta")

, , , $possibilities , . word.

+1

- :

SELECT word
FROM dictionary
WHERE word LIKE '%a%a%a%'
AND word LIKE '%n%'
AND word LIKE '%g%'
AND word LIKE '%r%'
AND word LIKE '%m%'
AND CHAR_LENGTH(word) = 7

.

SELECT word
FROM dictionary
WHERE sorted_word = 'aaagmnr'

sorted_word.

+4

, php. -,

SELECT myWord FROM myTable
WHERE myWord in (LIST OF PERMUTATION FROM PHP)

LIST OF PERMUTATION "' . implode( '", "', $permutations) . '"

+1

, , , - php php , , .

EDIT: : , 100 .

0

All Articles