Skip to content

Apache Lucene open-source search software

Many javadoc additions, and adding ASL to each file

Erik Hatcher297d1429eb76
diff --git a/contrib/regex/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java b/contrib/regex/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java
index 0808b5db63e..5f4a76cb043 100644
--- a/contrib/regex/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java
+++ b/contrib/regex/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java
@@ -1,8 +1,29 @@
package org.apache.lucene.search.regex;
+/**
+ * Copyright 2006 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.regexp.RE;
import org.apache.regexp.RegexpTunnel;
+/**
+ * Implementation tying <a href="http://jakarta.apache.org/regexp">Jakarta Regexp</a>
+ * to RegexQuery. Thanks to some internals of Jakarta Regexp, this
+ * has a solid {@link #prefix} implementation.
+ */
public class JakartaRegexpCapabilities implements RegexCapabilities {
private RE regexp;
diff --git a/contrib/regex/src/java/org/apache/lucene/search/regex/JavaUtilRegexCapabilities.java b/contrib/regex/src/java/org/apache/lucene/search/regex/JavaUtilRegexCapabilities.java
index 6245c1b488f..ce7140ad624 100644
--- a/contrib/regex/src/java/org/apache/lucene/search/regex/JavaUtilRegexCapabilities.java
+++ b/contrib/regex/src/java/org/apache/lucene/search/regex/JavaUtilRegexCapabilities.java
@@ -1,7 +1,30 @@
package org.apache.lucene.search.regex;
+/**
+ * Copyright 2006 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.util.regex.Pattern;
+/**
+ * An implementation tying Java's built-in java.util.regex to RegexQuery.
+ *
+ * Note that because this implementation currently only returns null from
+ * {@link #prefix} that queries using this implementation will enumerate and
+ * attempt to {@link #match} each term for the specified field in the index.
+ */
public class JavaUtilRegexCapabilities implements RegexCapabilities {
private Pattern pattern;
diff --git a/contrib/regex/src/java/org/apache/lucene/search/regex/RegexCapabilities.java b/contrib/regex/src/java/org/apache/lucene/search/regex/RegexCapabilities.java
index fb1224e5240..08bec89606f 100644
--- a/contrib/regex/src/java/org/apache/lucene/search/regex/RegexCapabilities.java
+++ b/contrib/regex/src/java/org/apache/lucene/search/regex/RegexCapabilities.java
@@ -1,7 +1,47 @@
package org.apache.lucene.search.regex;
-public interface RegexCapabilities {
+/**
+ * Copyright 2006 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.
+ */
+
+/**
+ * Defines basic operations needed by {@link RegexQuery} for a regular
+ * expression implementation.
+ */
+interface RegexCapabilities {
+ /**
+ * Called by the constructor of {@link RegexTermEnum} allowing
+ * implementations to cache a compiled version of the regular
+ * expression pattern.
+ *
+ * @param pattern regular expression pattern
+ */
void compile(String pattern);
+
+ /**
+ *
+ * @param string
+ * @return true if string matches the pattern last passed to {@link #compile}.
+ */
boolean match(String string);
+
+ /**
+ * A wise prefix implementation can reduce the term enumeration (and thus performance)
+ * of RegexQuery dramatically!
+ *
+ * @return static non-regex prefix of the pattern last passed to {@link #compile}. May return null.
+ */
String prefix();
}
diff --git a/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQuery.java b/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQuery.java
index a0843bab97a..f34789e220c 100644
--- a/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQuery.java
+++ b/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQuery.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.regex;
+/**
+ * Copyright 2006 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.search.MultiTermQuery;
import org.apache.lucene.search.FilteredTermEnum;
import org.apache.lucene.index.Term;
@@ -7,17 +23,32 @@ import org.apache.lucene.index.IndexReader;
import java.io.IOException;
+/** Implements the regular expression term search query.
+ * The expressions supported depend on the regular expression implementation
+ * used by way of the {@link RegexCapabilities} interface.
+ *
+ * @see RegexTermEnum
+ */
public class RegexQuery extends MultiTermQuery implements RegexQueryCapable {
private RegexCapabilities regexImpl = new JavaUtilRegexCapabilities();
+ /** Constructs a query for terms matching <code>term</code>. */
public RegexQuery(Term term) {
super(term);
}
+ /**
+ * Defines which {@link RegexCapabilities} implementation is used by this instance.
+ *
+ * @param impl
+ */
public void setRegexImplementation(RegexCapabilities impl) {
this.regexImpl = impl;
}
+ /**
+ * @return The implementation used by this instance.
+ */
public RegexCapabilities getRegexImplementation() {
return regexImpl;
}
diff --git a/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQueryCapable.java b/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQueryCapable.java
index 79ca08a4227..4b85435928d 100644
--- a/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQueryCapable.java
+++ b/contrib/regex/src/java/org/apache/lucene/search/regex/RegexQueryCapable.java
@@ -1,6 +1,26 @@
package org.apache.lucene.search.regex;
-public interface RegexQueryCapable {
+/**
+ * Copyright 2006 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.
+ */
+
+
+/**
+ * Defines methods for regular expression supporting Querys to use.
+ */
+interface RegexQueryCapable {
void setRegexImplementation(RegexCapabilities impl);
RegexCapabilities getRegexImplementation();
}
diff --git a/contrib/regex/src/java/org/apache/lucene/search/regex/RegexTermEnum.java b/contrib/regex/src/java/org/apache/lucene/search/regex/RegexTermEnum.java
index 19b2739f160..6d8ec490155 100644
--- a/contrib/regex/src/java/org/apache/lucene/search/regex/RegexTermEnum.java
+++ b/contrib/regex/src/java/org/apache/lucene/search/regex/RegexTermEnum.java
@@ -1,11 +1,36 @@
package org.apache.lucene.search.regex;
+/**
+ * Copyright 2006 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.search.FilteredTermEnum;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import java.io.IOException;
+/**
+ * Subclass of FilteredTermEnum for enumerating all terms that match the
+ * specified regular expression term using the specified regular expression
+ * implementation.
+ * <p>
+ * Term enumerations are always ordered by Term.compareTo(). Each term in
+ * the enumeration is greater than all that precede it.
+ */
+
public class RegexTermEnum extends FilteredTermEnum {
private String field = "";
private String pre = "";
diff --git a/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java b/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
index 37c649e018c..99701e1ee0d 100644
--- a/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
+++ b/contrib/regex/src/java/org/apache/lucene/search/regex/SpanRegexQuery.java
@@ -1,5 +1,21 @@
package org.apache.lucene.search.regex;
+/**
+ * Copyright 2006 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.index.Term;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Query;
@@ -16,6 +32,10 @@ import java.io.IOException;
import java.util.Collection;
import java.util.ArrayList;
+/**
+ * A SpanQuery version of {@link RegexQuery} allowing regular expression
+ * queries to be nested within other SpanQuery subclasses.
+ */
public class SpanRegexQuery extends SpanQuery implements RegexQueryCapable {
private RegexCapabilities regexImpl = new JavaUtilRegexCapabilities();
private Term term;
diff --git a/contrib/regex/src/java/org/apache/lucene/search/regex/package.html b/contrib/regex/src/java/org/apache/lucene/search/regex/package.html
new file mode 100644
index 00000000000..c963307fecb
--- /dev/null
+++ b/contrib/regex/src/java/org/apache/lucene/search/regex/package.html
@@ -0,0 +1,5 @@
+<html><head></head>
+<body>
+Regular expression Query.
+</body>
+</html>
diff --git a/contrib/regex/src/java/org/apache/regexp/RegexpTunnel.java b/contrib/regex/src/java/org/apache/regexp/RegexpTunnel.java
index 5861956beeb..dc5665a8935 100644
--- a/contrib/regex/src/java/org/apache/regexp/RegexpTunnel.java
+++ b/contrib/regex/src/java/org/apache/regexp/RegexpTunnel.java
@@ -1,5 +1,22 @@
package org.apache.regexp;
+/**
+ * Copyright 2006 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.
+ */
+
+
/**
* This class exists as a gateway to access useful Jakarta Regexp package protected data.
*/
diff --git a/contrib/regex/src/java/org/apache/regexp/package.html b/contrib/regex/src/java/org/apache/regexp/package.html
new file mode 100644
index 00000000000..2688cfb35a5
--- /dev/null
+++ b/contrib/regex/src/java/org/apache/regexp/package.html
@@ -0,0 +1,7 @@
+<html><head></head>
+<body>
+This package exists to allow access to useful package protected data within
+Jakarta Regexp. This data has now been opened up with an accessor, but
+an official release with that change has not been made to date.
+</body>
+</html>
diff --git a/contrib/regex/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java b/contrib/regex/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java
index 6b662bcdcd4..ab27374ef83 100644
--- a/contrib/regex/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java
+++ b/contrib/regex/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java
@@ -12,22 +12,29 @@ import org.apache.lucene.search.Hits;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.search.spans.SpanNearQuery;
import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.search.spans.SpanFirstQuery;
public class TestSpanRegexQuery extends TestCase {
public void testSpanRegex() throws Exception {
RAMDirectory directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true);
Document doc = new Document();
- doc.add(new Field("field", "the quick brown fox jumps over the lazy dog", Field.Store.NO, Field.Index.TOKENIZED));
+// doc.add(new Field("field", "the quick brown fox jumps over the lazy dog", Field.Store.NO, Field.Index.TOKENIZED));
+// writer.addDocument(doc);
+// doc = new Document();
+ doc.add(new Field("field", "auto update", Field.Store.NO, Field.Index.TOKENIZED));
+ writer.addDocument(doc);
+ doc = new Document();
+ doc.add(new Field("field", "first auto update", Field.Store.NO, Field.Index.TOKENIZED));
writer.addDocument(doc);
writer.optimize();
writer.close();
IndexSearcher searcher = new IndexSearcher(directory);
- SpanRegexQuery srq = new SpanRegexQuery(new Term("field", "q.[aeiou]c.*"));
- SpanTermQuery stq = new SpanTermQuery(new Term("field","dog"));
- SpanNearQuery query = new SpanNearQuery(new SpanQuery[] {srq, stq}, 6, true);
- Hits hits = searcher.search(query);
+ SpanRegexQuery srq = new SpanRegexQuery(new Term("field", "aut.*"));
+ SpanFirstQuery sfq = new SpanFirstQuery(srq, 1);
+// SpanNearQuery query = new SpanNearQuery(new SpanQuery[] {srq, stq}, 6, true);
+ Hits hits = searcher.search(sfq);
assertEquals(1, hits.length());
}
}