I'm reviewing some search-engine-like code which scores documents according to two different criteria.
One is "number of times word appears", and the other is "contains n of the words searched for".
It's a crude but effective way of scoring documents.
If the search term is "apple banana cherry" a document may score 10 for its apple-content, 5 for its banana-content, 1 for its cherry-content, a score of 16, but then get a "bonus" of fifty points for containing all three words, putting it ahead of another document with 20 for cherry, 20 for banana but zero for apple.
When I wrote the code a year ago I never would have thought of using multidimensional structures, but having hung around the Monks for a year, it occurs to me that I can do it this way:
keeping two hashes, or I can do it this way:$total_word_score{$this_document} = 16; $number_of_matches{$this_document} = 3;
$various_scores{$this_document} = [16,3];
are there any arguments -- stylistic, maintenance, extendability -- about doing it one way rather than the other?
--
Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.
M-J D
In reply to Hash of Arrays versus Two Hashes by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |