- Added ASL 2.0

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150186 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Otis Gospodnetic 2004-02-02 13:27:52 +00:00
parent 93ff39de13
commit 7ce4f079f5
11 changed files with 204 additions and 28 deletions

View File

@ -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++) {

View File

@ -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
}

View File

@ -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;
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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())

View File

@ -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

View File

@ -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) {