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/18 03:16:28 UTC
svn commit: r955810 - in /lucene/lucy/trunk: core/Lucy/Search/Matcher.bp
core/Lucy/Search/Matcher.c perl/lib/Lucy/Search/Matcher.pm
Author: marvin
Date: Fri Jun 18 01:16:28 2010
New Revision: 955810
URL: http://svn.apache.org/viewvc?rev=955810&view=rev
Log:
LUCY-111:
Add Lucy::Search::Matcher.
Added:
lucene/lucy/trunk/core/Lucy/Search/Matcher.bp (with props)
lucene/lucy/trunk/core/Lucy/Search/Matcher.c (with props)
lucene/lucy/trunk/perl/lib/Lucy/Search/Matcher.pm (with props)
Added: lucene/lucy/trunk/core/Lucy/Search/Matcher.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Search/Matcher.bp?rev=955810&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Search/Matcher.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Search/Matcher.bp Fri Jun 18 01:16:28 2010
@@ -0,0 +1,84 @@
+parcel Lucy;
+
+/** Match a set of document ids.
+ *
+ * A Matcher iterates over an ascending set of document ids. Some Matchers
+ * implement Score() and can assign relevance scores to the docs that they
+ * match. Other implementations may be match-only.
+ */
+
+abstract class Lucy::Search::Matcher extends Lucy::Object::Obj {
+
+ /** Abstract constructor.
+ */
+ public inert Matcher*
+ init(Matcher* self);
+
+ /** Proceed to the next doc id.
+ *
+ * @return A positive doc id, or 0 once the iterator is exhausted.
+ */
+ public abstract int32_t
+ Next(Matcher *self);
+
+ /** Advance the iterator to the first doc id greater than or equal to
+ * <code>target</code>. The default implementation simply calls Next()
+ * over and over, but subclasses have the option of doing something more
+ * efficient.
+ *
+ * @param target A positive doc id, which must be greater than the current
+ * doc id once the iterator has been initialized.
+ * @return A positive doc id, or 0 once the iterator is exhausted.
+ */
+ public int32_t
+ Advance(Matcher *self, int32_t target);
+
+ /** Return the current doc id. Valid only after a successful call to
+ * Next() or Advance() and must not be called otherwise.
+ */
+ public abstract int32_t
+ Get_Doc_ID(Matcher *self);
+
+ /** Return the score of the current document.
+ *
+ * Only Matchers which are used for scored search need implement Score().
+ */
+ public abstract float
+ Score(Matcher *self);
+
+ /** Collect hits.
+ *
+ * @param collector The Collector to collect hits with.
+ * @param deletions A deletions iterator.
+ */
+ void
+ Collect(Matcher *self, Collector *collector,
+ Matcher *deletions = NULL);
+}
+
+/** Placeholder stub.
+ */
+class Lucy::Search::Collector cnick Coll extends Lucy::Object::Obj {
+
+ abstract void
+ Set_Matcher(Collector *self, Matcher *match);
+
+ abstract void
+ Collect(Collector *self, int32_t doc_id);
+}
+
+/* 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/Matcher.bp
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/core/Lucy/Search/Matcher.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Search/Matcher.c?rev=955810&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Search/Matcher.c (added)
+++ lucene/lucy/trunk/core/Lucy/Search/Matcher.c Fri Jun 18 01:16:28 2010
@@ -0,0 +1,90 @@
+#define C_LUCY_MATCHER
+#define LUCY_USE_SHORT_NAMES
+#define CHY_USE_SHORT_NAMES
+
+#include "Lucy/Search/Matcher.h"
+#include "Lucy/Object/Err.h"
+#include "Lucy/Object/VTable.h"
+
+Matcher*
+Matcher_init(Matcher *self)
+{
+ ABSTRACT_CLASS_CHECK(self, MATCHER);
+ return self;
+}
+
+int32_t
+Matcher_advance(Matcher *self, int32_t target)
+{
+ while (1) {
+ int32_t doc_id = Matcher_Next(self);
+ if (doc_id == 0 || doc_id >= target)
+ return doc_id;
+ }
+}
+
+void
+Matcher_collect(Matcher *self, Collector *collector, Matcher *deletions)
+{
+ int32_t doc_id = 0;
+ int32_t next_deletion = deletions ? 0 : I32_MAX;
+
+ Coll_Set_Matcher(collector, self);
+
+ // Execute scoring loop.
+ while (1) {
+ if (doc_id > next_deletion) {
+ next_deletion = Matcher_Advance(deletions, doc_id);
+ if (next_deletion == 0) { next_deletion = I32_MAX; }
+ continue;
+ }
+ else if (doc_id == next_deletion) {
+ // Skip past deletions.
+ while (doc_id == next_deletion) {
+ // Artifically advance matcher.
+ while (doc_id == next_deletion) {
+ doc_id++;
+ next_deletion = Matcher_Advance(deletions, doc_id);
+ if (next_deletion == 0) { next_deletion = I32_MAX; }
+ }
+ // Verify that the artificial advance actually worked.
+ doc_id = Matcher_Advance(self, doc_id);
+ if (doc_id > next_deletion) {
+ next_deletion = Matcher_Advance(deletions, doc_id);
+ }
+ }
+ }
+ else {
+ doc_id = Matcher_Advance(self, doc_id + 1);
+ if (doc_id >= next_deletion) {
+ next_deletion = Matcher_Advance(deletions, doc_id);
+ if (doc_id == next_deletion) { continue; }
+ }
+ }
+
+ if (doc_id) {
+ Coll_Collect(collector, doc_id);
+ }
+ else {
+ break;
+ }
+ }
+
+ Coll_Set_Matcher(collector, NULL);
+}
+
+/* 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/Matcher.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/perl/lib/Lucy/Search/Matcher.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/lib/Lucy/Search/Matcher.pm?rev=955810&view=auto
==============================================================================
--- lucene/lucy/trunk/perl/lib/Lucy/Search/Matcher.pm (added)
+++ lucene/lucy/trunk/perl/lib/Lucy/Search/Matcher.pm Fri Jun 18 01:16:28 2010
@@ -0,0 +1,49 @@
+package Lucy::Search::Matcher;
+use Lucy;
+
+1;
+
+__END__
+
+__BINDING__
+
+my $synopsis = <<'END_SYNOPSIS';
+ # Matcher is an abstract base class -- see MockScorer for an example
+ # implementation.
+END_SYNOPSIS
+
+my $constructor = <<'END_CONSTRUCTOR_CODE_SAMPLE';
+ my $matcher = MyMatcher->SUPER::new;
+END_CONSTRUCTOR_CODE_SAMPLE
+
+Clownfish::Binding::Perl::Class->register(
+ parcel => "Lucy",
+ class_name => "Lucy::Search::Matcher",
+ bind_methods => [qw( Next Advance Get_Doc_ID Score Collect )],
+ bind_constructors => ["new"],
+ make_pod => {
+ synopsis => $synopsis,
+ constructor => { sample => $constructor },
+ methods => [qw( next advance get_doc_id score )],
+ }
+);
+
+__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/Matcher.pm
------------------------------------------------------------------------------
svn:eol-style = native