I have 6 values 1 - The cat and the hat 2 - We the people of the united states 3 - The cat ate the hat 4 - Where are the starts 5 - the cat wen to the hat 6- the books are not good What is the most efficient way in perl and/or mysql to group them search for cat and the and return The cat and the hat The cat ate the hat the cat wen to the hat
I'm not sure if I understand your question right, but you can easily sort arrays alphabetically using the sort function. @values = sort { $a cmp $b } @values; Maybe you can clarify your question.
Imagine a scoring / search algorithm. Let's say for example, we are searching for "cat food selections" and the data sets are - johns cat food - html web design - mikes cat food - dog food is bad - cat food is great - web designers I only want - johns cat food - mikes cat food - cat food is great to come back. I hope that clears it up a bit. Thanks for the help.
@dataset = ('johns cat food', 'html web design', 'mikes cat food', 'dog food is bad', 'cat food is great', 'web designers'); $query = 'cat food selection'; @qwords = split(/ /, $query); foreach $_ (@dataset) { foreach $qword (@qwords) { if(/$qword/) { $matches[$i]++; } } $i++; } for($i=0;$i<($#dataset+1);$i++) { print $dataset[$i].':'.int($matches[$i])."\n"; } Code (markup): Now you only have to determine the highest score and then list all data that have that score. This is what it returns: johns cat food:2 html web design:0 mikes cat food:2 dog food is bad:1 cat food is great:2 web designers:0 Code (markup):