Skip to content

Instantly share code, notes, and snippets.

@dcolish
Created August 17, 2012 05:04
Show Gist options
  • Select an option

  • Save dcolish/3376095 to your computer and use it in GitHub Desktop.

Select an option

Save dcolish/3376095 to your computer and use it in GitHub Desktop.
diff --git a/xapian-bindings/java/SmokeTest.java b/xapian-bindings/java/SmokeTest.java
old mode 100644
new mode 100755
index 7e5223a..01a692b
--- a/xapian-bindings/java/SmokeTest.java
+++ b/xapian-bindings/java/SmokeTest.java
@@ -112,21 +112,33 @@ public class SmokeTest {
System.err.println("Unexpected mset.size()");
System.exit(1);
}
+ MSetIterator m_itor = mset.begin();
+ Document m_doc = null;
+ long m_id;
+ while(m_itor.hasNext()) {
+ m_id = m_itor.next();
+ if(m_itor.hasNext()) {
+ m_doc = mset.getDocument(m_id);
+ }
+ }
+
+ // Only one doc exists in this mset
+ if(m_doc != null && m_doc.getDocId() != 0) {
+ System.err.println("Unexpected docid");
+ System.exit(1);
+ }
String term_str = "";
- String[] itor = enq.getMatchingTerms(mset.getElement(0));
- int size = itor.length - 1;
- for (String str : itor) {
- term_str += str;
- if (size > 0)
+ TermIterator itor = enq.getMatchingTermsBegin(mset.getElement(0));
+ while (itor.hasNext()) {
+ term_str += itor.next();
+ if (itor.hasNext())
term_str += ' ';
- size--;
}
if (!term_str.equals("is there")) {
System.err.println("Unexpected term_str");
System.exit(1);
}
-
/* FIXME:dc: Fails since Xapian::Error is still unmapped
boolean ok = false;
try {
@@ -156,10 +168,9 @@ public class SmokeTest {
System.exit(1);
}
-/*
- ESetIterator eit = eset.iterator();
int count = 0;
- while (eit.hasNext()) {
+ for(ESetIterator eit = eset.begin(); eit.hasNext(); ) {
+ // for (int i = 0; i < eset.size(); i++) {
if (eit.getTerm().charAt(0) == 'a') {
System.err.println("MyExpandDecider wasn't used");
System.exit(1);
@@ -169,9 +180,9 @@ public class SmokeTest {
}
if (count != eset.size()) {
System.err.println("ESet.size() mismatched number of terms returned by ESetIterator");
+ System.err.printf("%s %s", count, eset.size());
System.exit(1);
}
-*/
/*
MSet mset2 = enq.getMSet(0, 10, null, new MyMatchDecider());
diff --git a/xapian-bindings/java/java.i b/xapian-bindings/java/java.i
old mode 100644
new mode 100755
index 349e69f..64b628e
--- a/xapian-bindings/java/java.i
+++ b/xapian-bindings/java/java.i
@@ -3,6 +3,7 @@
/* java.i: SWIG interface file for the Java bindings
*
* Copyright (c) 2007,2009,2011,2012 Olly Betts
+ * Copyright (c) 2012 Dan Colish
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -109,20 +110,88 @@ namespace Xapian {
// For compatibility with the original JNI wrappers.
// FIXME: These make use of the fact that the default ctor for PostingIterator,
// TermIterator, and ValueIterator produces an end iterator.
+%{
+
+Xapian::PostingIterator posting_end_ = Xapian::PostingIterator();
+Xapian::TermIterator term_end_ = Xapian::TermIterator();
+Xapian::ValueIterator value_end_ = Xapian::ValueIterator();
+
+%}
%extend PostingIterator {
- bool hasNext() const { return (*self) == Xapian::PostingIterator(); }
+ Xapian::docid next () {
+ Xapian::docid tmp;
+ if ((*self) != posting_end_) {
+ tmp = (**self);
+ ++(*self);
+ } else {
+ tmp = -1;
+ }
+ return tmp;
+ }
+
+ bool hasNext() const { return (*self) != posting_end_; }
}
%extend TermIterator {
- bool hasNext() const { return (*self) == Xapian::TermIterator(); }
+ std::string next () {
+ std:string tmp;
+ if ((*self) != term_end_) {
+ tmp = (**self);
+ ++(*self);
+ } else {
+ tmp = "";
+ }
+ return tmp;
+ }
+
+ bool hasNext() const { return (*self) != term_end_; }
}
%extend ValueIterator {
- bool hasNext() const { return (*self) == Xapian::ValueIterator(); }
+ std::string next () {
+ std:string tmp;
+ if ((*self) != value_end_) {
+ tmp = (**self);
+ ++(*self);
+ } else {
+ tmp = "";
+ }
+ return tmp;
+ }
+
+ bool hasNext() const { return (*self) != value_end_; }
+}
+
+%extend ESetIterator {
+ std::string next () {
+ std:string tmp;
+ if (!self->at_end()) {
+ tmp = (**self);
+ ++(*self);
+ } else {
+ tmp = "";
+ }
+ return tmp;
+ }
+
+ bool hasNext() const { return !self->at_end(); }
}
-// FIXME: MSetIterator::hasNext() and ESetIterator::hasNext().
+%extend MSetIterator {
+ Xapian::docid next () {
+ Xapian::docid tmp;
+ if (!self->at_end()) {
+ tmp = (**self);
+ ++(*self);
+ } else {
+ tmp = -1;
+ }
+ return tmp;
+ }
+
+ bool hasNext() const { return !self->at_end(); }
+}
}
diff --git a/xapian-core/include/xapian/enquire.h b/xapian-core/include/xapian/enquire.h
old mode 100644
new mode 100755
index d16d7e2..2f1dded
--- a/xapian-core/include/xapian/enquire.h
+++ b/xapian-core/include/xapian/enquire.h
@@ -396,6 +396,9 @@ class XAPIAN_VISIBILITY_DEFAULT MSetIterator {
*/
int get_percent() const;
+ /// Determine if iterator is exhausted
+ bool at_end() const { return index == mset.size(); }
+
/// Return a string describing this object.
std::string get_description() const;
@@ -482,6 +485,7 @@ class XAPIAN_VISIBILITY_DEFAULT ESet {
std::string get_description() const;
};
+//FIXME:dc: This iterator should be converted to use an Internal class
/** Iterate through terms in the ESet */
class XAPIAN_VISIBILITY_DEFAULT ESetIterator {
private:
@@ -549,6 +553,9 @@ class XAPIAN_VISIBILITY_DEFAULT ESetIterator {
/// Return a string describing this object.
std::string get_description() const;
+ /// Determine if the iterator has been exhausted
+ bool at_end() const { return index == eset.size(); }
+
/// Allow use as an STL iterator
//@{
typedef std::bidirectional_iterator_tag iterator_category; // FIXME: go for randomaccess_iterator!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment