X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java diff --git a/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java b/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java new file mode 100644 index 0000000..3cdb25d --- /dev/null +++ b/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java @@ -0,0 +1,195 @@ +package org.apache.lucene.search.function; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.IndexReader; +import org.apache.lucene.index.Term; +import org.apache.lucene.index.TermDocs; +import org.apache.lucene.search.*; +import org.apache.lucene.util.ToStringUtils; + +import java.io.IOException; +import java.util.Set; + +/** + * Expert: A Query that sets the scores of document to the + * values obtained from a {@link org.apache.lucene.search.function.ValueSource ValueSource}. + *
+ * This query provides a score for each and every undeleted document in the index. + *
+ * The value source can be based on a (cached) value of an indexed field, but it + * can also be based on an external source, e.g. values read from an external database. + *
+ * Score is set as: Score(doc,query) = query.getBoost()2 * valueSource(doc).
+ *
+ * @lucene.experimental
+ */
+public class ValueSourceQuery extends Query {
+ ValueSource valSrc;
+
+ /**
+ * Create a value source query
+ * @param valSrc provides the values defines the function to be used for scoring
+ */
+ public ValueSourceQuery(ValueSource valSrc) {
+ this.valSrc=valSrc;
+ }
+
+ /*(non-Javadoc) @see org.apache.lucene.search.Query#rewrite(org.apache.lucene.index.IndexReader) */
+ @Override
+ public Query rewrite(IndexReader reader) throws IOException {
+ return this;
+ }
+
+ /*(non-Javadoc) @see org.apache.lucene.search.Query#extractTerms(java.util.Set) */
+ @Override
+ public void extractTerms(Seto
is equal to this. */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!super.equals(o))
+ return false;
+ if (getClass() != o.getClass()) {
+ return false;
+ }
+ ValueSourceQuery other = (ValueSourceQuery)o;
+ return this.getBoost() == other.getBoost()
+ && this.valSrc.equals(other.valSrc);
+ }
+
+ /** Returns a hash code value for this object. */
+ @Override
+ public int hashCode() {
+ return (getClass().hashCode() + valSrc.hashCode()) ^ Float.floatToIntBits(getBoost());
+ }
+
+}