You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2014/01/25 23:30:07 UTC
svn commit: r1561416 - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/suggest/ lucene/suggest/src/java/org/apache/lucene/search/suggest/
lucene/suggest/src/test/org/apache/lucene/search/suggest/ solr/ solr/core/
solr/core/src/java/org/apache/solr...
Author: simonw
Date: Sat Jan 25 22:30:06 2014
New Revision: 1561416
URL: http://svn.apache.org/r1561416
Log:
LUCENE-5414: Suggest module should not depend on expression module
Added:
lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java
- copied, changed from r1561415, lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java
lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java
- copied, changed from r1561415, lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java
Removed:
lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentExpressionDictionary.java
lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentExpressionDictionaryTest.java
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/lucene/suggest/ (props changed)
lucene/dev/branches/branch_4x/lucene/suggest/build.xml
lucene/dev/branches/branch_4x/solr/ (props changed)
lucene/dev/branches/branch_4x/solr/core/ (props changed)
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/spelling/suggest/DocumentExpressionDictionaryFactory.java
Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1561416&r1=1561415&r2=1561416&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Sat Jan 25 22:30:06 2014
@@ -145,6 +145,12 @@ API Changes
etc. but it's easy to override the parseShape method if you wish. (David
Smiley)
+* LUCENE-5414: DocumentExpressionDictionary was renamed to
+ DocumentValueSourceDictionary and all dependencies to the lucene-expression
+ module were removed from lucene-suggest. DocumentValueSourceDictionary now
+ only accepts a ValueSource instead of a convenience ctor for an expression
+ string. (Simon Willnauer)
+
Optimizations
* LUCENE-5372: Replace StringBuffer by StringBuilder, where possible.
Modified: lucene/dev/branches/branch_4x/lucene/suggest/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/suggest/build.xml?rev=1561416&r1=1561415&r2=1561416&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/suggest/build.xml (original)
+++ lucene/dev/branches/branch_4x/lucene/suggest/build.xml Sat Jan 25 22:30:06 2014
@@ -31,13 +31,10 @@
<path id="classpath">
<pathelement path="${analyzers-common.jar}"/>
<pathelement path="${misc.jar}"/>
- <pathelement path="${expressions.jar}"/>
<pathelement path="${queries.jar}"/>
- <fileset dir="${common.dir}/expressions/lib"/>
<path refid="base.classpath"/>
</path>
-
<target name="javadocs" depends="javadocs-queries,compile-core">
<invoke-module-javadoc>
<links>
Copied: lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java (from r1561415, lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java?p2=lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java&p1=lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java&r1=1561415&r2=1561416&rev=1561416&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java (original)
+++ lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java Sat Jan 25 22:30:06 2014
@@ -21,10 +21,10 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.List;
+import org.apache.lucene.document.Document;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.ReaderUtil;
-import org.apache.lucene.index.StoredDocument;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.util.BytesRefIterator;
@@ -125,7 +125,7 @@ public class DocumentValueSourceDictiona
* by the <code>weightsValueSource</code>
* */
@Override
- protected long getWeight(StoredDocument doc, int docId) {
+ protected long getWeight(Document doc, int docId) {
if (currentWeightValues == null) {
return 0;
}
Copied: lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java (from r1561415, lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java?p2=lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java&p1=lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java&r1=1561415&r2=1561416&rev=1561416&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java Sat Jan 25 22:30:06 2014
@@ -54,7 +54,7 @@ public class DocumentValueSourceDictiona
static final String PAYLOAD_FIELD_NAME = "p1";
private Map<String, Document> generateIndexDocuments(int ndocs) {
- Map<String, Document> docs = new HashMap<>();
+ Map<String, Document> docs = new HashMap<String, Document>();
for(int i = 0; i < ndocs ; i++) {
Field field = new TextField(FIELD_NAME, "field_" + i, Field.Store.YES);
Field payload = new StoredField(PAYLOAD_FIELD_NAME, new BytesRef("payload_" + i));
@@ -165,7 +165,7 @@ public class DocumentValueSourceDictiona
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
Map<String, Document> docs = generateIndexDocuments(atLeast(100));
Random rand = random();
- List<String> termsToDel = new ArrayList<>();
+ List<String> termsToDel = new ArrayList<String>();
for(Document doc : docs.values()) {
if(rand.nextBoolean() && termsToDel.size() < docs.size()-1) {
termsToDel.add(doc.get(FIELD_NAME));
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/spelling/suggest/DocumentExpressionDictionaryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/spelling/suggest/DocumentExpressionDictionaryFactory.java?rev=1561416&r1=1561415&r2=1561416&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/spelling/suggest/DocumentExpressionDictionaryFactory.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/spelling/suggest/DocumentExpressionDictionaryFactory.java Sat Jan 25 22:30:06 2014
@@ -17,12 +17,17 @@ package org.apache.solr.spelling.suggest
* limitations under the License.
*/
+import java.text.ParseException;
import java.util.HashSet;
import java.util.Set;
+import org.apache.lucene.expressions.Expression;
+import org.apache.lucene.expressions.SimpleBindings;
+import org.apache.lucene.expressions.js.JavascriptCompiler;
+import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.spell.Dictionary;
-import org.apache.lucene.search.suggest.DocumentExpressionDictionary;
+import org.apache.lucene.search.suggest.DocumentValueSourceDictionary;
import org.apache.solr.core.SolrCore;
import org.apache.solr.schema.DoubleField;
import org.apache.solr.schema.FieldType;
@@ -36,7 +41,7 @@ import org.apache.solr.schema.TrieLongFi
import org.apache.solr.search.SolrIndexSearcher;
/**
- * Factory for {@link DocumentExpressionDictionary}
+ * Factory for {@link org.apache.lucene.search.suggest.DocumentValueSourceDictionary}
*/
public class DocumentExpressionDictionaryFactory extends DictionaryFactory {
@@ -89,8 +94,22 @@ public class DocumentExpressionDictionar
}
}
- return new DocumentExpressionDictionary(searcher.getIndexReader(), field, weightExpression,
- sortFields, payloadField);
+ return new DocumentValueSourceDictionary(searcher.getIndexReader(), field, fromExpression(weightExpression,
+ sortFields), payloadField);
+ }
+
+ public ValueSource fromExpression(String weightExpression, Set<SortField> sortFields) {
+ Expression expression = null;
+ try {
+ expression = JavascriptCompiler.compile(weightExpression);
+ } catch (ParseException e) {
+ throw new RuntimeException();
+ }
+ SimpleBindings bindings = new SimpleBindings();
+ for (SortField sortField : sortFields) {
+ bindings.add(sortField);
+ }
+ return expression.getValueSource(bindings);
}
private SortField.Type getSortFieldType(SolrCore core, String sortFieldName) {