buildlib/Lucy/Build/Binding/Search.pm

filter: Statementstmt 100% 233 / 233 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 30 / 30 Podpod 0.0% 0 / 28 totaltotal 90.3% 263 / 291 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
bind_all
1.0
CRAP 1.0
« buildlib/LucyX/Build/Binding/Search.pm ↑ Summary buildlib/Lucy/Build/Binding/Plan.pm »
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 package Lucy::Build::Binding::Search;
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = '0.008000';
20 1 $VERSION = eval $VERSION;
21  
22 1 ▶sub bind_all {
Subroutine bind_all: called CC=1 SCAR=0.0
Pod undocumented
23 1 my $class = shift;
24 1 $class->bind_andquery;
25 1 $class->bind_collector;
26 1 $class->bind_bitcollector;
27 1 $class->bind_compiler;
28 1 $class->bind_hits;
29 1 $class->bind_indexsearcher;
30 1 $class->bind_leafquery;
31 1 $class->bind_matchallquery;
32 1 $class->bind_matcher;
33 1 $class->bind_notquery;
34 1 $class->bind_nomatchquery;
35 1 $class->bind_orquery;
36 1 $class->bind_parserelem;
37 1 $class->bind_phrasequery;
38 1 $class->bind_phrasecompiler;
39 1 $class->bind_polyquery;
40 1 $class->bind_polysearcher;
41 1 $class->bind_query;
42 1 $class->bind_queryparser;
43 1 $class->bind_rangequery;
44 1 $class->bind_requiredoptionalquery;
45 1 $class->bind_searcher;
46 1 $class->bind_sortrule;
47 1 $class->bind_sortspec;
48 1 $class->bind_span;
49 1 $class->bind_termquery;
50 1 $class->bind_termcompiler;
51 }
52  
53 1 ▶sub bind_andquery {
Subroutine bind_andquery: called CC=1 SCAR=0.0
Pod undocumented
54 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
55 1 my $synopsis = <<'END_SYNOPSIS';
56 my $foo_and_bar_query = Lucy::Search::ANDQuery->new(
57 children => [ $foo_query, $bar_query ],
58 );
59 my $hits = $searcher->hits( query => $foo_and_bar_query );
60 ...
61 END_SYNOPSIS
62 1 my $constructor = <<'END_CONSTRUCTOR';
63 my $foo_and_bar_query = Lucy::Search::ANDQuery->new(
64 children => [ $foo_query, $bar_query ],
65 );
66 END_CONSTRUCTOR
67 1 $pod_spec->set_synopsis($synopsis);
68 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
69  
70 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
71 parcel => "Lucy",
72 class_name => "Lucy::Search::ANDQuery",
73 );
74 1 $binding->set_pod_spec($pod_spec);
75  
76 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
77 }
78  
79 1 ▶sub bind_collector {
Subroutine bind_collector: called CC=1 SCAR=0.0
Pod undocumented
80 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
81 1 my $constructor = <<'END_CONSTRUCTOR';
82 =head2 new
83  
84 package MyCollector;
85 use base qw( Lucy::Search::Collector );
86 our %foo;
87 sub new {
88 my $self = shift->SUPER::new;
89 my %args = @_;
90 $foo{$$self} = $args{foo};
91 return $self;
92 }
93  
94 Abstract constructor. Takes no arguments.
95 END_CONSTRUCTOR
96 1 $pod_spec->set_synopsis(" # Abstract base class.\n");
97 1 $pod_spec->add_constructor( alias => 'new', pod => $constructor, );
98  
99 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
100 parcel => "Lucy",
101 class_name => "Lucy::Search::Collector",
102 );
103 1 $binding->set_pod_spec($pod_spec);
104  
105 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
106 }
107  
108 1 ▶sub bind_bitcollector {
Subroutine bind_bitcollector: called CC=1 SCAR=0.0
Pod undocumented
109 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
110 1 my $synopsis = <<'END_SYNOPSIS';
111 my $bit_vec = Lucy::Object::BitVector->new(
112 capacity => $searcher->doc_max + 1,
113 );
114 my $bit_collector = Lucy::Search::Collector::BitCollector->new(
115 bit_vector => $bit_vec,
116 );
117 $searcher->collect(
118 collector => $bit_collector,
119 query => $query,
120 );
121 END_SYNOPSIS
122 1 my $constructor = <<'END_CONSTRUCTOR';
123 my $bit_collector = Lucy::Search::Collector::BitCollector->new(
124 bit_vector => $bit_vec, # required
125 );
126 END_CONSTRUCTOR
127 1 $pod_spec->set_synopsis($synopsis);
128 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
129  
130 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
131 parcel => "Lucy",
132 class_name => "Lucy::Search::Collector::BitCollector",
133 );
134 1 $binding->set_pod_spec($pod_spec);
135  
136 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
137 }
138  
139 1 ▶sub bind_compiler {
Subroutine bind_compiler: called CC=1 SCAR=0.0
Pod undocumented
140 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
141 1 my $synopsis = <<'END_SYNOPSIS';
142 # (Compiler is an abstract base class.)
143 package MyCompiler;
144 use base qw( Lucy::Search::Compiler );
145  
146 sub make_matcher {
147 my $self = shift;
148 return MyMatcher->new( @_, compiler => $self );
149 }
150 END_SYNOPSIS
151 1 my $constructor = <<'END_CONSTRUCTOR_POD';
152 =head2 new
153  
154 my $compiler = MyCompiler->SUPER::new(
155 parent => $my_query,
156 searcher => $searcher,
157 similarity => $sim, # default: undef
158 boost => undef, # default: see below
159 );
160  
161 Abstract constructor.
162  
163 =over
164  
165 =item *
166  
167 B<parent> - The parent Query.
168  
169 =item *
170  
171 B<searcher> - A Lucy::Search::Searcher, such as an
172 IndexSearcher.
173  
174 =item *
175  
176 B<similarity> - A Similarity.
177  
178 =item *
179  
180 B<boost> - An arbitrary scoring multiplier. Defaults to the boost of
181 the parent Query.
182  
183 =back
184 END_CONSTRUCTOR_POD
185 1 $pod_spec->set_synopsis($synopsis);
186 1 $pod_spec->add_constructor( alias => 'new', pod => $constructor, );
187  
188 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
189 parcel => "Lucy",
190 class_name => "Lucy::Search::Compiler",
191 );
192 1 $binding->bind_constructor( alias => 'do_new' );
193 1 $binding->set_pod_spec($pod_spec);
194  
195 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
196 }
197  
198 1 ▶sub bind_hits {
Subroutine bind_hits: called CC=1 SCAR=0.0
Pod undocumented
199 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
200 1 my $synopsis = <<'END_SYNOPSIS';
201 my $hits = $searcher->hits(
202 query => $query,
203 offset => 0,
204 num_wanted => 10,
205 );
206 while ( my $hit = $hits->next ) {
207 print "<p>$hit->{title} <em>" . $hit->get_score . "</em></p>\n";
208 }
209 END_SYNOPSIS
210 1 $pod_spec->set_synopsis($synopsis);
211  
212 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
213 parcel => "Lucy",
214 class_name => "Lucy::Search::Hits",
215 );
216 1 $binding->set_pod_spec($pod_spec);
217  
218 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
219 }
220  
221 1 ▶sub bind_indexsearcher {
Subroutine bind_indexsearcher: called CC=1 SCAR=0.0
Pod undocumented
222 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
223 1 my $synopsis = <<'END_SYNOPSIS';
224 my $searcher = Lucy::Search::IndexSearcher->new(
225 index => '/path/to/index'
226 );
227 my $hits = $searcher->hits(
228 query => 'foo bar',
229 offset => 0,
230 num_wanted => 100,
231 );
232 END_SYNOPSIS
233 1 my $constructor = <<'END_CONSTRUCTOR';
234 my $searcher = Lucy::Search::IndexSearcher->new(
235 index => '/path/to/index'
236 );
237 END_CONSTRUCTOR
238 1 $pod_spec->set_synopsis($synopsis);
239 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
240  
241 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
242 parcel => "Lucy",
243 class_name => "Lucy::Search::IndexSearcher",
244 );
245 1 $binding->set_pod_spec($pod_spec);
246  
247 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
248 }
249  
250 1 ▶sub bind_leafquery {
Subroutine bind_leafquery: called CC=1 SCAR=0.0
Pod undocumented
251 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
252 1 my $synopsis = <<'END_SYNOPSIS';
253 package MyQueryParser;
254 use base qw( Lucy::Search::QueryParser );
255  
256 sub expand_leaf {
257 my ( $self, $leaf_query ) = @_;
258 if ( $leaf_query->get_text =~ /.\*\s*$/ ) {
259 return PrefixQuery->new(
260 query_string => $leaf_query->get_text,
261 field => $leaf_query->get_field,
262 );
263 }
264 else {
265 return $self->SUPER::expand_leaf($leaf_query);
266 }
267 }
268 END_SYNOPSIS
269 1 my $constructor = <<'END_CONSTRUCTOR';
270 my $leaf_query = Lucy::Search::LeafQuery->new(
271 text => '"three blind mice"', # required
272 field => 'content', # default: undef
273 );
274 END_CONSTRUCTOR
275 1 $pod_spec->set_synopsis($synopsis);
276 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
277  
278 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
279 parcel => "Lucy",
280 class_name => "Lucy::Search::LeafQuery",
281 );
282 1 $binding->set_pod_spec($pod_spec);
283  
284 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
285 }
286  
287 1 ▶sub bind_matchallquery {
Subroutine bind_matchallquery: called CC=1 SCAR=0.0
Pod undocumented
288 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
289 1 my $constructor = <<'END_CONSTRUCTOR';
290 my $match_all_query = Lucy::Search::MatchAllQuery->new;
291 END_CONSTRUCTOR
292 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
293  
294 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
295 parcel => "Lucy",
296 class_name => "Lucy::Search::MatchAllQuery",
297 );
298 1 $binding->set_pod_spec($pod_spec);
299  
300 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
301 }
302  
303 1 ▶sub bind_matcher {
Subroutine bind_matcher: called CC=1 SCAR=0.0
Pod undocumented
304 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
305 1 my $synopsis = <<'END_SYNOPSIS';
306 # abstract base class
307 END_SYNOPSIS
308 1 my $constructor = <<'END_CONSTRUCTOR_POD';
309 =head2 new
310  
311 my $matcher = MyMatcher->SUPER::new;
312  
313 Abstract constructor.
314 END_CONSTRUCTOR_POD
315 1 $pod_spec->set_synopsis($synopsis);
316 1 $pod_spec->add_constructor( alias => 'new', pod => $constructor, );
317  
318 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
319 parcel => "Lucy",
320 class_name => "Lucy::Search::Matcher",
321 );
322 1 $binding->set_pod_spec($pod_spec);
323  
324 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
325 }
326  
327 1 ▶sub bind_notquery {
Subroutine bind_notquery: called CC=1 SCAR=0.0
Pod undocumented
328 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
329 1 my $synopsis = <<'END_SYNOPSIS';
330 my $not_bar_query = Lucy::Search::NOTQuery->new(
331 negated_query => $bar_query,
332 );
333 my $foo_and_not_bar_query = Lucy::Search::ANDQuery->new(
334 children => [ $foo_query, $not_bar_query ].
335 );
336 my $hits = $searcher->hits( query => $foo_and_not_bar_query );
337 ...
338 END_SYNOPSIS
339 1 my $constructor = <<'END_CONSTRUCTOR';
340 my $not_query = Lucy::Search::NOTQuery->new(
341 negated_query => $query,
342 );
343 END_CONSTRUCTOR
344 1 $pod_spec->set_synopsis($synopsis);
345 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
346  
347 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
348 parcel => "Lucy",
349 class_name => "Lucy::Search::NOTQuery",
350 );
351 1 $binding->set_pod_spec($pod_spec);
352  
353 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
354 }
355  
356 1 ▶sub bind_nomatchquery {
Subroutine bind_nomatchquery: called CC=1 SCAR=0.0
Pod undocumented
357 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
358 1 my $constructor = <<'END_CONSTRUCTOR';
359 my $no_match_query = Lucy::Search::NoMatchQuery->new;
360 END_CONSTRUCTOR
361 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
362  
363 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
364 parcel => "Lucy",
365 class_name => "Lucy::Search::NoMatchQuery",
366 );
367 1 $binding->set_pod_spec($pod_spec);
368  
369 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
370 }
371  
372 1 ▶sub bind_orquery {
Subroutine bind_orquery: called CC=1 SCAR=0.0
Pod undocumented
373 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
374 1 my $synopsis = <<'END_SYNOPSIS';
375 my $foo_or_bar_query = Lucy::Search::ORQuery->new(
376 children => [ $foo_query, $bar_query ],
377 );
378 my $hits = $searcher->hits( query => $foo_or_bar_query );
379 ...
380 END_SYNOPSIS
381 1 my $constructor = <<'END_CONSTRUCTOR';
382 my $foo_or_bar_query = Lucy::Search::ORQuery->new(
383 children => [ $foo_query, $bar_query ],
384 );
385 END_CONSTRUCTOR
386 1 $pod_spec->set_synopsis($synopsis);
387 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
388  
389 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
390 parcel => "Lucy",
391 class_name => "Lucy::Search::ORQuery",
392 );
393 1 $binding->set_pod_spec($pod_spec);
394  
395 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
396 }
397  
398 1 ▶sub bind_parserelem {
Subroutine bind_parserelem: called CC=1 SCAR=0.0
Pod undocumented
399 1 my $xs_code = <<'END_XS_CODE';
400 MODULE = Lucy PACKAGE = Lucy::Search::QueryParser::ParserElem
401  
402 SV*
403 new(either_sv, ...)
404 SV *either_sv;
405 CODE:
406 {
407 static const XSBind_ParamSpec param_specs[2] = {
408 XSBIND_PARAM("type", true),
409 XSBIND_PARAM("value", false)
410 };
411 int32_t locations[2];
412 SV *type_sv = NULL;
413 SV *value_sv = NULL;
414 const char *type_str = NULL;
415 cfish_Obj *value = NULL;
416 uint32_t type = 0;
417 lucy_ParserElem *self = NULL;
418  
419 XSBind_locate_args(aTHX_ &ST(0), 1, items, param_specs, locations, 2);
420  
421 type_sv = ST(locations[0]);
422 value_sv = locations[1] < items ? ST(locations[1]) : NULL;
423  
424 type_str = SvPVutf8_nolen(type_sv);
425  
426 if (strcmp(type_str, "OPEN_PAREN") == 0) {
427 type = LUCY_QPARSER_TOKEN_OPEN_PAREN;
428 }
429 else if (strcmp(type_str, "CLOSE_PAREN") == 0) {
430 type = LUCY_QPARSER_TOKEN_CLOSE_PAREN;
431 }
432 else if (strcmp(type_str, "MINUS") == 0) {
433 type = LUCY_QPARSER_TOKEN_MINUS;
434 }
435 else if (strcmp(type_str, "PLUS") == 0) {
436 type = LUCY_QPARSER_TOKEN_PLUS;
437 }
438 else if (strcmp(type_str, "NOT") == 0) {
439 type = LUCY_QPARSER_TOKEN_NOT;
440 }
441 else if (strcmp(type_str, "AND") == 0) {
442 type = LUCY_QPARSER_TOKEN_AND;
443 }
444 else if (strcmp(type_str, "OR") == 0) {
445 type = LUCY_QPARSER_TOKEN_OR;
446 }
447 else if (strcmp(type_str, "FIELD") == 0) {
448 type = LUCY_QPARSER_TOKEN_FIELD;
449 value = XSBind_perl_to_cfish(aTHX_ value_sv, CFISH_STRING);
450 }
451 else if (strcmp(type_str, "STRING") == 0) {
452 type = LUCY_QPARSER_TOKEN_STRING;
453 value = XSBind_perl_to_cfish(aTHX_ value_sv, CFISH_STRING);
454 }
455 else if (strcmp(type_str, "QUERY") == 0) {
456 type = LUCY_QPARSER_TOKEN_QUERY;
457 value = XSBind_perl_to_cfish(aTHX_ value_sv, LUCY_QUERY);
458 }
459 else {
460 CFISH_THROW(CFISH_ERR, "Bad type: '%s'", type_str);
461 }
462  
463 self = (lucy_ParserElem*)XSBind_new_blank_obj(aTHX_ either_sv);
464 self = lucy_ParserElem_init(self, type, value);
465 RETVAL = XSBind_cfish_to_perl(aTHX_ (cfish_Obj*)self);
466 CFISH_DECREF(self);
467 }
468 OUTPUT: RETVAL
469  
470 END_XS_CODE
471 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
472 parcel => "Lucy",
473 class_name => "Lucy::Search::QueryParser::ParserElem",
474 );
475 1 $binding->exclude_constructor;
476 1 $binding->append_xs($xs_code);
477 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
478 }
479  
480 1 ▶sub bind_phrasequery {
Subroutine bind_phrasequery: called CC=1 SCAR=0.0
Pod undocumented
481 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
482 1 my $synopsis = <<'END_SYNOPSIS';
483 my $phrase_query = Lucy::Search::PhraseQuery->new(
484 field => 'content',
485 terms => [qw( the who )],
486 );
487 my $hits = $searcher->hits( query => $phrase_query );
488 END_SYNOPSIS
489 1 $pod_spec->set_synopsis($synopsis);
490 1 $pod_spec->add_constructor( alias => 'new' );
491  
492 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
493 parcel => "Lucy",
494 class_name => "Lucy::Search::PhraseQuery",
495 );
496 1 $binding->set_pod_spec($pod_spec);
497  
498 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
499 }
500  
501 1 ▶sub bind_phrasecompiler {
Subroutine bind_phrasecompiler: called CC=1 SCAR=0.0
Pod undocumented
502 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
503 parcel => "Lucy",
504 class_name => "Lucy::Search::PhraseCompiler",
505 );
506 1 $binding->bind_constructor( alias => 'do_new' );
507 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
508 }
509  
510 1 ▶sub bind_polyquery {
Subroutine bind_polyquery: called CC=1 SCAR=0.0
Pod undocumented
511 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
512 1 my $synopsis = <<'END_SYNOPSIS';
513 sub walk {
514 my $query = shift;
515 if ( $query->isa("Lucy::Search::PolyQuery") ) {
516 if ( $query->isa("Lucy::Search::ORQuery") ) { ... }
517 elsif ( $query->isa("Lucy::Search::ANDQuery") ) { ... }
518 elsif ( $query->isa("Lucy::Search::RequiredOptionalQuery") ) {
519 ...
520 }
521 elsif ( $query->isa("Lucy::Search::NOTQuery") ) { ... }
522 }
523 else { ... }
524 }
525 END_SYNOPSIS
526 1 $pod_spec->set_synopsis($synopsis);
527  
528 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
529 parcel => "Lucy",
530 class_name => "Lucy::Search::PolyQuery",
531 );
532 1 $binding->set_pod_spec($pod_spec);
533  
534 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
535 }
536  
537 1 ▶sub bind_polysearcher {
Subroutine bind_polysearcher: called CC=1 SCAR=0.0
Pod undocumented
538 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
539 1 my $synopsis = <<'END_SYNOPSIS';
540 my $schema = MySchema->new;
541 for my $index (@index_paths) {
542 push @searchers, Lucy::Search::IndexSearcher->new( index => $index );
543 }
544 my $poly_searcher = Lucy::Search::PolySearcher->new(
545 schema => $schema,
546 searchers => \@searchers,
547 );
548 my $hits = $poly_searcher->hits( query => $query );
549 END_SYNOPSIS
550 1 my $constructor = <<'END_CONSTRUCTOR';
551 my $poly_searcher = Lucy::Search::PolySearcher->new(
552 schema => $schema,
553 searchers => \@searchers,
554 );
555 END_CONSTRUCTOR
556 1 $pod_spec->set_synopsis($synopsis);
557 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
558  
559 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
560 parcel => "Lucy",
561 class_name => "Lucy::Search::PolySearcher",
562 );
563 1 $binding->set_pod_spec($pod_spec);
564  
565 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
566 }
567  
568 1 ▶sub bind_query {
Subroutine bind_query: called CC=1 SCAR=0.0
Pod undocumented
569 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
570 1 my $synopsis = <<'END_SYNOPSIS';
571 # Query is an abstract base class.
572 package MyQuery;
573 use base qw( Lucy::Search::Query );
574
575 sub make_compiler {
576 my ( $self, %args ) = @_;
577 my $subordinate = delete $args{subordinate};
578 my $compiler = MyCompiler->new( %args, parent => $self );
579 $compiler->normalize unless $subordinate;
580 return $compiler;
581 }
582
583 package MyCompiler;
584 use base ( Lucy::Search::Compiler );
585 ...
586 END_SYNOPSIS
587 1 my $constructor = <<'END_CONSTRUCTOR_POD';
588 =head2 new
589  
590 my $query = MyQuery->SUPER::new(
591 boost => 2.5,
592 );
593  
594 Abstract constructor.
595  
596 =over
597  
598 =item *
599  
600 B<boost> - A scoring multiplier, affecting the Query's relative
601 contribution to each document's score. Typically defaults to 1.0, but
602 subclasses which do not contribute to document scores such as NOTQuery
603 and MatchAllQuery default to 0.0 instead.
604  
605 =back
606 END_CONSTRUCTOR_POD
607 1 $pod_spec->set_synopsis($synopsis);
608 1 $pod_spec->add_constructor( alias => 'new', pod => $constructor, );
609  
610 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
611 parcel => "Lucy",
612 class_name => "Lucy::Search::Query",
613 );
614 1 $binding->set_pod_spec($pod_spec);
615  
616 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
617 }
618  
619 1 ▶sub bind_queryparser {
Subroutine bind_queryparser: called CC=1 SCAR=0.0
Pod undocumented
620 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
621 1 my $synopsis = <<'END_SYNOPSIS';
622 my $query_parser = Lucy::Search::QueryParser->new(
623 schema => $searcher->get_schema,
624 fields => ['body'],
625 );
626 my $query = $query_parser->parse( $query_string );
627 my $hits = $searcher->hits( query => $query );
628 END_SYNOPSIS
629 1 my $constructor = <<'END_CONSTRUCTOR';
630 my $query_parser = Lucy::Search::QueryParser->new(
631 schema => $searcher->get_schema, # required
632 analyzer => $analyzer, # overrides schema
633 fields => ['bodytext'], # default: indexed fields
634 default_boolop => 'AND', # default: 'OR'
635 );
636 END_CONSTRUCTOR
637 1 $pod_spec->set_synopsis($synopsis);
638 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
639  
640 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
641 parcel => "Lucy",
642 class_name => "Lucy::Search::QueryParser",
643 );
644 1 $binding->set_pod_spec($pod_spec);
645  
646 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
647 }
648  
649 1 ▶sub bind_rangequery {
Subroutine bind_rangequery: called CC=1 SCAR=0.0
Pod undocumented
650 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
651 1 my $synopsis = <<'END_SYNOPSIS';
652 # Match all articles by "Foo" published since the year 2000.
653 my $range_query = Lucy::Search::RangeQuery->new(
654 field => 'publication_date',
655 lower_term => '2000-01-01',
656 include_lower => 1,
657 );
658 my $author_query = Lucy::Search::TermQuery->new(
659 field => 'author_last_name',
660 text => 'Foo',
661 );
662 my $and_query = Lucy::Search::ANDQuery->new(
663 children => [ $range_query, $author_query ],
664 );
665 my $hits = $searcher->hits( query => $and_query );
666 ...
667 END_SYNOPSIS
668 1 my $constructor = <<'END_CONSTRUCTOR';
669 my $range_query = Lucy::Search::RangeQuery->new(
670 field => 'product_number', # required
671 lower_term => '003', # see below
672 upper_term => '060', # see below
673 include_lower => 0, # default true
674 include_upper => 0, # default true
675 );
676 END_CONSTRUCTOR
677 1 $pod_spec->set_synopsis($synopsis);
678 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
679  
680 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
681 parcel => "Lucy",
682 class_name => "Lucy::Search::RangeQuery",
683 );
684 1 $binding->set_pod_spec($pod_spec);
685  
686 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
687 }
688  
689 1 ▶sub bind_requiredoptionalquery {
Subroutine bind_requiredoptionalquery: called CC=1 SCAR=0.0
Pod undocumented
690 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
691 1 my $synopsis = <<'END_SYNOPSIS';
692 my $foo_and_maybe_bar = Lucy::Search::RequiredOptionalQuery->new(
693 required_query => $foo_query,
694 optional_query => $bar_query,
695 );
696 my $hits = $searcher->hits( query => $foo_and_maybe_bar );
697 ...
698 END_SYNOPSIS
699 1 my $constructor = <<'END_CONSTRUCTOR';
700 my $reqopt_query = Lucy::Search::RequiredOptionalQuery->new(
701 required_query => $foo_query, # required
702 optional_query => $bar_query, # required
703 );
704 END_CONSTRUCTOR
705 1 $pod_spec->set_synopsis($synopsis);
706 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
707  
708 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
709 parcel => "Lucy",
710 class_name => "Lucy::Search::RequiredOptionalQuery",
711 );
712 1 $binding->set_pod_spec($pod_spec);
713  
714 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
715 }
716  
717 1 ▶sub bind_searcher {
Subroutine bind_searcher: called CC=1 SCAR=0.0
Pod undocumented
718 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
719 1 my $constructor = <<'END_CONSTRUCTOR';
720 =head2 new
721  
722 package MySearcher;
723 use base qw( Lucy::Search::Searcher );
724 sub new {
725 my $self = shift->SUPER::new;
726 ...
727 return $self;
728 }
729  
730 Abstract constructor.
731  
732 =over
733  
734 =item *
735  
736 B<schema> - A Schema.
737  
738 =back
739 END_CONSTRUCTOR
740 1 $pod_spec->set_synopsis(" # Abstract base class.\n");
741 1 $pod_spec->add_constructor( alias => 'new', pod => $constructor, );
742  
743 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
744 parcel => "Lucy",
745 class_name => "Lucy::Search::Searcher",
746 );
747 1 $binding->set_pod_spec($pod_spec);
748  
749 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
750 }
751  
752 1 ▶sub bind_sortrule {
Subroutine bind_sortrule: called CC=1 SCAR=0.0
Pod undocumented
753 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
754 1 my $synopsis = <<'END_SYNOPSIS';
755 my $sort_spec = Lucy::Search::SortSpec->new(
756 rules => [
757 Lucy::Search::SortRule->new( field => 'date' ),
758 Lucy::Search::SortRule->new( type => 'doc_id' ),
759 ],
760 );
761 END_SYNOPSIS
762 1 my $constructor = <<'END_CONSTRUCTOR';
763 my $by_title = Lucy::Search::SortRule->new( field => 'title' );
764 my $by_score = Lucy::Search::SortRule->new( type => 'score' );
765 my $by_doc_id = Lucy::Search::SortRule->new( type => 'doc_id' );
766 my $reverse_date = Lucy::Search::SortRule->new(
767 field => 'date',
768 reverse => 1,
769 );
770 END_CONSTRUCTOR
771 1 $pod_spec->set_synopsis($synopsis);
772 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
773  
774 1 my $xs_code = <<'END_XS_CODE';
775 MODULE = Lucy PACKAGE = Lucy::Search::SortRule
776  
777 int32_t
778 FIELD()
779 CODE:
780 RETVAL = lucy_SortRule_FIELD;
781 OUTPUT: RETVAL
782  
783 int32_t
784 SCORE()
785 CODE:
786 RETVAL = lucy_SortRule_SCORE;
787 OUTPUT: RETVAL
788  
789 int32_t
790 DOC_ID()
791 CODE:
792 RETVAL = lucy_SortRule_DOC_ID;
793 OUTPUT: RETVAL
794 END_XS_CODE
795  
796 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
797 parcel => "Lucy",
798 class_name => "Lucy::Search::SortRule",
799 );
800 1 $binding->bind_constructor( alias => '_new' );
801 1 $binding->append_xs($xs_code);
802 1 $binding->set_pod_spec($pod_spec);
803  
804 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
805 }
806  
807 1 ▶sub bind_sortspec {
Subroutine bind_sortspec: called CC=1 SCAR=0.0
Pod undocumented
808 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
809 1 my $synopsis = <<'END_SYNOPSIS';
810 my $sort_spec = Lucy::Search::SortSpec->new(
811 rules => [
812 Lucy::Search::SortRule->new( field => 'date' ),
813 Lucy::Search::SortRule->new( type => 'doc_id' ),
814 ],
815 );
816 my $hits = $searcher->hits(
817 query => $query,
818 sort_spec => $sort_spec,
819 );
820 END_SYNOPSIS
821 1 my $constructor = <<'END_CONSTRUCTOR';
822 my $sort_spec = Lucy::Search::SortSpec->new( rules => \@rules );
823 END_CONSTRUCTOR
824 1 $pod_spec->set_synopsis($synopsis);
825 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
826  
827 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
828 parcel => "Lucy",
829 class_name => "Lucy::Search::SortSpec",
830 );
831 1 $binding->set_pod_spec($pod_spec);
832  
833 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
834 }
835  
836 1 ▶sub bind_span {
Subroutine bind_span: called CC=1 SCAR=0.0
Pod undocumented
837 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
838 1 my $synopsis = <<'END_SYNOPSIS';
839 my $combined_length = $upper_span->get_length
840 + ( $upper_span->get_offset - $lower_span->get_offset );
841 my $combined_span = Lucy::Search::Span->new(
842 offset => $lower_span->get_offset,
843 length => $combined_length,
844 );
845 ...
846 END_SYNOPSIS
847 1 my $constructor = <<'END_CONSTRUCTOR';
848 my $span = Lucy::Search::Span->new(
849 offset => 75, # required
850 length => 7, # required
851 weight => 1.0, # default 0.0
852 );
853 END_CONSTRUCTOR
854 1 $pod_spec->set_synopsis($synopsis);
855 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
856  
857 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
858 parcel => "Lucy",
859 class_name => "Lucy::Search::Span",
860 );
861 1 $binding->set_pod_spec($pod_spec);
862  
863 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
864 }
865  
866 1 ▶sub bind_termquery {
Subroutine bind_termquery: called CC=1 SCAR=0.0
Pod undocumented
867 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
868 1 my $synopsis = <<'END_SYNOPSIS';
869 my $term_query = Lucy::Search::TermQuery->new(
870 field => 'content',
871 term => 'foo',
872 );
873 my $hits = $searcher->hits( query => $term_query );
874 END_SYNOPSIS
875 1 my $constructor = <<'END_CONSTRUCTOR';
876 my $term_query = Lucy::Search::TermQuery->new(
877 field => 'content', # required
878 term => 'foo', # required
879 );
880 END_CONSTRUCTOR
881 1 $pod_spec->set_synopsis($synopsis);
882 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
883  
884 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
885 parcel => "Lucy",
886 class_name => "Lucy::Search::TermQuery",
887 );
888 1 $binding->set_pod_spec($pod_spec);
889  
890 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
891 }
892  
893 1 ▶sub bind_termcompiler {
Subroutine bind_termcompiler: called CC=1 SCAR=0.0
Pod undocumented
894 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
895 parcel => "Lucy",
896 class_name => "Lucy::Search::TermCompiler",
897 );
898 1 $binding->bind_constructor( alias => 'do_new' );
899 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
900 }
901  
902 1 1;
« buildlib/LucyX/Build/Binding/Search.pm ↑ Summary buildlib/Lucy/Build/Binding/Plan.pm »