----- Original Message -----
From: "Kate L Pugh" <kake(a)earth.li>
To: "Discussion of development on the OpenGuides software."
<openguides-dev(a)openguides.org>
Sent: 09 October 2003 20:25
Subject: Re: [OpenGuides-Dev] Search and search syntax
On Thu 09 Oct 2003, Earle Martin
<openguides(a)downlode.org> wrote:
My preferred approach is "one box" as
well, but to *also* to have an
"advanced search" page, much like this one:
http://www.google.com/advanced_search?hl=en
I'm just reluctant to expend effort on creating a more advanced search
thing when (a) nobody's expressed a real need for it, and (b) the
simple search we have still needs work.
Fine, I agree that the search needs work, but first I think we need to agree what
direction we are working towards.
What I had in mind was a common search cgi script, which could be passed a
single text string, or could be passed a form with multiple fields in it,
corresponding to the "advanced" search. Either way, it's the same cgi
script being invoked.
Kake wrote:
> Regarding search more generally, I think that
words typed into the
> search box should default to an "AND" search, which I don't believe
> they do at the moment.
Earle wrote:
No, they don't, which is definitely not
right. This should return the
Windsor Castle as the first hit:
http://openguides.org/london/supersearch.cgi?search=sausages+oysters
I've had a bash about at it, but I'm hampered by not having learnt
Parse::RecDescent yet. From my reading of the code, I'd have thought
that searches should default to OR, but they're not, so I'm clearly
misunderstanding the code.
In fact, it's not AND or OR by default, but a phrase search. In this case
looking for "sausages oysters", which doesn't make much sense.
Ivor: Could you take the time to comment the
RecDescent grammar in
OpenGuides::SuperSearch, so I have something to go on? If you won't
find time to do it soon then we may have to put RecDescent aside for
now and use something simpler.
I'm wondering what level of commenting you need, as I didn't think that
the grammar was _that_ difficult to understand - apologies.
Anyway, here is an alternative grammar which is a drop-in replacement,
which does a google style AND by default, and gives you AND if
you separate the words with commas. Phrase search is still available, by
passing a string bounded by "". Note that this has two new treenode types
of "meta" and "regexp", but these are commented out, as there is no
code
to handle these node types.
my $parse = Parse::RecDescent->new(q{
search: list eostring {$return = $item[1]} #A search is a list followed by an
eostring
list: comby(s) #A list is a list of one or more combys
{$return = (@{$item[1]}>1) ? ['AND', @{$item[1]}] : $item[1][0]}
comby: <leftop: term ',' term> #A comby is a list of terms
separated by commas
{$return = (@{$item[1]}>1) ? ['OR', @{$item[1]}] : $item[1][0]}
# A term can be one of a number of things
term: '(' list ')' {$return = $item[2]} #A subexpression in
parentheses
| '!' term {$return = ['NOT', @{$item[2]}]} #A
'!' (NOT) expression
# | word ':' term {$return = ['meta', $item[1], $item[3]];} #A
metadata lookup
| '"' word(s) '"' {$return = ['word',
@{$item[2]}]} #A phrase in ""
| word {$return = ['word', $item[1]]} # A word
# | m([/|\\]) m([^$item[1]]+) $item[1] # A regexp bounded by '/'
'|' or '\'
# { $return = ['regexp', qr($item[2])] }
word: /[\w'*%]+/ {$return = $item[1]} #A word can contain wildcards * and %
also '
eostring: /^\Z/
});
Hope this helps,
Ivor.