/usr/lib/perl5/KinoSearch1/Search/Query.pm is in libkinosearch1-perl 1.00-1build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | package KinoSearch1::Search::Query;
use strict;
use warnings;
use KinoSearch1::Util::ToolSet;
use base qw( KinoSearch1::Util::Class );
BEGIN {
__PACKAGE__->init_instance_vars(
# constructor params / members
boost => 1,
);
__PACKAGE__->ready_get_set(qw( boost ));
}
=begin comment
my $string = $query->to_string( $field_name );
Return a string representation of the query. $field_name is a default field,
and affects how the string is generated -- for instance, if a TermQuery's
field matches $field_name, the field will be omitted, while if it doesn't
match, the field will be included in the string.
=end comment
=cut
sub to_string { shift->abstract_death }
=begin comment
my $weight = $query->create_weight($searcher);
Only low-level Queries which rewrite themselves implement this method.
=end comment
=cut
sub create_weight { shift->abstract_death }
# Derive a weight for a high-level query.
sub to_weight { # in Lucene, this method is simply "weight"
my ( $self, $searcher ) = @_;
my $rewritten_self = $searcher->rewrite($self);
my $weight = $rewritten_self->create_weight($searcher);
my $sum = $weight->sum_of_squared_weights;
my $sim = $self->get_similarity($searcher);
my $norm = $sim->query_norm($sum);
$weight->normalize($norm);
return $weight;
}
=begin comment
my $rewritten_query = $query->rewrite( $index_reader );
Called by high-level Queries that wish to reformulate themselves as
agglomerations of low-level queries.
=end comment
=cut
sub rewrite { return shift }
=begin comment
my @terms = $query->extract_terms;
Return all the Terms within this query.
=end comment
=cut
sub extract_terms { shift->abstract_death }
# These will be needed by MultiSearcher if we add queries which rewrite
# themselves.
sub combine { shift->todo_death }
sub merge_boolean_queries { shift->todo_death }
# return the Similarity implementation used by the Query.
sub get_similarity {
my ( $self, $searcher, $field_name ) = @_;
# This can be overriden in subclasses, allowing alternative Sims.
return defined $field_name
? $searcher->get_similarity($field_name)
: $searcher->get_similarity;
}
sub clone { shift->todo_death }
1;
__END__
=head1 NAME
KinoSearch1::Search::Query - base class for search queries
=head1 SYNOPSIS
# abstract base class
=head1 DESCRIPTION
Base class for queries to be performed against an invindex.
L<TermQuery|KinoSearch1::Search::TermQuery> is one example.
=head1 METHODS
=head2 set_boost get_boost
$term_query_a->set_boost(2);
$boolean_query->add_clause( query => $term_query_a, occur => 'SHOULD' );
$boolean_query->add_clause( query => $term_query_b, occur => 'SHOULD' );
The boost of any Query is 1.0 by default. Setting boost to a number greater
than one increases a Query's relative contribution to a score, and setting
boost to a lower number decreases the contribution.
=begin devdocs
A Query in KinoSearch1 is a highly abstracted representation. It must be
transformed in several ways before the index is actually consulted to see how
documents score against it.
First, a Query must be "rewritten", a task that falls to the searcher.
Rewriting something as simple as a TermQuery just means returning the original
object; other more complex Queries, e.g. the as-yet-unimplemented SpanQueries,
may get transformed into collections of simpler queries -- such as
TermQueries.
Next, a Weight must be derived from a Query. The role of a Weight is to hold
all data which changes as the search gets processed -- allowing still-pristine
Query objects to be reused later.
The Weight object is used to derive a Scorer. The scorer iterates over the
documents which match the query, producing doc_num => score pairs. These
pairs are are processed by a HitCollector.
Different types of HitCollectors yield different results.
Here's another way of looking at the divided responsibilities:
# 1. Searcher-dependent info belongs in the Weight.
# 2. IndexReader-dependent info belongs in the Scorer.
=end devdocs
=head1 COPYRIGHT
Copyright 2005-2010 Marvin Humphrey
=head1 LICENSE, DISCLAIMER, BUGS, etc.
See L<KinoSearch1> version 1.00.
=cut
|