IF you just want to rank documents in terms of how many query terms (
@term = qw{hairline receding} in your example) each document contains, you don't need to do any permuting.
Note that there are various trade-offs of memory, disk space, and search time that you can make. You'll need to analyze carefully what a "typical" query is like, and what a "bad" query is like, and take appropriate measures.
Here's A Way To Do It. I assume you have (or will manufacture) a list of all search terms.
- Create for each search term a list of the document IDs in which it appears.
- (Untested, of course...)
my %hit;
foreach my $t (@term) {
my @doc = $documents_mentioning{$t};
$hit{$_}++ for (@doc);
}
# Filter (keys %hits) by # of hits (at least 2), then sort.
my @res = sort { $hit{$b} <=> $hit{$a} }
(grep {$hit{$_} >= 2} keys %hit);
"Interesting" parts include dealing with very large indexes (if your collection of documents is large), stemming words, and selecting the relevant words.
A good alternative might be to get a 3rd-party search engine instead of writing your own.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.