But I have never needed to use this reverse syntax. To be perfectly honest with you this looks less like a perl question and more like an advanced database design question.SELECT * FROM Grade_Theory WHERE 'The funcdamental particle is called +a quark, Bob!' LIKE '%'||Answer||'%'
Ideally you need to understand the importance of the key words in the answers.
So let us try and build up a dynamic query that tries to find important words. Your initial SQL starts off :-
Although this sounds ok it can create massive performace issues in the future when some adds many large columns to the table. Always specify exactly what you are after.SELECT * FROM Grade_Theory
Now comes the tricky part finding the matching answer. Now we do not know exactly how many words are relivent so we need to try and find a best match. Perl can help by generating the where clause.SELECT RowID, Question,Answer FROM Grade_Theory
This will result in the following type of query.my @words = split /\W+/, 'The funcdamental particle is called a quark, + Bob!'; my @parts = (); for (@words) { push @parts, "Answer like '%$_%'"; } my $where_clause = join (" or\n",@parts); my $sql = "SELECT RowID, Question,Answer FROM Grade_Theory WHERE $where_clause"; print "$sql\n";
You can improved this by removing short/irrelvent words from the word list.SELECT RowID, Question,Answer FROM Grade_Theory WHERE Answer like '%The%' or Answer like '%funcdamental%' or Answer like '%particle%' or Answer like '%is%' or Answer like '%called%' or Answer like '%quark%' or Answer like '%Bob%'
This will result in the following resulting query.my @words = split /\W+/, 'The funcdamental particle is called a quark, + Bob!'; my @long_words=(); for (@words) { push @long_words, $1 if (/^(\w{3,})$/); } my @parts = (); for (@long_words) { push @parts, "Answer like '%$_%'"; } my $where_clause = join (" or\n",@parts); my $sql = "SELECT RowID, Question,Answer FROM Grade_Theory WHERE $where_clause"; print "$sql\n";
If you want to go any further you really need a completely different design of database. If you have a table that contains words and a many to many relationship between that and your question table you could then do a far more interesting query. But this is PERL monks so I will lay of the database theory.SELECT RowID, Question,Answer FROM Grade_Theory WHERE Answer like '%The%' or Answer like '%funcdamental%' or Answer like '%particle%' or Answer like '%called%' or Answer like '%quark%' or Answer like '%Bob%'
Hope it helps
UnderMine
In reply to Re: Wildcards, SQL and Perl
by UnderMine
in thread Wildcards, SQL and Perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |