You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2010/12/29 22:18:06 UTC
[lucy-commits] svn commit: r1053737 - in /incubator/lucy/trunk:
core/Lucy/Search/NoMatchQuery.c core/Lucy/Search/NoMatchQuery.cfh
core/Lucy/Search/QueryParser.c perl/t/601-queryparser.t
Author: marvin
Date: Wed Dec 29 21:18:04 2010
New Revision: 1053737
URL: http://svn.apache.org/viewvc?rev=1053737&view=rev
Log:
Prevent stop words from blocking a complete query, so that for example a
search for 'the smiths' returns the results for 'smiths' rather than nothing.
Modified:
incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.c
incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.cfh
incubator/lucy/trunk/core/Lucy/Search/QueryParser.c
incubator/lucy/trunk/perl/t/601-queryparser.t
Modified: incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.c?rev=1053737&r1=1053736&r2=1053737&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.c (original)
+++ incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.c Wed Dec 29 21:18:04 2010
@@ -37,7 +37,9 @@ NoMatchQuery_new()
NoMatchQuery*
NoMatchQuery_init(NoMatchQuery *self)
{
- return (NoMatchQuery*)Query_init((Query*)self, 0.0f);
+ Query_init((Query*)self, 0.0f);
+ self->fails_to_match = true;
+ return self;
}
bool_t
@@ -46,6 +48,7 @@ NoMatchQuery_equals(NoMatchQuery *self,
NoMatchQuery *evil_twin = (NoMatchQuery*)other;
if (!Obj_Is_A(other, NOMATCHQUERY)) return false;
if (self->boost != evil_twin->boost) return false;
+ if (!!self->fails_to_match != !!evil_twin->fails_to_match) return false;
return true;
}
@@ -63,6 +66,56 @@ NoMatchQuery_make_compiler(NoMatchQuery
return (Compiler*)NoMatchCompiler_new(self, searcher, boost);
}
+void
+NoMatchQuery_set_fails_to_match(NoMatchQuery *self, bool_t fails_to_match)
+ { self->fails_to_match = fails_to_match; }
+bool_t
+NoMatchQuery_get_fails_to_match(NoMatchQuery *self)
+ { return self->fails_to_match; }
+
+Obj*
+NoMatchQuery_dump(NoMatchQuery *self)
+{
+ NoMatchQuery_dump_t super_dump
+ = (NoMatchQuery_dump_t)SUPER_METHOD(NOMATCHQUERY, NoMatchQuery, Dump);
+ Hash *dump = (Hash*)CERTIFY(super_dump(self), HASH);
+ Hash_Store_Str(dump, "fails_to_match", 14, (Obj*)CB_newf("%i64",
+ (int64_t)self->fails_to_match));
+ return (Obj*)dump;
+}
+
+NoMatchQuery*
+NoMatchQuery_load(NoMatchQuery *self, Obj *dump)
+{
+ Hash *source = (Hash*)CERTIFY(dump, HASH);
+ NoMatchQuery_load_t super_load
+ = (NoMatchQuery_load_t)SUPER_METHOD(NOMATCHQUERY, NoMatchQuery, Load);
+ NoMatchQuery *loaded = super_load(self, dump);
+ Obj *fails = Cfish_Hash_Fetch_Str(source, "fails_to_match", 14);
+ if (fails) {
+ loaded->fails_to_match = (bool_t)!!Obj_To_I64(fails);
+ }
+ else {
+ loaded->fails_to_match = true;
+ }
+ return loaded;
+}
+
+void
+NoMatchQuery_serialize(NoMatchQuery *self, OutStream *outstream)
+{
+ OutStream_Write_I8(outstream, !!self->fails_to_match);
+}
+
+NoMatchQuery*
+NoMatchQuery_deserialize(NoMatchQuery *self, InStream *instream)
+{
+ self = self ? self : (NoMatchQuery*)VTable_Make_Obj(NOMATCHQUERY);
+ NoMatchQuery_init(self);
+ self->fails_to_match = !!InStream_Read_I8(instream);
+ return self;
+}
+
/**********************************************************************/
NoMatchCompiler*
Modified: incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.cfh?rev=1053737&r1=1053736&r2=1053737&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.cfh Wed Dec 29 21:18:04 2010
@@ -26,6 +26,8 @@ parcel Lucy;
class Lucy::Search::NoMatchQuery inherits Lucy::Search::Query
: dumpable {
+ bool_t fails_to_match;
+
inert incremented NoMatchQuery*
new();
@@ -34,6 +36,24 @@ class Lucy::Search::NoMatchQuery inherit
public inert NoMatchQuery*
init(NoMatchQuery *self);
+ void
+ Set_Fails_To_Match(NoMatchQuery *self, bool_t fails_to_match);
+
+ bool_t
+ Get_Fails_To_Match(NoMatchQuery *self);
+
+ public incremented Obj*
+ Dump(NoMatchQuery *self);
+
+ public incremented NoMatchQuery*
+ Load(NoMatchQuery *self, Obj *dump);
+
+ public void
+ Serialize(NoMatchQuery *self, OutStream *outstream);
+
+ public incremented NoMatchQuery*
+ Deserialize(NoMatchQuery *self, InStream *instream);
+
public bool_t
Equals(NoMatchQuery *self, Obj *other);
Modified: incubator/lucy/trunk/core/Lucy/Search/QueryParser.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Search/QueryParser.c?rev=1053737&r1=1053736&r2=1053737&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Search/QueryParser.c (original)
+++ incubator/lucy/trunk/core/Lucy/Search/QueryParser.c Wed Dec 29 21:18:04 2010
@@ -812,7 +812,18 @@ QParser_expand(QueryParser *self, Query
for (uint32_t i = 0, max = VA_Get_Size(children); i < max; i++) {
Query *child = (Query*)VA_Fetch(children, i);
Query *new_child = QParser_Expand(self, child); // recurse
- if (new_child) VA_Push(new_kids, (Obj*)new_child);
+ if (new_child) {
+ if (Query_Is_A(new_child, NOMATCHQUERY)) {
+ bool_t fails = NoMatchQuery_Get_Fails_To_Match(
+ (NoMatchQuery*)new_child);
+ if (fails) {
+ VA_Push(new_kids, (Obj*)new_child);
+ }
+ }
+ else {
+ VA_Push(new_kids, (Obj*)new_child);
+ }
+ }
}
if (VA_Get_Size(new_kids) == 0) {
@@ -907,6 +918,7 @@ QParser_expand_leaf(QueryParser *self, Q
Schema *schema = self->schema;
ZombieCharBuf *source_text = ZCB_BLANK();
bool_t is_phrase = false;
+ bool_t ambiguous = false;
// Determine whether we can actually process the input.
if (!Query_Is_A(query, LEAFQUERY)) return NULL;
@@ -964,6 +976,11 @@ QParser_expand_leaf(QueryParser *self, Q
}
}
+ if (VA_Get_Size(token_texts) == 0) {
+ /* Query might include stop words. Who knows? */
+ ambiguous = true;
+ }
+
// Add either a TermQuery or a PhraseQuery.
if (is_phrase || VA_Get_Size(token_texts) > 1) {
VA_Push(queries, (Obj*)
@@ -982,6 +999,9 @@ QParser_expand_leaf(QueryParser *self, Q
Query *retval;
if (VA_Get_Size(queries) == 0) {
retval = (Query*)NoMatchQuery_new();
+ if (ambiguous) {
+ NoMatchQuery_Set_Fails_To_Match((NoMatchQuery*)retval, false);
+ }
}
else if (VA_Get_Size(queries) == 1) {
retval = (Query*)INCREF(VA_Fetch(queries, 0));
Modified: incubator/lucy/trunk/perl/t/601-queryparser.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/t/601-queryparser.t?rev=1053737&r1=1053736&r2=1053737&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/t/601-queryparser.t (original)
+++ incubator/lucy/trunk/perl/t/601-queryparser.t Wed Dec 29 21:18:04 2010
@@ -154,28 +154,28 @@ my @logical_tests = (
'-x' => [ 0, 0, 0, 0, ],
'x -c' => [ 3, 3, 0, 0, ],
'x "-c"' => [ 5, 0, 0, 0, ],
- 'x +c' => [ 2, 2, 2, 0, ],
+ 'x +c' => [ 2, 2, 2, 2, ],
'x "+c"' => [ 5, 0, 0, 0, ],
- '+x +c' => [ 2, 2, 0, 0, ],
+ '+x +c' => [ 2, 2, 2, 2, ],
'+x -c' => [ 3, 3, 0, 0, ],
'-x +c' => [ 0, 0, 2, 2, ],
'-x -c' => [ 0, 0, 0, 0, ],
- 'x y' => [ 6, 0, 1, 0, ],
- 'x a d' => [ 5, 1, 4, 0, ],
+ 'x y' => [ 6, 0, 1, 1, ],
+ 'x a d' => [ 5, 1, 4, 1, ],
'x "a d"' => [ 5, 0, 0, 0, ],
'"x a"' => [ 3, 3, 4, 4, ],
- 'x AND y' => [ 0, 0, 0, 0, ],
+ 'x AND y' => [ 0, 0, 1, 1, ],
'x OR y' => [ 6, 6, 1, 1, ],
'x AND NOT y' => [ 5, 5, 0, 0, ],
- 'x (b OR c)' => [ 5, 3, 3, 0, ],
- 'x AND (b OR c)' => [ 3, 3, 0, 0, ],
+ 'x (b OR c)' => [ 5, 3, 3, 3, ],
+ 'x AND (b OR c)' => [ 3, 3, 3, 3, ],
'x OR (b OR c)' => [ 5, 5, 3, 3, ],
- 'x (y OR c)' => [ 6, 2, 3, 0, ],
- 'x AND (y OR c)' => [ 2, 2, 0, 0, ],
+ 'x (y OR c)' => [ 6, 2, 3, 3, ],
+ 'x AND (y OR c)' => [ 2, 2, 3, 3, ],
'a AND NOT (b OR "c d")' => [ 1, 1, 1, 1, ],
'a AND NOT "a b"' => [ 1, 1, 1, 1, ],