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/06/22 08:21:44 UTC

svn commit: r956783 - in /lucene/lucy/trunk: core/Lucy/Search/NOTScorer.bp core/Lucy/Search/NOTScorer.c perl/lib/Lucy/Search/NOTScorer.pm

Author: marvin
Date: Tue Jun 22 06:21:44 2010
New Revision: 956783

URL: http://svn.apache.org/viewvc?rev=956783&view=rev
Log:
LUCY-117:
Add NOTScorer.
(not_scorer.patch)

Added:
    lucene/lucy/trunk/core/Lucy/Search/NOTScorer.bp   (with props)
    lucene/lucy/trunk/core/Lucy/Search/NOTScorer.c   (with props)
    lucene/lucy/trunk/perl/lib/Lucy/Search/NOTScorer.pm   (with props)

Added: lucene/lucy/trunk/core/Lucy/Search/NOTScorer.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Search/NOTScorer.bp?rev=956783&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Search/NOTScorer.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Search/NOTScorer.bp Tue Jun 22 06:21:44 2010
@@ -0,0 +1,49 @@
+parcel Lucy;
+
+/** Return the inverse of a Matcher's set.  Scores are always 0.
+ */
+
+class Lucy::Search::NOTScorer extends Lucy::Search::PolyMatcher {
+
+    Matcher       *negated_matcher; 
+    int32_t        doc_id;
+    int32_t        doc_max;
+    int32_t        next_negation;
+
+    inert incremented NOTScorer* 
+    new(Matcher* negated_matcher, int32_t doc_max);
+
+    inert NOTScorer* 
+    init(NOTScorer *self, Matcher *negated_matcher, int32_t doc_max);
+
+    public void
+    Destroy(NOTScorer *self);
+
+    public int32_t
+    Next(NOTScorer *self);
+
+    public int32_t
+    Advance(NOTScorer *self, int32_t target);
+
+    public float
+    Score(NOTScorer *self);
+
+    public int32_t 
+    Get_Doc_ID(NOTScorer *self);
+}
+
+/* Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/core/Lucy/Search/NOTScorer.bp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/lucy/trunk/core/Lucy/Search/NOTScorer.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Search/NOTScorer.c?rev=956783&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Search/NOTScorer.c (added)
+++ lucene/lucy/trunk/core/Lucy/Search/NOTScorer.c Tue Jun 22 06:21:44 2010
@@ -0,0 +1,104 @@
+#define C_LUCY_NOTSCORER
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Search/NOTScorer.h"
+#include "Lucy/Index/Similarity.h"
+#include "Lucy/Plan/Schema.h"
+
+NOTScorer*
+NOTScorer_new(Matcher *negated_matcher, int32_t doc_max) 
+{
+    NOTScorer *self = (NOTScorer*)VTable_Make_Obj(NOTSCORER);
+    return NOTScorer_init(self, negated_matcher, doc_max);
+}
+
+NOTScorer*
+NOTScorer_init(NOTScorer *self, Matcher *negated_matcher, int32_t doc_max)
+{
+    VArray *children = VA_new(1);
+    VA_Push(children, INCREF(negated_matcher));
+    PolyMatcher_init((PolyMatcher*)self, children, NULL);
+
+    // Init. 
+    self->doc_id           = 0;
+    self->next_negation    = 0;
+
+    // Assign. 
+    self->negated_matcher   = (Matcher*)INCREF(negated_matcher);
+    self->doc_max          = doc_max;
+
+    DECREF(children);
+
+    return self;
+}
+
+void
+NOTScorer_destroy(NOTScorer *self) 
+{
+    DECREF(self->negated_matcher);
+    SUPER_DESTROY(self, NOTSCORER);
+}
+
+int32_t
+NOTScorer_next(NOTScorer *self)
+{
+    while (1) {
+        self->doc_id++;
+
+        // Get next negated doc id. 
+        if (self->next_negation < self->doc_id) {
+            self->next_negation 
+                = Matcher_Advance(self->negated_matcher, self->doc_id);
+            if (self->next_negation == 0) {
+                DECREF(self->negated_matcher);
+                self->negated_matcher = NULL;
+                self->next_negation = self->doc_max + 1;
+            }
+        }
+
+        if (self->doc_id > self->doc_max) {
+            self->doc_id = self->doc_max; // halt advance 
+            return 0;
+        }
+        else if (self->doc_id != self->next_negation) {
+            // Success! 
+            return self->doc_id;
+        }
+    }
+}
+
+int32_t
+NOTScorer_advance(NOTScorer *self, int32_t target)
+{
+    self->doc_id = target - 1;
+    return NOTScorer_next(self);
+}
+
+int32_t
+NOTScorer_get_doc_id(NOTScorer *self)
+{
+    return self->doc_id;
+}
+
+float
+NOTScorer_score(NOTScorer *self)
+{
+    UNUSED_VAR(self);
+    return 0.0f;
+}
+
+/* Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/core/Lucy/Search/NOTScorer.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/lucy/trunk/perl/lib/Lucy/Search/NOTScorer.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/lib/Lucy/Search/NOTScorer.pm?rev=956783&view=auto
==============================================================================
--- lucene/lucy/trunk/perl/lib/Lucy/Search/NOTScorer.pm (added)
+++ lucene/lucy/trunk/perl/lib/Lucy/Search/NOTScorer.pm Tue Jun 22 06:21:44 2010
@@ -0,0 +1,33 @@
+package Lucy::Search::NOTScorer;
+use Lucy;
+
+1;
+
+__END__
+
+__BINDING__
+
+Clownfish::Binding::Perl::Class->register(
+    parcel            => "Lucy",
+    class_name        => "Lucy::Search::NOTScorer",
+    bind_constructors => ["new"],
+);
+
+__COPYRIGHT__
+
+    /**
+     * Copyright 2010 The Apache Software Foundation
+     *
+     * Licensed under the Apache License, Version 2.0 (the "License");
+     * you may not use this file except in compliance with the License.
+     * You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+     * implied.  See the License for the specific language governing
+     * permissions and limitations under the License.
+     */
+

Propchange: lucene/lucy/trunk/perl/lib/Lucy/Search/NOTScorer.pm
------------------------------------------------------------------------------
    svn:eol-style = native