| 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::Index; | ||
| 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_backgroundmerger; | |
| 25 | 1 | $class->bind_datareader; | |
| 26 | 1 | $class->bind_datawriter; | |
| 27 | 1 | $class->bind_deletionswriter; | |
| 28 | 1 | $class->bind_docreader; | |
| 29 | 1 | $class->bind_indexmanager; | |
| 30 | 1 | $class->bind_indexreader; | |
| 31 | 1 | $class->bind_indexer; | |
| 32 | 1 | $class->bind_lexicon; | |
| 33 | 1 | $class->bind_lexiconreader; | |
| 34 | 1 | $class->bind_polyreader; | |
| 35 | 1 | $class->bind_scoreposting; | |
| 36 | 1 | $class->bind_postinglist; | |
| 37 | 1 | $class->bind_postinglistreader; | |
| 38 | 1 | $class->bind_postinglistwriter; | |
| 39 | 1 | $class->bind_segreader; | |
| 40 | 1 | $class->bind_segwriter; | |
| 41 | 1 | $class->bind_segment; | |
| 42 | 1 | $class->bind_similarity; | |
| 43 | 1 | $class->bind_snapshot; | |
| 44 | 1 | $class->bind_sortcache; | |
| 45 | 1 | $class->bind_sortwriter; | |
| 46 | } | ||
| 47 | |||
| 48 | 1 | ▶ | sub bind_backgroundmerger { |
|
Subroutine
bind_backgroundmerger: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 49 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 50 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 51 | my $bg_merger = Lucy::Index::BackgroundMerger->new( | ||
| 52 | index => '/path/to/index', | ||
| 53 | ); | ||
| 54 | $bg_merger->commit; | ||
| 55 | END_SYNOPSIS | ||
| 56 | 1 | my $constructor = <<'END_CONSTRUCTOR'; | |
| 57 | my $bg_merger = Lucy::Index::BackgroundMerger->new( | ||
| 58 | index => '/path/to/index', # required | ||
| 59 | manager => $manager # default: created internally | ||
| 60 | ); | ||
| 61 | END_CONSTRUCTOR | ||
| 62 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 63 | 1 | $pod_spec->add_constructor( alias => 'new', sample => $constructor, ); | |
| 64 | |||
| 65 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 66 | parcel => "Lucy", | ||
| 67 | class_name => "Lucy::Index::BackgroundMerger", | ||
| 68 | ); | ||
| 69 | 1 | $binding->set_pod_spec($pod_spec); | |
| 70 | |||
| 71 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 72 | } | ||
| 73 | |||
| 74 | 1 | ▶ | sub bind_datareader { |
|
Subroutine
bind_datareader: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 75 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 76 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 77 | # Abstract base class. | ||
| 78 | END_SYNOPSIS | ||
| 79 | 1 | my $constructor = <<'END_CONSTRUCTOR'; | |
| 80 | =head2 new | ||
| 81 | |||
| 82 | my $reader = MyDataReader->new( | ||
| 83 | schema => $seg_reader->get_schema, # default undef | ||
| 84 | folder => $seg_reader->get_folder, # default undef | ||
| 85 | snapshot => $seg_reader->get_snapshot, # default undef | ||
| 86 | segments => $seg_reader->get_segments, # default undef | ||
| 87 | seg_tick => $seg_reader->get_seg_tick, # default -1 | ||
| 88 | ); | ||
| 89 | |||
| 90 | Abstract constructor. | ||
| 91 | |||
| 92 | =over | ||
| 93 | |||
| 94 | =item * | ||
| 95 | |||
| 96 | B<schema> - A Schema. | ||
| 97 | |||
| 98 | =item * | ||
| 99 | |||
| 100 | B<folder> - A Folder. | ||
| 101 | |||
| 102 | =item * | ||
| 103 | |||
| 104 | B<snapshot> - A Snapshot. | ||
| 105 | |||
| 106 | =item * | ||
| 107 | |||
| 108 | B<segments> - An array of Segments. | ||
| 109 | |||
| 110 | =item * | ||
| 111 | |||
| 112 | B<seg_tick> - The array index of the Segment object within the | ||
| 113 | C<segments> array that this particular DataReader is assigned | ||
| 114 | to, if any. A value of -1 indicates that no Segment should be | ||
| 115 | assigned. | ||
| 116 | |||
| 117 | =back | ||
| 118 | END_CONSTRUCTOR | ||
| 119 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 120 | 1 | $pod_spec->add_constructor( alias => 'new', pod => $constructor, ); | |
| 121 | |||
| 122 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 123 | parcel => "Lucy", | ||
| 124 | class_name => "Lucy::Index::DataReader", | ||
| 125 | ); | ||
| 126 | 1 | $binding->set_pod_spec($pod_spec); | |
| 127 | |||
| 128 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 129 | } | ||
| 130 | |||
| 131 | 1 | ▶ | sub bind_datawriter { |
|
Subroutine
bind_datawriter: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 132 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 133 | 1 | my $synopsis = <<END_SYNOPSIS; | |
| 134 | # Abstract base class. | ||
| 135 | END_SYNOPSIS | ||
| 136 | 1 | my $constructor = <<'END_CONSTRUCTOR'; | |
| 137 | =head2 new | ||
| 138 | |||
| 139 | my $writer = MyDataWriter->new( | ||
| 140 | snapshot => $snapshot, # required | ||
| 141 | segment => $segment, # required | ||
| 142 | polyreader => $polyreader, # required | ||
| 143 | ); | ||
| 144 | |||
| 145 | Abstract constructor. | ||
| 146 | |||
| 147 | =over | ||
| 148 | |||
| 149 | =item * | ||
| 150 | |||
| 151 | B<snapshot> - The Snapshot that will be committed at the end of the | ||
| 152 | indexing session. | ||
| 153 | |||
| 154 | =item * | ||
| 155 | |||
| 156 | B<segment> - The Segment in progress. | ||
| 157 | |||
| 158 | =item * | ||
| 159 | |||
| 160 | B<polyreader> - A PolyReader representing all existing data in the | ||
| 161 | index. (If the index is brand new, the PolyReader will have no | ||
| 162 | sub-readers). | ||
| 163 | |||
| 164 | =back | ||
| 165 | END_CONSTRUCTOR | ||
| 166 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 167 | 1 | $pod_spec->add_constructor( alias => 'new', pod => $constructor, ); | |
| 168 | |||
| 169 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 170 | parcel => "Lucy", | ||
| 171 | class_name => "Lucy::Index::DataWriter", | ||
| 172 | ); | ||
| 173 | 1 | $binding->set_pod_spec($pod_spec); | |
| 174 | |||
| 175 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 176 | } | ||
| 177 | |||
| 178 | 1 | ▶ | sub bind_deletionswriter { |
|
Subroutine
bind_deletionswriter: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 179 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 180 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 181 | my $polyreader = $del_writer->get_polyreader; | ||
| 182 | my $seg_readers = $polyreader->seg_readers; | ||
| 183 | for my $seg_reader (@$seg_readers) { | ||
| 184 | my $count = $del_writer->seg_del_count( $seg_reader->get_seg_name ); | ||
| 185 | ... | ||
| 186 | } | ||
| 187 | END_SYNOPSIS | ||
| 188 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 189 | |||
| 190 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 191 | parcel => "Lucy", | ||
| 192 | class_name => "Lucy::Index::DeletionsWriter", | ||
| 193 | ); | ||
| 194 | 1 | $binding->set_pod_spec($pod_spec); | |
| 195 | |||
| 196 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 197 | } | ||
| 198 | |||
| 199 | 1 | ▶ | sub bind_docreader { |
|
Subroutine
bind_docreader: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 200 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 201 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 202 | my $doc_reader = $seg_reader->obtain("Lucy::Index::DocReader"); | ||
| 203 | my $doc = $doc_reader->fetch_doc($doc_id); | ||
| 204 | END_SYNOPSIS | ||
| 205 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 206 | |||
| 207 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 208 | parcel => "Lucy", | ||
| 209 | class_name => "Lucy::Index::DocReader", | ||
| 210 | ); | ||
| 211 | 1 | $binding->set_pod_spec($pod_spec); | |
| 212 | |||
| 213 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 214 | } | ||
| 215 | |||
| 216 | 1 | ▶ | sub bind_indexmanager { |
|
Subroutine
bind_indexmanager: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 217 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 218 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 219 | use Sys::Hostname qw( hostname ); | ||
| 220 | my $hostname = hostname() or die "Can't get unique hostname"; | ||
| 221 | my $manager = Lucy::Index::IndexManager->new( | ||
| 222 | host => $hostname, | ||
| 223 | ); | ||
| 224 | |||
| 225 | # Index time: | ||
| 226 | my $indexer = Lucy::Index::Indexer->new( | ||
| 227 | index => '/path/to/index', | ||
| 228 | manager => $manager, | ||
| 229 | ); | ||
| 230 | |||
| 231 | # Search time: | ||
| 232 | my $reader = Lucy::Index::IndexReader->open( | ||
| 233 | index => '/path/to/index', | ||
| 234 | manager => $manager, | ||
| 235 | ); | ||
| 236 | my $searcher = Lucy::Search::IndexSearcher->new( index => $reader ); | ||
| 237 | END_SYNOPSIS | ||
| 238 | 1 | my $constructor = <<'END_CONSTRUCTOR'; | |
| 239 | my $manager = Lucy::Index::IndexManager->new( | ||
| 240 | host => $hostname, # default: "" | ||
| 241 | ); | ||
| 242 | END_CONSTRUCTOR | ||
| 243 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 244 | 1 | $pod_spec->add_constructor( alias => 'new', sample => $constructor, ); | |
| 245 | |||
| 246 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 247 | parcel => "Lucy", | ||
| 248 | class_name => "Lucy::Index::IndexManager", | ||
| 249 | ); | ||
| 250 | 1 | $binding->set_pod_spec($pod_spec); | |
| 251 | |||
| 252 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 253 | } | ||
| 254 | |||
| 255 | 1 | ▶ | sub bind_indexreader { |
|
Subroutine
bind_indexreader: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 256 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 257 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 258 | my $reader = Lucy::Index::IndexReader->open( | ||
| 259 | index => '/path/to/index', | ||
| 260 | ); | ||
| 261 | my $seg_readers = $reader->seg_readers; | ||
| 262 | for my $seg_reader (@$seg_readers) { | ||
| 263 | my $seg_name = $seg_reader->get_segment->get_name; | ||
| 264 | my $num_docs = $seg_reader->doc_max; | ||
| 265 | print "Segment $seg_name ($num_docs documents):\n"; | ||
| 266 | my $doc_reader = $seg_reader->obtain("Lucy::Index::DocReader"); | ||
| 267 | for my $doc_id ( 1 .. $num_docs ) { | ||
| 268 | my $doc = $doc_reader->fetch_doc($doc_id); | ||
| 269 | print " $doc_id: $doc->{title}\n"; | ||
| 270 | } | ||
| 271 | } | ||
| 272 | END_SYNOPSIS | ||
| 273 | 1 | my $constructor = <<'END_CONSTRUCTOR'; | |
| 274 | my $reader = Lucy::Index::IndexReader->open( | ||
| 275 | index => '/path/to/index', # required | ||
| 276 | snapshot => $snapshot, | ||
| 277 | manager => $index_manager, | ||
| 278 | ); | ||
| 279 | END_CONSTRUCTOR | ||
| 280 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 281 | 1 | $pod_spec->add_constructor( | |
| 282 | alias => 'open', | ||
| 283 | sample => $constructor, | ||
| 284 | ); | ||
| 285 | 1 | $pod_spec->add_method( | |
| 286 | method => 'Offsets', | ||
| 287 | alias => 'offsets', | ||
| 288 | ); | ||
| 289 | |||
| 290 | 1 | my $xs_code = <<'END_XS_CODE'; | |
| 291 | MODULE = Lucy PACKAGE = Lucy::Index::IndexReader | ||
| 292 | |||
| 293 | void | ||
| 294 | set_race_condition_debug1(val_sv) | ||
| 295 | SV *val_sv; | ||
| 296 | PPCODE: | ||
| 297 | CFISH_DECREF(lucy_PolyReader_race_condition_debug1); | ||
| 298 | lucy_PolyReader_race_condition_debug1 = (cfish_String*) | ||
| 299 | XSBind_perl_to_cfish_nullable(aTHX_ val_sv, CFISH_STRING); | ||
| 300 | |||
| 301 | int32_t | ||
| 302 | debug1_num_passes() | ||
| 303 | CODE: | ||
| 304 | RETVAL = lucy_PolyReader_debug1_num_passes; | ||
| 305 | OUTPUT: RETVAL | ||
| 306 | END_XS_CODE | ||
| 307 | |||
| 308 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 309 | parcel => "Lucy", | ||
| 310 | class_name => "Lucy::Index::IndexReader", | ||
| 311 | ); | ||
| 312 | 1 | $binding->bind_constructor( | |
| 313 | alias => 'open', | ||
| 314 | initializer => 'do_open', | ||
| 315 | ); | ||
| 316 | 1 | $binding->exclude_constructor; | |
| 317 | 1 | $binding->bind_method( alias => '_offsets', method => 'Offsets' ); | |
| 318 | 1 | $binding->append_xs($xs_code); | |
| 319 | 1 | $binding->set_pod_spec($pod_spec); | |
| 320 | |||
| 321 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 322 | } | ||
| 323 | |||
| 324 | 1 | ▶ | sub bind_indexer { |
|
Subroutine
bind_indexer: called CC=2 SCAR=6.9
Pod
undocumented
| |||
| 325 | 1 | my @hand_rolled = qw( Add_Doc ); | |
| 326 | |||
| 327 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 328 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 329 | my $indexer = Lucy::Index::Indexer->new( | ||
| 330 | schema => $schema, | ||
| 331 | index => '/path/to/index', | ||
| 332 | create => 1, | ||
| 333 | ); | ||
| 334 | while ( my ( $title, $content ) = each %source_docs ) { | ||
| 335 | $indexer->add_doc({ | ||
| 336 | title => $title, | ||
| 337 | content => $content, | ||
| 338 | }); | ||
| 339 | } | ||
| 340 | $indexer->commit; | ||
| 341 | END_SYNOPSIS | ||
| 342 | 1 | my $constructor = <<'END_NEW'; | |
| 343 | =head2 new | ||
| 344 | |||
| 345 | my $indexer = Lucy::Index::Indexer->new( | ||
| 346 | schema => $schema, # required at index creation | ||
| 347 | index => '/path/to/index', # required | ||
| 348 | create => 1, # default: 0 | ||
| 349 | truncate => 1, # default: 0 | ||
| 350 | manager => $manager # default: created internally | ||
| 351 | ); | ||
| 352 | |||
| 353 | =over | ||
| 354 | |||
| 355 | =item * | ||
| 356 | |||
| 357 | B<schema> - A Schema. Required when index is being created; if not supplied, | ||
| 358 | will be extracted from the index folder. | ||
| 359 | |||
| 360 | =item * | ||
| 361 | |||
| 362 | B<index> - Either a filepath to an index or a Folder. | ||
| 363 | |||
| 364 | =item * | ||
| 365 | |||
| 366 | B<create> - If true and the index directory does not exist, attempt to create | ||
| 367 | it. | ||
| 368 | |||
| 369 | =item * | ||
| 370 | |||
| 371 | B<truncate> - If true, proceed with the intention of discarding all previous | ||
| 372 | indexing data. The old data will remain intact and visible until commit() | ||
| 373 | succeeds. | ||
| 374 | |||
| 375 | =item * | ||
| 376 | |||
| 377 | B<manager> - An IndexManager. | ||
| 378 | |||
| 379 | =back | ||
| 380 | END_NEW | ||
| 381 | 1 | my $add_doc_pod = <<'END_ADD_DOC_POD'; | |
| 382 | =head2 add_doc | ||
| 383 | |||
| 384 | $indexer->add_doc($doc); | ||
| 385 | $indexer->add_doc( { field_name => $field_value } ); | ||
| 386 | $indexer->add_doc( | ||
| 387 | doc => { field_name => $field_value }, | ||
| 388 | boost => 2.5, # default: 1.0 | ||
| 389 | ); | ||
| 390 | |||
| 391 | Add a document to the index. Accepts either a single argument or labeled | ||
| 392 | params. | ||
| 393 | |||
| 394 | =over | ||
| 395 | |||
| 396 | =item * | ||
| 397 | |||
| 398 | B<doc> - Either a Lucy::Document::Doc object, or a hashref (which will | ||
| 399 | be attached to a Lucy::Document::Doc object internally). | ||
| 400 | |||
| 401 | =item * | ||
| 402 | |||
| 403 | B<boost> - A floating point weight which affects how this document scores. | ||
| 404 | |||
| 405 | =back | ||
| 406 | |||
| 407 | END_ADD_DOC_POD | ||
| 408 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 409 | |||
| 410 | # Override necessary because of different handling for flags. | ||
| 411 | 1 | $pod_spec->add_constructor( alias => 'new', pod => $constructor ); | |
| 412 | |||
| 413 | # Override is necessary because there's no standard way to explain | ||
| 414 | # hash/hashref across multiple host languages. | ||
| 415 | 1 | $pod_spec->add_method( | |
| 416 | method => 'Add_Doc', | ||
| 417 | alias => 'add_doc', | ||
| 418 | pod => $add_doc_pod, | ||
| 419 | ); | ||
| 420 | |||
| 421 | 1 | my $xs_code = <<'END_XS_CODE'; | |
| 422 | MODULE = Lucy PACKAGE = Lucy::Index::Indexer | ||
| 423 | |||
| 424 | int32_t | ||
| 425 | CREATE(...) | ||
| 426 | CODE: | ||
| 427 | CFISH_UNUSED_VAR(items); | ||
| 428 | RETVAL = lucy_Indexer_CREATE; | ||
| 429 | OUTPUT: RETVAL | ||
| 430 | |||
| 431 | int32_t | ||
| 432 | TRUNCATE(...) | ||
| 433 | CODE: | ||
| 434 | CFISH_UNUSED_VAR(items); | ||
| 435 | RETVAL = lucy_Indexer_TRUNCATE; | ||
| 436 | OUTPUT: RETVAL | ||
| 437 | |||
| 438 | void | ||
| 439 | add_doc(self, ...) | ||
| 440 | lucy_Indexer *self; | ||
| 441 | PPCODE: | ||
| 442 | { | ||
| 443 | lucy_Doc *doc = NULL; | ||
| 444 | SV *doc_sv = NULL; | ||
| 445 | float boost = 1.0; | ||
| 446 | |||
| 447 | if (items == 2) { | ||
| 448 | doc_sv = ST(1); | ||
| 449 | } | ||
| 450 | else { | ||
| 451 | static const XSBind_ParamSpec param_specs[2] = { | ||
| 452 | XSBIND_PARAM("doc", true), | ||
| 453 | XSBIND_PARAM("boost", false) | ||
| 454 | }; | ||
| 455 | int32_t locations[2]; | ||
| 456 | |||
| 457 | XSBind_locate_args(aTHX_ &ST(0), 1, items, param_specs, locations, 2); | ||
| 458 | |||
| 459 | doc_sv = ST(locations[0]); | ||
| 460 | if (locations[1] < items) { boost = (float)SvNV(ST(locations[1])); } | ||
| 461 | } | ||
| 462 | |||
| 463 | // Either get a Doc or use the stock doc. | ||
| 464 | if (sv_isobject(doc_sv) | ||
| 465 | && sv_derived_from(doc_sv, "Lucy::Document::Doc") | ||
| 466 | ) { | ||
| 467 | IV tmp = SvIV(SvRV(doc_sv)); | ||
| 468 | doc = INT2PTR(lucy_Doc*, tmp); | ||
| 469 | } | ||
| 470 | else if (XSBind_sv_defined(aTHX_ doc_sv) && SvROK(doc_sv)) { | ||
| 471 | HV *maybe_fields = (HV*)SvRV(doc_sv); | ||
| 472 | if (SvTYPE((SV*)maybe_fields) == SVt_PVHV) { | ||
| 473 | doc = LUCY_Indexer_Get_Stock_Doc(self); | ||
| 474 | LUCY_Doc_Set_Fields(doc, maybe_fields); | ||
| 475 | } | ||
| 476 | } | ||
| 477 | if (!doc) { | ||
| 478 | THROW(CFISH_ERR, "Need either a hashref or a %o", | ||
| 479 | CFISH_Class_Get_Name(LUCY_DOC)); | ||
| 480 | } | ||
| 481 | |||
| 482 | LUCY_Indexer_Add_Doc(self, doc, boost); | ||
| 483 | } | ||
| 484 | END_XS_CODE | ||
| 485 | |||
| 486 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 487 | parcel => "Lucy", | ||
| 488 | class_name => "Lucy::Index::Indexer", | ||
| 489 | ); | ||
| 490 | 1 | $binding->bind_constructor( alias => '_new' ); | |
| 491 | 1 | $binding->exclude_method($_) for @hand_rolled; | |
| 492 | 1 | $binding->append_xs($xs_code); | |
| 493 | 1 | $binding->set_pod_spec($pod_spec); | |
| 494 | |||
| 495 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 496 | } | ||
| 497 | |||
| 498 | 1 | ▶ | sub bind_lexicon { |
|
Subroutine
bind_lexicon: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 499 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 500 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 501 | my $lex_reader = $seg_reader->obtain('Lucy::Index::LexiconReader'); | ||
| 502 | my $lexicon = $lex_reader->lexicon( field => 'content' ); | ||
| 503 | while ( $lexicon->next ) { | ||
| 504 | print $lexicon->get_term . "\n"; | ||
| 505 | } | ||
| 506 | END_SYNOPSIS | ||
| 507 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 508 | |||
| 509 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 510 | parcel => "Lucy", | ||
| 511 | class_name => "Lucy::Index::Lexicon", | ||
| 512 | ); | ||
| 513 | 1 | $binding->set_pod_spec($pod_spec); | |
| 514 | |||
| 515 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 516 | } | ||
| 517 | |||
| 518 | 1 | ▶ | sub bind_lexiconreader { |
|
Subroutine
bind_lexiconreader: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 519 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 520 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 521 | my $lex_reader = $seg_reader->obtain("Lucy::Index::LexiconReader"); | ||
| 522 | my $lexicon = $lex_reader->lexicon( field => 'title' ); | ||
| 523 | END_SYNOPSIS | ||
| 524 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 525 | |||
| 526 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 527 | parcel => "Lucy", | ||
| 528 | class_name => "Lucy::Index::LexiconReader", | ||
| 529 | ); | ||
| 530 | 1 | $binding->set_pod_spec($pod_spec); | |
| 531 | |||
| 532 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 533 | } | ||
| 534 | |||
| 535 | 1 | ▶ | sub bind_polyreader { |
|
Subroutine
bind_polyreader: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 536 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 537 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 538 | my $polyreader = Lucy::Index::IndexReader->open( | ||
| 539 | index => '/path/to/index', | ||
| 540 | ); | ||
| 541 | my $doc_reader = $polyreader->obtain("Lucy::Index::DocReader"); | ||
| 542 | for my $doc_id ( 1 .. $polyreader->doc_max ) { | ||
| 543 | my $doc = $doc_reader->fetch_doc($doc_id); | ||
| 544 | print " $doc_id: $doc->{title}\n"; | ||
| 545 | } | ||
| 546 | END_SYNOPSIS | ||
| 547 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 548 | 1 | $pod_spec->add_method( | |
| 549 | method => 'Offsets', | ||
| 550 | alias => 'offsets', | ||
| 551 | ); | ||
| 552 | |||
| 553 | 1 | my $xs_code = <<'END_XS_CODE'; | |
| 554 | MODULE = Lucy PACKAGE = Lucy::Index::PolyReader | ||
| 555 | |||
| 556 | uint32_t | ||
| 557 | sub_tick(offsets, doc_id) | ||
| 558 | lucy_I32Array *offsets; | ||
| 559 | int32_t doc_id; | ||
| 560 | CODE: | ||
| 561 | RETVAL = lucy_PolyReader_sub_tick(offsets, doc_id); | ||
| 562 | OUTPUT: RETVAL | ||
| 563 | |||
| 564 | END_XS_CODE | ||
| 565 | |||
| 566 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 567 | parcel => "Lucy", | ||
| 568 | class_name => "Lucy::Index::PolyReader", | ||
| 569 | ); | ||
| 570 | 1 | $binding->bind_constructor( alias => 'open', initializer => 'do_open' ); | |
| 571 | 1 | $binding->append_xs($xs_code); | |
| 572 | 1 | $binding->set_pod_spec($pod_spec); | |
| 573 | |||
| 574 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 575 | } | ||
| 576 | |||
| 577 | 1 | ▶ | sub bind_scoreposting { |
|
Subroutine
bind_scoreposting: called CC=2 SCAR=6.9
Pod
undocumented
| |||
| 578 | 1 | my @hand_rolled = qw( Get_Prox ); | |
| 579 | |||
| 580 | 1 | my $xs_code = <<'END_XS_CODE'; | |
| 581 | MODULE = Lucy PACKAGE = Lucy::Index::Posting::ScorePosting | ||
| 582 | |||
| 583 | SV* | ||
| 584 | get_prox(self) | ||
| 585 | lucy_ScorePosting *self; | ||
| 586 | CODE: | ||
| 587 | { | ||
| 588 | AV *out_av = newAV(); | ||
| 589 | uint32_t *positions = LUCY_ScorePost_Get_Prox(self); | ||
| 590 | uint32_t i, max; | ||
| 591 | |||
| 592 | for (i = 0, max = LUCY_ScorePost_Get_Freq(self); i < max; i++) { | ||
| 593 | SV *pos_sv = newSVuv(positions[i]); | ||
| 594 | av_push(out_av, pos_sv); | ||
| 595 | } | ||
| 596 | |||
| 597 | RETVAL = newRV_noinc((SV*)out_av); | ||
| 598 | } | ||
| 599 | OUTPUT: RETVAL | ||
| 600 | END_XS_CODE | ||
| 601 | |||
| 602 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 603 | parcel => "Lucy", | ||
| 604 | class_name => "Lucy::Index::Posting::ScorePosting", | ||
| 605 | ); | ||
| 606 | 1 | $binding->append_xs($xs_code); | |
| 607 | 1 | $binding->exclude_method($_) for @hand_rolled; | |
| 608 | |||
| 609 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 610 | } | ||
| 611 | |||
| 612 | 1 | ▶ | sub bind_postinglist { |
|
Subroutine
bind_postinglist: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 613 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 614 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 615 | my $posting_list_reader | ||
| 616 | = $seg_reader->obtain("Lucy::Index::PostingListReader"); | ||
| 617 | my $posting_list = $posting_list_reader->posting_list( | ||
| 618 | field => 'content', | ||
| 619 | term => 'foo', | ||
| 620 | ); | ||
| 621 | while ( my $doc_id = $posting_list->next ) { | ||
| 622 | say "Matching doc id: $doc_id"; | ||
| 623 | } | ||
| 624 | END_SYNOPSIS | ||
| 625 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 626 | |||
| 627 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 628 | parcel => "Lucy", | ||
| 629 | class_name => "Lucy::Index::PostingList", | ||
| 630 | ); | ||
| 631 | 1 | $binding->set_pod_spec($pod_spec); | |
| 632 | |||
| 633 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 634 | } | ||
| 635 | |||
| 636 | 1 | ▶ | sub bind_postinglistreader { |
|
Subroutine
bind_postinglistreader: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 637 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 638 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 639 | my $posting_list_reader | ||
| 640 | = $seg_reader->obtain("Lucy::Index::PostingListReader"); | ||
| 641 | my $posting_list = $posting_list_reader->posting_list( | ||
| 642 | field => 'title', | ||
| 643 | term => 'foo', | ||
| 644 | ); | ||
| 645 | END_SYNOPSIS | ||
| 646 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 647 | |||
| 648 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 649 | parcel => "Lucy", | ||
| 650 | class_name => "Lucy::Index::PostingListReader", | ||
| 651 | ); | ||
| 652 | 1 | $binding->set_pod_spec($pod_spec); | |
| 653 | |||
| 654 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 655 | } | ||
| 656 | |||
| 657 | 1 | ▶ | sub bind_postinglistwriter { |
|
Subroutine
bind_postinglistwriter: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 658 | 1 | my $xs_code = <<'END_XS'; | |
| 659 | MODULE = Lucy PACKAGE = Lucy::Index::PostingListWriter | ||
| 660 | |||
| 661 | void | ||
| 662 | set_default_mem_thresh(mem_thresh) | ||
| 663 | uint32_t mem_thresh; | ||
| 664 | PPCODE: | ||
| 665 | lucy_PListWriter_set_default_mem_thresh(mem_thresh); | ||
| 666 | END_XS | ||
| 667 | |||
| 668 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 669 | parcel => "Lucy", | ||
| 670 | class_name => "Lucy::Index::PostingListWriter", | ||
| 671 | ); | ||
| 672 | 1 | $binding->append_xs($xs_code); | |
| 673 | |||
| 674 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 675 | } | ||
| 676 | |||
| 677 | 1 | ▶ | sub bind_segreader { |
|
Subroutine
bind_segreader: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 678 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 679 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 680 | my $polyreader = Lucy::Index::IndexReader->open( | ||
| 681 | index => '/path/to/index', | ||
| 682 | ); | ||
| 683 | my $seg_readers = $polyreader->seg_readers; | ||
| 684 | for my $seg_reader (@$seg_readers) { | ||
| 685 | my $seg_name = $seg_reader->get_seg_name; | ||
| 686 | my $num_docs = $seg_reader->doc_max; | ||
| 687 | print "Segment $seg_name ($num_docs documents):\n"; | ||
| 688 | my $doc_reader = $seg_reader->obtain("Lucy::Index::DocReader"); | ||
| 689 | for my $doc_id ( 1 .. $num_docs ) { | ||
| 690 | my $doc = $doc_reader->fetch_doc($doc_id); | ||
| 691 | print " $doc_id: $doc->{title}\n"; | ||
| 692 | } | ||
| 693 | } | ||
| 694 | END_SYNOPSIS | ||
| 695 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 696 | |||
| 697 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 698 | parcel => "Lucy", | ||
| 699 | class_name => "Lucy::Index::SegReader", | ||
| 700 | ); | ||
| 701 | 1 | $binding->set_pod_spec($pod_spec); | |
| 702 | |||
| 703 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 704 | } | ||
| 705 | |||
| 706 | 1 | ▶ | sub bind_segwriter { |
|
Subroutine
bind_segwriter: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 707 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 708 | |||
| 709 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 710 | parcel => "Lucy", | ||
| 711 | class_name => "Lucy::Index::SegWriter", | ||
| 712 | ); | ||
| 713 | 1 | $binding->set_pod_spec($pod_spec); | |
| 714 | |||
| 715 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 716 | } | ||
| 717 | |||
| 718 | 1 | ▶ | sub bind_segment { |
|
Subroutine
bind_segment: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 719 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 720 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 721 | # Index-time. | ||
| 722 | package MyDataWriter; | ||
| 723 | use base qw( Lucy::Index::DataWriter ); | ||
| 724 | |||
| 725 | sub finish { | ||
| 726 | my $self = shift; | ||
| 727 | my $segment = $self->get_segment; | ||
| 728 | my $metadata = $self->SUPER::metadata(); | ||
| 729 | $metadata->{foo} = $self->get_foo; | ||
| 730 | $segment->store_metadata( | ||
| 731 | key => 'my_component', | ||
| 732 | metadata => $metadata | ||
| 733 | ); | ||
| 734 | } | ||
| 735 | |||
| 736 | # Search-time. | ||
| 737 | package MyDataReader; | ||
| 738 | use base qw( Lucy::Index::DataReader ); | ||
| 739 | |||
| 740 | sub new { | ||
| 741 | my $self = shift->SUPER::new(@_); | ||
| 742 | my $segment = $self->get_segment; | ||
| 743 | my $metadata = $segment->fetch_metadata('my_component'); | ||
| 744 | if ($metadata) { | ||
| 745 | $self->set_foo( $metadata->{foo} ); | ||
| 746 | ... | ||
| 747 | } | ||
| 748 | return $self; | ||
| 749 | } | ||
| 750 | END_SYNOPSIS | ||
| 751 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 752 | |||
| 753 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 754 | parcel => "Lucy", | ||
| 755 | class_name => "Lucy::Index::Segment", | ||
| 756 | ); | ||
| 757 | 1 | $binding->set_pod_spec($pod_spec); | |
| 758 | |||
| 759 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 760 | } | ||
| 761 | |||
| 762 | 1 | ▶ | sub bind_similarity { |
|
Subroutine
bind_similarity: called CC=2 SCAR=6.9
Pod
undocumented
| |||
| 763 | 1 | my @hand_rolled = qw( Get_Norm_Decoder ); | |
| 764 | |||
| 765 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 766 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 767 | package MySimilarity; | ||
| 768 | |||
| 769 | sub length_norm { return 1.0 } # disable length normalization | ||
| 770 | |||
| 771 | package MyFullTextType; | ||
| 772 | use base qw( Lucy::Plan::FullTextType ); | ||
| 773 | |||
| 774 | sub make_similarity { MySimilarity->new } | ||
| 775 | END_SYNOPSIS | ||
| 776 | 1 | my $constructor = qq| my \$sim = Lucy::Index::Similarity->new;\n|; | |
| 777 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 778 | 1 | $pod_spec->add_constructor( alias => 'new', sample => $constructor, ); | |
| 779 | |||
| 780 | 1 | my $xs_code = <<'END_XS_CODE'; | |
| 781 | MODULE = Lucy PACKAGE = Lucy::Index::Similarity | ||
| 782 | |||
| 783 | SV* | ||
| 784 | get_norm_decoder(self) | ||
| 785 | lucy_Similarity *self; | ||
| 786 | CODE: | ||
| 787 | RETVAL = newSVpvn((char*)LUCY_Sim_Get_Norm_Decoder(self), | ||
| 788 | (256 * sizeof(float))); | ||
| 789 | OUTPUT: RETVAL | ||
| 790 | END_XS_CODE | ||
| 791 | |||
| 792 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 793 | parcel => "Lucy", | ||
| 794 | class_name => "Lucy::Index::Similarity", | ||
| 795 | ); | ||
| 796 | 1 | $binding->exclude_method($_) for @hand_rolled; | |
| 797 | 1 | $binding->append_xs($xs_code); | |
| 798 | 1 | $binding->set_pod_spec($pod_spec); | |
| 799 | |||
| 800 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 801 | } | ||
| 802 | |||
| 803 | 1 | ▶ | sub bind_snapshot { |
|
Subroutine
bind_snapshot: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 804 | 1 | my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; | |
| 805 | 1 | my $synopsis = <<'END_SYNOPSIS'; | |
| 806 | my $snapshot = Lucy::Index::Snapshot->new; | ||
| 807 | $snapshot->read_file( folder => $folder ); # load most recent snapshot | ||
| 808 | my $files = $snapshot->list; | ||
| 809 | print "$_\n" for @$files; | ||
| 810 | END_SYNOPSIS | ||
| 811 | 1 | my $constructor = <<'END_CONSTRUCTOR'; | |
| 812 | my $snapshot = Lucy::Index::Snapshot->new; | ||
| 813 | END_CONSTRUCTOR | ||
| 814 | 1 | $pod_spec->set_synopsis($synopsis); | |
| 815 | 1 | $pod_spec->add_constructor( alias => 'new', sample => $constructor, ); | |
| 816 | |||
| 817 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 818 | parcel => "Lucy", | ||
| 819 | class_name => "Lucy::Index::Snapshot", | ||
| 820 | ); | ||
| 821 | 1 | $binding->set_pod_spec($pod_spec); | |
| 822 | |||
| 823 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 824 | } | ||
| 825 | |||
| 826 | 1 | ▶ | sub bind_sortcache { |
|
Subroutine
bind_sortcache: called CC=2 SCAR=6.9
Pod
undocumented
| |||
| 827 | 1 | my @hand_rolled = qw( Value ); | |
| 828 | |||
| 829 | 1 | my $xs_code = <<'END_XS_CODE'; | |
| 830 | MODULE = Lucy PACKAGE = Lucy::Index::SortCache | ||
| 831 | |||
| 832 | SV* | ||
| 833 | value(self, ...) | ||
| 834 | lucy_SortCache *self; | ||
| 835 | CODE: | ||
| 836 | { | ||
| 837 | static const XSBind_ParamSpec param_specs[1] = { | ||
| 838 | XSBIND_PARAM("ord", false) | ||
| 839 | }; | ||
| 840 | int32_t locations[1]; | ||
| 841 | int32_t ord = 0; | ||
| 842 | |||
| 843 | XSBind_locate_args(aTHX_ &ST(0), 1, items, param_specs, locations, 1); | ||
| 844 | |||
| 845 | ord = locations[0] < items ? (int32_t)SvIV(ST(locations[0])) : 0; | ||
| 846 | |||
| 847 | { | ||
| 848 | cfish_Obj *value = LUCY_SortCache_Value(self, ord); | ||
| 849 | RETVAL = XSBind_cfish_to_perl(aTHX_ value); | ||
| 850 | CFISH_DECREF(value); | ||
| 851 | } | ||
| 852 | } | ||
| 853 | OUTPUT: RETVAL | ||
| 854 | END_XS_CODE | ||
| 855 | |||
| 856 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 857 | parcel => "Lucy", | ||
| 858 | class_name => "Lucy::Index::SortCache", | ||
| 859 | ); | ||
| 860 | 1 | $binding->exclude_method($_) for @hand_rolled; | |
| 861 | 1 | $binding->append_xs($xs_code); | |
| 862 | |||
| 863 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 864 | } | ||
| 865 | |||
| 866 | 1 | ▶ | sub bind_sortwriter { |
|
Subroutine
bind_sortwriter: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 867 | 1 | my $xs_code = <<'END_XS'; | |
| 868 | MODULE = Lucy PACKAGE = Lucy::Index::SortWriter | ||
| 869 | |||
| 870 | void | ||
| 871 | set_default_mem_thresh(mem_thresh) | ||
| 872 | size_t mem_thresh; | ||
| 873 | PPCODE: | ||
| 874 | lucy_SortWriter_set_default_mem_thresh(mem_thresh); | ||
| 875 | END_XS | ||
| 876 | |||
| 877 | 1 | my $binding = Clownfish::CFC::Binding::Perl::Class->new( | |
| 878 | parcel => "Lucy", | ||
| 879 | class_name => "Lucy::Index::SortWriter", | ||
| 880 | ); | ||
| 881 | 1 | $binding->append_xs($xs_code); | |
| 882 | |||
| 883 | 1 | Clownfish::CFC::Binding::Perl::Class->register($binding); | |
| 884 | } | ||
| 885 | |||
| 886 | 1 | 1; | |