Fails: CQL: dc:title any "dogs cats"
Succeeds: Swish: dc:title = (dogs or cats)
Could we change the toSwish() method in TermNode.pm (around line
105) to
[if $relation is "any"]
$term =~ s/\s/ and /g;
$swish = join( ' ', $qualifier, '=', '(', $term, ')' );
similarly
Fails: CQL: dc:title all "dogs cats"
Succeeds: Swish: dc:title = (dogs and cats)
so:
[$relation is "all"]
$term =~ s/\s/ and /g;
$swish = join( ' ', $qualifier, '=', '(', $term, ')' );
I'm still not an expert in this regard, but I do know that things
like the query "dogs cats" (without the quote marks) is an invalid
CQL query because I think CQL is expecting phrase searches or truples
(dogs or cats). In the query "dogs cats" (without the quote marks)
dogs is considered a field, cats is considered an operator, and there
is no value field.
Furthermore, CQL is not expecting every indexer (swish-e, Plucene,
Lucene, etc.) to support every syntax. You are expected to trap for
valid CQL syntax but syntax not supported by your indexer and return
an error accordingly. In order to avoid this problem, you are
expected to "explain" the situation in your explain response.
This being the case, I have tried to munge incoming queries to be CQL-
like before I send them off to the SRU server. This is what I do for
SRU interfaces to swish-based indexes:
# do simple munging of the query; try to force it into CQL
if ($query =~ /\s/) {
if (($query =~ / and /) |
($query =~ / or /) |
($query =~ / not /)) { }
elsif ($query =~ /=/) { }
elsif ($query !~ /"/) {
# try to make queries with no syntactical sugar a bit "smarter"
my @terms = split / /, $query;
my $enhancement;
for (my $i; $i <= $#terms; $i++) {
if ($i < $#terms) { $enhancement .= $terms[$i] . ' and ' }
else { $enhancement .= $terms[$i] }
}
$query = '"' . $query . '"' . " or ($enhancement)";
}
}
This transforms queries like this:
* dogs cats => "dogs cats" or (dogs and cats)
* "dogs cats" => "dogs cats"
* dogs => dogs
* dogs and cats => dogs and cats
I sincerely don't know if it were better to "fix" this problem in a
person's client or in the SRU module.
On the other hand, for most of the CQL query types I get the line:
croak( "Swish does not support relational modifiers" )
This handling of errors, through the use of croak, also needs to be
trapped in your code because if you don't, then non-XML gets returned
to the client, and that is no-no #1. It has been suggested to me you
trap for this error something like this:
eval { $cql->to_swish(); };
if ($@) { # do something about the error }
--
Eric Lease Morgan