Bug 9407: patrons search should match substrings

If a patron lives at 4345 Library Rd, a search on Street Address for
    Library should find it. However, it does not, but a search for 4345
    Library does.  This patch adds a "Search Type" drop-down, defaulting
    to the current behaviour.

    To test:
    1) Search for a patron based on a non-leading part of a field.
    2) Should return no results.
    3) Search again with "Search Type" of "Contains".
    4) Should return the patron.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
This commit is contained in:
MJ Ray 2013-01-16 20:13:57 +00:00 committed by Chris Cormack
parent a28436da47
commit eff7ba7d4f
2 changed files with 13 additions and 1 deletions

View File

@ -62,6 +62,12 @@ YAHOO.util.Event.onContentReady("header_search", function() {
<option value='phone,phonepro,B_phone,altcontactphone,mobile'>Phone number</option>
</select>
<label for="searchtype">Search type:</label>
<select name="searchtype" id="searchtype">
<option selected="selected" value=''>Starts with</option>
<option value='contain'>Contains</option>
</select>
<label for="orderby">Order by:</label>
<select name="orderby" id="searchorderby">
<option value="surname,0">Surname</option>

View File

@ -101,13 +101,19 @@ my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname",
$member =~ s/,//g; #remove any commas from search string
$member =~ s/\*/%/g;
my $searchtype = $input->param('searchtype');
my %searchtype_ok = ( 'contain' => 1 );
if ( !defined($searchtype_ok{$searchtype}) ) {
undef $searchtype;
}
my $from = ( $startfrom - 1 ) * $resultsperpage;
my $to = $from + $resultsperpage;
my ($count,$results);
if ($member || keys %$patron) {
#($results)=Search($member || $patron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] );
my $search_scope = ( $quicksearch ? "field_start_with" : "start_with" );
my $search_scope = $searchtype || ( $quicksearch ? "field_start_with" : "start_with" );
($results) = Search( $member || $patron, \@orderby, undef, undef, \@searchfields, $search_scope );
}