Skip to content

Apache Lucene open-source search software

- Added ASL 2.0

Otis Gospodnetic7ce4f079f55b
diff --git a/src/java/org/apache/lucene/search/spans/NearSpans.java b/src/java/org/apache/lucene/search/spans/NearSpans.java
index dab48215c52..f29813a28de 100644
--- a/src/java/org/apache/lucene/search/spans/NearSpans.java
+++ b/src/java/org/apache/lucene/search/spans/NearSpans.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import java.io.IOException;
import java.util.List;
@@ -10,7 +26,7 @@ import org.apache.lucene.index.IndexReader;
class NearSpans implements Spans {
private SpanNearQuery query;
-
+
private List ordered = new ArrayList(); // spans in query order
private int slop; // from query
private boolean inOrder; // from query
@@ -34,9 +50,9 @@ class NearSpans implements Spans {
private Spans spans;
private SpansCell next;
private int length = -1;
-
+
public SpansCell(Spans spans) { this.spans = spans; }
-
+
public boolean next() throws IOException {
if (length != -1) // subtract old length
totalLength -= length;
@@ -94,7 +110,7 @@ class NearSpans implements Spans {
ordered.add(cell); // add to ordered
}
}
-
+
public boolean next() throws IOException {
if (firstTime) {
initList(true);
@@ -104,17 +120,17 @@ class NearSpans implements Spans {
more = last.next(); // trigger scan
queueStale = true;
}
-
+
while (more) {
if (listStale) { // maintain list
queueToList();
listStale = false;
}
-
+
// skip to doc w/ all clauses
- while (more && first.doc() < last.doc()) {
+ while (more && first.doc() < last.doc()) {
more = first.skipTo(last.doc()); // skip first upto last
firstToLast(); // and move it to the end
queueStale = true;
@@ -125,7 +141,7 @@ class NearSpans implements Spans {
// found doc w/ all clauses
if (queueStale) { // maintain the queue
- listToQueue();
+ listToQueue();
queueStale = false;
}
@@ -134,7 +150,7 @@ class NearSpans implements Spans {
&& (!inOrder || matchIsOrdered())) { // check order
return true;
}
-
+
more = min().next(); // trigger further scanning
if (more) {
@@ -169,7 +185,7 @@ class NearSpans implements Spans {
}
return next(); // no, scan
}
-
+
return false;
}
@@ -221,7 +237,7 @@ class NearSpans implements Spans {
queue.put(cell); // build queue from list
}
}
-
+
private boolean matchIsOrdered() {
int lastStart = -1;
for (int i = 0; i < ordered.size(); i++) {
diff --git a/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java b/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
index 40f06e9baff..f23d44e59b0 100644
--- a/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import java.io.IOException;
import java.util.Collection;
@@ -56,7 +72,7 @@ public class SpanFirstQuery extends SpanQuery {
if (spans.end() <= end) // there is a match
return true;
-
+
return next(); // scan to next match
}
diff --git a/src/java/org/apache/lucene/search/spans/SpanNearQuery.java b/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
index 9625efe81e7..4b116347d09 100644
--- a/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import java.io.IOException;
import java.util.Collection;
@@ -37,7 +53,7 @@ public class SpanNearQuery extends SpanQuery {
}
this.clauses.add(clause);
}
-
+
this.slop = slop;
this.inOrder = inOrder;
}
diff --git a/src/java/org/apache/lucene/search/spans/SpanNotQuery.java b/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
index ce5bd38e860..be0f38d7a9e 100644
--- a/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import java.io.IOException;
import java.util.Collection;
@@ -55,10 +71,10 @@ public class SpanNotQuery extends SpanQuery {
moreInclude = includeSpans.next();
while (moreInclude && moreExclude) {
-
+
if (includeSpans.doc() > excludeSpans.doc()) // skip exclude
moreExclude = excludeSpans.skipTo(includeSpans.doc());
-
+
while (moreExclude // while exclude is before
&& includeSpans.doc() == excludeSpans.doc()
&& excludeSpans.end() <= includeSpans.start()) {
@@ -69,9 +85,9 @@ public class SpanNotQuery extends SpanQuery {
|| includeSpans.doc() != excludeSpans.doc()
|| includeSpans.end() <= excludeSpans.start())
break; // we found a match
-
+
moreInclude = includeSpans.next(); // intersected: keep scanning
- }
+ }
return moreInclude;
}
@@ -96,7 +112,7 @@ public class SpanNotQuery extends SpanQuery {
|| includeSpans.doc() != excludeSpans.doc()
|| includeSpans.end() <= excludeSpans.start())
return true; // we found a match
-
+
return next(); // scan to next match
}
diff --git a/src/java/org/apache/lucene/search/spans/SpanOrQuery.java b/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
index c580c41f99a..c41bfb70085 100644
--- a/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import java.io.IOException;
import java.util.List;
@@ -73,10 +89,10 @@ public class SpanOrQuery extends SpanQuery {
{
Iterator i = clauses.iterator();
while (i.hasNext()) { // initialize all
- all.add(((SpanQuery)i.next()).getSpans(reader));
+ all.add(((SpanQuery)i.next()).getSpans(reader));
}
}
-
+
private boolean firstTime = true;
public boolean next() throws IOException {
diff --git a/src/java/org/apache/lucene/search/spans/SpanQuery.java b/src/java/org/apache/lucene/search/spans/SpanQuery.java
index 753b3419dce..511317eb574 100644
--- a/src/java/org/apache/lucene/search/spans/SpanQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanQuery.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import java.io.IOException;
import java.util.Collection;
diff --git a/src/java/org/apache/lucene/search/spans/SpanQueue.java b/src/java/org/apache/lucene/search/spans/SpanQueue.java
index 6dda06a5e0d..fba8c64eb9c 100644
--- a/src/java/org/apache/lucene/search/spans/SpanQueue.java
+++ b/src/java/org/apache/lucene/search/spans/SpanQueue.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import org.apache.lucene.util.PriorityQueue;
class SpanQueue extends PriorityQueue {
diff --git a/src/java/org/apache/lucene/search/spans/SpanScorer.java b/src/java/org/apache/lucene/search/spans/SpanScorer.java
index 1671dc3addc..9c03a1308b5 100644
--- a/src/java/org/apache/lucene/search/spans/SpanScorer.java
+++ b/src/java/org/apache/lucene/search/spans/SpanScorer.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
diff --git a/src/java/org/apache/lucene/search/spans/SpanTermQuery.java b/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
index 8e8a3a19d12..7aece4d0ce3 100644
--- a/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
+++ b/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import java.io.IOException;
import java.util.Collection;
@@ -42,7 +58,7 @@ public class SpanTermQuery extends SpanQuery {
private int freq;
private int count;
private int position;
-
+
public boolean next() throws IOException {
if (count == freq) {
if (!positions.next())
diff --git a/src/java/org/apache/lucene/search/spans/SpanWeight.java b/src/java/org/apache/lucene/search/spans/SpanWeight.java
index 117a9feb483..a1159205745 100644
--- a/src/java/org/apache/lucene/search/spans/SpanWeight.java
+++ b/src/java/org/apache/lucene/search/spans/SpanWeight.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import java.io.IOException;
import java.util.Iterator;
@@ -43,7 +59,7 @@ class SpanWeight implements Weight {
public void normalize(float queryNorm) {
this.queryNorm = queryNorm;
queryWeight *= queryNorm; // normalize query weight
- value = queryWeight * idf; // idf for document
+ value = queryWeight * idf; // idf for document
}
public Scorer scorer(IndexReader reader) throws IOException {
@@ -74,7 +90,7 @@ class SpanWeight implements Weight {
Explanation idfExpl =
new Explanation(idf, "idf(" + field + ": " + docFreqs + ")");
-
+
// explain query weight
Explanation queryExpl = new Explanation();
queryExpl.setDescription("queryWeight(" + getQuery() + "), product of:");
@@ -83,16 +99,16 @@ class SpanWeight implements Weight {
if (getQuery().getBoost() != 1.0f)
queryExpl.addDetail(boostExpl);
queryExpl.addDetail(idfExpl);
-
+
Explanation queryNormExpl = new Explanation(queryNorm,"queryNorm");
queryExpl.addDetail(queryNormExpl);
-
+
queryExpl.setValue(boostExpl.getValue() *
idfExpl.getValue() *
queryNormExpl.getValue());
result.addDetail(queryExpl);
-
+
// explain field weight
Explanation fieldExpl = new Explanation();
fieldExpl.setDescription("fieldWeight("+field+":"+query.toString(field)+
@@ -113,7 +129,7 @@ class SpanWeight implements Weight {
fieldExpl.setValue(tfExpl.getValue() *
idfExpl.getValue() *
fieldNormExpl.getValue());
-
+
result.addDetail(fieldExpl);
// combine them
diff --git a/src/java/org/apache/lucene/search/spans/Spans.java b/src/java/org/apache/lucene/search/spans/Spans.java
index af36e68977a..ef8bac861fa 100644
--- a/src/java/org/apache/lucene/search/spans/Spans.java
+++ b/src/java/org/apache/lucene/search/spans/Spans.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.spans;
+/**
+ * Copyright 2004 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.
+ */
+
import java.io.IOException;
/** Expert: an enumeration of span matches. Used to implement span searching.
@@ -10,7 +26,7 @@ public interface Spans {
/** Move to the next match, returning true iff any such exists. */
boolean next() throws IOException;
- /** Skips to the first match beyond the current whose document number is
+ /** Skips to the first match beyond the current, whose document number is
* greater than or equal to <i>target</i>. <p>Returns true iff there is such
* a match. <p>Behaves as if written: <pre>
* boolean skipTo(int target) {