1 package Search
::Xapian
::Enquire
;
10 our @ISA = qw(DynaLoader);
12 # Preloaded methods go here.
14 # In a new thread, copy objects of this class to unblessed, undef values.
20 if( ref( $query ) ne 'Search::Xapian::Query' ) {
21 $query = Search
::Xapian
::Query
->new( $query, @_ );
22 $self->set_query1( $query );
25 my $nargs = scalar(@_);
27 Carp
::carp
( "USAGE: \$enquire->set_query(\$query) or \$enquire->set_query(\$query, \$length)" );
31 $self->set_query1( $query );
33 $self->set_query2( $query, shift );
39 my $nargs = scalar(@_);
41 my $type = ref( $_[2] );
42 if ( $type eq 'CODE' ) {
43 # get_mset(first, max, matchdecider) [perl extra]
44 return $self->get_mset2(@_);
46 if ( $type eq 'Search::Xapian::RSet' ) {
47 # get_mset(first, max, rset)
48 splice @_, 2, 0, (0); # insert checkatleast
50 } elsif( $nargs == 4 && ref( $_[3] ) eq 'CODE' ) {
51 # get_mset(first, max, rset, matchdecider)
52 splice @_, 2, 0, (0); # insert checkatleast
54 return $self->get_mset1( @_ );
59 return $self->get_mset(@_)->items();
62 sub get_matching_terms_begin
{
64 if( scalar(@_) == 1 ) {
66 my $arg_class = ref( $arg );
67 if( $arg_class eq 'Search::Xapian::MSetIterator' ) {
68 return $self->get_matching_terms_begin2($arg);
70 return $self->get_matching_terms_begin1($arg);
73 Carp
::carp
( "USAGE: \$enquire->get_matching_terms_begin(\$docid) or \$enquire->get_matching_terms_begin(\$msetiterator)" );
77 sub get_matching_terms_end
{
79 if( scalar(@_) == 1 ) {
81 my $arg_class = ref( $arg );
82 if( $arg_class eq 'Search::Xapian::MSetIterator' ) {
83 return $self->get_matching_terms_end2($arg);
85 return $self->get_matching_terms_end1($arg);
88 Carp
::carp
( "USAGE: \$enquire->get_matching_terms_end(\$docid) or \$enquire->get_matching_terms_end(\$msetiterator)" );
98 Search::Xapian::Enquire - Make queries against a database
102 This class provides an interface to the information retrieval system for the
103 purpose of searching.
113 takes either a ready made L<Search::Xapian::Query> or a scalar containing
114 a query, which in that case will be passed to L<Search::Xapian::Query>'s
115 constructor, together with any other passed arguments.
117 =item set_query_object <query>
121 =item matches <start> <size> [<check_at_least>]
123 Takes the start element, and maximum number of elements (and optionally
124 the minimum number of matches to check), and returns an array tied to
125 L<Search::Xapian::MSet::Tied>.
127 =item get_matching_terms_begin
129 Returns a L<Search::Xapian::TermIterator>, pointing to the start
132 =item get_matching_terms_end
134 Returns a L<Search::Xapian::TermIterator>, pointing to the end
137 =item set_collapse_key <collapse_key>
139 =item set_docid_order <order>
141 Set the direction in which documents are ordered by document id
142 in the returned MSet.
144 This order only has an effect on documents which would otherwise
145 have equal rank. For a weighted probabilistic match with no sort
146 value, this means documents with equal weight. For a boolean match,
147 with no sort value, this means all documents. And if a sort value
148 is used, this means documents with equal sort value (and also equal
149 weight if ordering on relevance after the sort).
151 order can be ENQ_ASCENDING (the default, docids sort in ascending order),
152 ENQ_DESCENDING (docds sort in descending order), or ENQ_DONT_CARE (docids sort
153 in whatever order is most efficient for the backend.)
155 Note: If you add documents in strict date order, then a boolean
156 search - i.e. set_weighting_scheme(Search::Xapian::BoolWeight->new())
157 - with set_docid_order(ENQ_DESCENDING) is a very efficient
158 way to perform "sort by date, newest first".
160 =item set_cutoff <percent_cutoff> [<weight_cutoff>]
162 =item set_sort_by_relevance
164 Set the sorting to be by relevance only. This is the default.
166 =item set_sort_by_value <sort_key> [<ascending>]
168 Set the sorting to be by value only.
170 sort_key - value number to reorder on. Sorting is with a
171 string compare. If ascending is true (the default) higher
172 is better; if ascending is false, lower is better.
174 ascending - If true, document values which sort higher by
175 string compare are better. If false, the sort order
176 is reversed. (default true)
178 =item set_sort_by_value_then_relevance <sort_key> [<ascending>]
180 Set the sorting to be by value, then by relevance for documents
183 sort_key - value number to reorder on. Sorting is with a
184 string compare. If ascending is true (the default) higher
185 is better; if ascending is false, lower is better.
187 ascending - If true, document values which sort higher by
188 string compare are better. If false, the sort order
189 is reversed. (default true)
191 =item set_sort_by_relevance_then_value <sort_key> [<ascending>]
193 Set the sorting to be by relevance then value.
195 Note that with the default BM25 weighting scheme parameters,
196 non-identical documents will rarely have the same weight, so
197 this setting will give very similar results to
198 set_sort_by_relevance(). It becomes more useful with particular
199 BM25 parameter settings (e.g. BM25Weight(1,0,1,0,0)) or custom
202 sort_key - value number to reorder on. Sorting is with a
203 string compare. If ascending is true (the default) higher
204 is better; if ascending is false, lower is better.
206 ascending - If true, document values which sort higher by
207 string compare are better. If false, the sort order
208 is reversed. (default true)
210 =item set_sort_by_key <sorter> [<ascending>]
212 Set the sorting to be by key only.
214 sorter - the functor to use to build the key.
216 ascending - If true, keys which sort higher by
217 string compare are better. If false, the sort order
218 is reversed. (default true)
220 =item set_sort_by_key_then_relevance <sorter> [<ascending>]
222 Set the sorting to be by key, then by relevance for documents
225 sorter - the functor to use to build the key.
227 ascending - If true, keys which sort higher by
228 string compare are better. If false, the sort order
229 is reversed. (default true)
231 =item set_sort_by_relevance_then_key <sorter> [<ascending>]
233 Set the sorting to be by relevance then key.
235 sorter - the functor to use to build the key.
237 ascending - If true, keys which sort higher by
238 string compare are better. If false, the sort order
239 is reversed. (default true)
245 =item get_eset <maxitems> <rset> [<decider>]
247 Get set of query expansion terms.
249 =item get_description
251 Return a description of this object.
253 =item add_matchspy <spy>
257 This matchspy will be called with some of the documents which match the query, during the match process.
259 =item clear_matchspies
261 Remove all the matchspies.
267 L<Search::Xapian::Query>,
268 L<Search::Xapian::Database>,
269 L<Search::Xapian::MatchSpy>