Permalink
Browse files

added andnot support

  • Loading branch information...
2 parents 37730d3 + e12aad0 commit 0ef4ddf958c9e51dd7deaf7f716afc91d4288497 John Wang committed Nov 1, 2011
View
@@ -1,12 +1,8 @@
-<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry kind="src" path="contrib/luceneCodec/test"/>
- <classpathentry excluding="com/kamikaze/lucecodec/util/" kind="src" path="contrib/luceneCodec/src"/>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
- <classpathentry kind="lib" path="/Users/john/.m2/repository/org/apache/lucene/lucene-core/3.4.0/lucene-core-3.4.0.jar"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+ <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
+ <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.5/junit-4.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/lucene/lucene-core/3.3.0/lucene-core-3.3.0.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+</classpath>
View
@@ -1,23 +1,17 @@
-<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>kamikaze</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+ <name>kamikaze</name>
+ <comment>information retrival utility package for enhancing Lucene. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Oops, something went wrong.
View
@@ -111,7 +111,7 @@
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
- <version>3.3.0</version>
+ <version>3.4.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -0,0 +1,58 @@
+package com.kamikaze.docidset.impl;
+
+import java.io.IOException;
+
+import org.apache.lucene.search.DocIdSetIterator;
+
+public class AndNotDocIdSetIterator extends DocIdSetIterator{
+ private int _nextDelDoc;
+ private final DocIdSetIterator _baseIter;
+ private final DocIdSetIterator _notIter;
+ private int _currID;
+
+ public AndNotDocIdSetIterator(DocIdSetIterator baseIter,DocIdSetIterator notIter) throws IOException{
+ _nextDelDoc = notIter.nextDoc();
+ _baseIter = baseIter;
+ _notIter = notIter;
+ _currID = -1;
+ }
+
+ @Override
+ public int advance(int target) throws IOException {
+ _currID = _baseIter.advance(target);
+ if (_currID==DocIdSetIterator.NO_MORE_DOCS)
+ return _currID;
+
+ if (_nextDelDoc!=DocIdSetIterator.NO_MORE_DOCS){
+ _currID = _baseIter.docID();
+ if (_currID<_nextDelDoc) return _currID;
+ _nextDelDoc = _notIter.advance(_currID);
+ if (_currID==_nextDelDoc) return nextDoc();
+ }
+ return _currID;
+ }
+
+ @Override
+ public int docID() {
+ return _currID;
+ }
+
+ @Override
+ public int nextDoc() throws IOException {
+ _currID =_baseIter.nextDoc();
+ if (_nextDelDoc!=DocIdSetIterator.NO_MORE_DOCS){
+ while(_currID != DocIdSetIterator.NO_MORE_DOCS){
+ if (_currID<_nextDelDoc){
+ return _currID;
+ }
+ else{
+ if (_currID == _nextDelDoc){
+ _currID =_baseIter.nextDoc();
+ }
+ _nextDelDoc = _notIter.advance(_currID);
+ }
+ }
+ }
+ return _currID;
+ }
+}
@@ -24,7 +24,9 @@
import com.kamikaze.docidset.api.DocSet;
import com.kamikaze.docidset.api.StatefulDSIterator;
import com.kamikaze.docidset.impl.AndDocIdSet;
+import com.kamikaze.docidset.impl.AndNotDocIdSetIterator;
import com.kamikaze.docidset.impl.IntArrayDocIdSet;
+import com.kamikaze.docidset.impl.OBSDocIdSet;
import com.kamikaze.docidset.impl.OrDocIdSet;
import com.kamikaze.docidset.impl.PForDeltaDocIdSet;
import com.kamikaze.docidset.utils.DocSetFactory;
@@ -73,6 +75,33 @@ public void testAddDocNextDoc() throws Exception
}
@Test
+ public void testAddNotDocsIdIterator() throws Exception
+ {
+ System.out.println("Running test case: testAddNotDocsIdIterator()...");
+
+ int n = 10;
+ OBSDocIdSet evenset = new OBSDocIdSet(n);
+ for (int i=0;i<n;i+=2){
+ evenset.addDoc(i);
+ }
+
+ OBSDocIdSet fullset = new OBSDocIdSet(n);
+ for (int i=0;i<n;++i){
+ fullset.addDoc(i);
+ }
+
+ AndNotDocIdSetIterator iter = new AndNotDocIdSetIterator(fullset.iterator(),evenset.iterator());
+ int doc;
+ int i=1;
+ while((doc=iter.nextDoc())!=DocIdSetIterator.NO_MORE_DOCS){
+ assertEquals(i,doc);
+ i+=2;
+ }
+
+ assertEquals(11,i);
+ }
+
+ @Test
public void testAddDocsNextDoc() throws Exception
{
// test the accuracy of PForDeltaDocIdSet.addDoc() (Compression) and PForDeltaDocIdSet.PForDeltaDocIdIterator.nextDoc() (Decompression).
Binary file not shown.

0 comments on commit 0ef4ddf

Please sign in to comment.