#use OpenILS::Application::Search::StaffClient;
-use OpenILS::Application::Search::Web;
use OpenILS::Application::Search::Biblio;
use OpenILS::Application::Search::Actor;
use OpenILS::Application::Search::Z3950;
OpenILS::Application::SearchCache->child_init();
}
+# returns -1 when we hit a dumb search
sub filter_search {
- my($self, $string) = @_;
-
- $string =~ s/\s+the\s+/ /i;
- $string =~ s/\s+an\s+/ /i;
- $string =~ s/\s+a\s+/ /i;
-
- $string =~ s/^the\s+//i;
- $string =~ s/^an\s+//i;
- $string =~ s/^a\s+//i;
-
- $string =~ s/\s+the$//i;
- $string =~ s/\s+an$//i;
- $string =~ s/\s+a$//i;
-
- $string =~ s/^the$//i;
- $string =~ s/^an$//i;
- $string =~ s/^a$//i;
+ my($self, $string, $full) = @_;
+
+ $string =~ s/\s+the\s+/ /oi;
+ $string =~ s/\s+an\s+/ /oi;
+ $string =~ s/\s+a\s+/ /oi;
+
+ $string =~ s/^the\s+//io;
+ $string =~ s/^an\s+//io;
+ $string =~ s/^a\s+//io;
+
+ $string =~ s/\s+the$//io;
+ $string =~ s/\s+an$//io;
+ $string =~ s/\s+a$//io;
+
+ $string =~ s/^the$//io;
+ $string =~ s/^an$//io;
+ $string =~ s/^a$//io;
+
+ if(!$full) { return $string; }
+
+ my @words = qw/
+ fiction
+ bibliograph
+ juvenil
+ histor
+ literatur
+ biograph
+ stor
+ american
+ videorecord
+ count
+ film
+ life
+ book
+ children
+ centur
+ war
+ genealog
+ etc
+ state
+ unit
+ /;
+
+ push @words, "united state";
+
+ for my $word (@words) {
+ if($string =~ /^\s*"?\s*$word\w*\s*"?\s*$/i) {
+ return "";
+ }
+ }
warn "Cleansed string to: $string\n";
return $string;
use base qw/OpenSRF::Application/;
use strict; use warnings;
+use OpenILS::EX;
+
use JSON;
use OpenILS::Utils::Fieldmapper;
use OpenILS::Utils::ModsParser;
# --------------------------------------------------------------------------------
+
+
__PACKAGE__->register_method(
method => "cat_biblio_search_class",
api_name => "open-ils.search.cat.biblio.class",
- argc => 3,
- note => "Searches biblio information by search class",
);
+
sub cat_biblio_search_class {
my( $self, $client, $org_id, $class, $sort, $string ) = @_;
$limit -= 1;
- $string = OpenILS::Application::Search->filter_search($string);
- if(!$string) { return undef; }
+ my $bool = ($class eq "subject" || $class eq "keyword");
+ $string = OpenILS::Application::Search->filter_search($string, $bool);
+
+ if(!$string) {
+ return OpenILS::EX->new("SEARCH_TOO_LARGE")->ex();
+ }
warn "Searching cat.biblio.class.id string: $string offset: $offset limit: $limit\n";
}
+__PACKAGE__->register_method(
+ method => "biblio_search_class_count",
+ api_name => "open-ils.search.biblio.class.count",
+ argc => 3,
+ note => "Searches biblio information by search class and returns the IDs",
+);
+sub biblio_search_class_count {
+
+ my( $self, $client, $class, $string, $org_id, $org_type ) = @_;
+
+ warn "org: $org_id : depth: $org_type\n";
+
+ $org_id = "1" unless defined($org_id); # xxx
+ $org_type = 0 unless defined($org_type);
+
+ warn "Searching biblio.class.id\n" .
+ "string: $string " .
+ "org_id: $org_id\n" .
+ "depth: $org_type\n" ;
+
+ my $bool = ($class eq "subject" || $class eq "keyword");
+ $string = OpenILS::Application::Search->filter_search($string, $bool);
+
+ if(!$string) {
+ return OpenILS::EX->new("SEARCH_TOO_LARGE")->ex;
+ }
+
+
+ if( !defined($org_id) or !$class or !$string ) {
+ warn "not enbough args to metarecord search\n";
+ throw OpenSRF::EX::InvalidArg
+ ("Not enough args to open-ils.search.cat.biblio.class")
+ }
+
+ $class =~ s/\s+//g;
+
+ if( ($class ne "title") and ($class ne "author") and
+ ($class ne "subject") and ($class ne "keyword") ) {
+ warn "Invalid search class: $class\n";
+ throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
+ }
+
+ # grab the mr id's from storage
+
+ my $method = "open-ils.storage.metabib.$class.search_fts.metarecord_count";
+ warn "Performing count method $method\n";
+ my $session = OpenSRF::AppSession->create('open-ils.storage');
+
+ my $request = $session->request( $method,
+ term => $string,
+ org_unit => $org_id,
+ depth =>$org_type );
+
+ my $count = $request->gather(1);
+ warn "Received count $count\n";
+
+ return $count;
+}
+
__PACKAGE__->register_method(
method => "biblio_search_class",
api_name => "open-ils.search.biblio.class",
- argc => 3,
- note => "Searches biblio information by search class and returns the IDs",
+);
+
+__PACKAGE__->register_method(
+ method => "biblio_search_class",
+ api_name => "open-ils.search.biblio.class.unordered",
);
sub biblio_search_class {
"org_id: $org_id\n" .
"depth: $org_type\n" ;
+ warn "Search filtering string " . time() . "\n";
$string = OpenILS::Application::Search->filter_search($string);
if(!$string) { return undef; }
throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
}
- # grab the mr id's from storage
+ my $method = "open-ils.storage.metabib.$class.search_fts.metarecord.atomic";
- my $method = "open-ils.storage.metabib.$class.search_fts.metarecord_count";
- warn "Performing count method $method\n";
- my $session = OpenSRF::AppSession->create('open-ils.storage');
+ if($self->api_name =~ /order/) {
+ $method = "open-ils.storage.metabib.$class.search_fts.metarecord.unordered.atomic";
+ }
- my $request = $session->request( $method,
- term => $string,
- org_unit => $org_id,
- depth =>$org_type );
+ warn "MR search method is $method\n";
- my $count = $request->gather(1);
- warn "Received count $count\n";
- # XXX check count size and respond accordingly
+ my $session = OpenSRF::AppSession->create('open-ils.storage');
- $request = $session->request(
- "open-ils.storage.metabib.$class.search_fts.metarecord.atomic",
+ warn "Search making request " . time() . "\n";
+ my $request = $session->request(
#"open-ils.storage.cachable.metabib.$class.search_fts.metarecord.atomic",
+ $method,
term => $string,
org_unit => $org_id,
depth => $org_type,
);
my $records = $request->gather(1);
+ warn "Search request complete " . time() . "\n";
+
my @all_ids;
use Data::Dumper;
- warn "Received from class search " . Dumper($records);
+ warn "Received " . scalar(@$records) . " id's from class search\n";
# if we just get one, it won't be wrapped in an array
if(!ref($records->[0])) {
- $records = [$records];
- }
-
+ $records = [$records]; }
for my $i (@$records) {
if(defined($i)) {
push @all_ids, $i;
}
}
- #my @ids = @all_ids[ $offset..($offset+$limit) ];
my @ids = @all_ids;
@ids = grep { defined($_->[0]) } @ids;
$session->finish();
$session->disconnect();
- return { count =>$count, ids => \@ids };
+ return { ids => \@ids };
}