You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by to...@apache.org on 2015/06/05 16:23:20 UTC
svn commit: r1683763 - in /jackrabbit/oak/branches/1.0/oak-solr-core/src:
main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/
main/resources/solr/oak/conf/ test/resources/solr/oak/conf/
Author: tommaso
Date: Fri Jun 5 14:23:19 2015
New Revision: 1683763
URL: http://svn.apache.org/r1683763
Log:
OAK-2958, OAK-2467 - backporting rep:suggest to branch 1.0
Modified:
jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java
jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml
jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/solrconfig.xml
jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml
jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/solrconfig.xml
Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java?rev=1683763&r1=1683762&r2=1683763&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/FilterQueryParser.java Fri Jun 5 14:23:19 2015
@@ -135,6 +135,15 @@ class FilterQueryParser {
}
solrQuery.setParam("spellcheck", true);
}
+ if ("/suggest".equals(requestHandlerString)) {
+ if ("term".equals(kv[0])) {
+ kv[0] = "suggest.q";
+ }
+ solrQuery.setParam("suggest", true);
+
+ // TODO : this should not be always passed to avoid building the dictionary on each suggest request
+ solrQuery.setParam("suggest.build", true);
+ }
solrQuery.setParam(kv[0], kv[1]);
}
}
@@ -306,7 +315,7 @@ class FilterQueryParser {
private static boolean isSupportedHttpRequest(String nativeQueryString) {
// the query string starts with ${supported-handler.selector}?
- return nativeQueryString.matches("(spellcheck|mlt|query|select|get)\\\\?.*");
+ return nativeQueryString.matches("(suggest|spellcheck|mlt|query|select|get)\\\\?.*");
}
private static void setDefaults(SolrQuery solrQuery, OakSolrConfiguration configuration) {
Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java?rev=1683763&r1=1683762&r2=1683763&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java Fri Jun 5 14:23:19 2015
@@ -24,6 +24,7 @@ import java.util.Deque;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
@@ -57,6 +58,8 @@ import org.apache.solr.client.solrj.resp
import org.apache.solr.client.solrj.response.SpellCheckResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -316,6 +319,37 @@ public class SolrQueryIndex implements F
noDocs = true;
}
+ // handle suggest
+ NamedList<Object> response = queryResponse.getResponse();
+ Map suggest = (Map) response.get("suggest");
+ if (suggest != null) {
+ Set<Map.Entry<String, Object>> suggestEntries = suggest.entrySet();
+ if (!suggestEntries.isEmpty()) {
+ SolrDocument fakeDoc = new SolrDocument();
+ for (Map.Entry<String, Object> suggestor : suggestEntries) {
+ SimpleOrderedMap<Object> suggestionResponses = ((SimpleOrderedMap) suggestor.getValue());
+ for (Map.Entry<String, Object> suggestionResponse : suggestionResponses) {
+ SimpleOrderedMap<Object> suggestionResults = ((SimpleOrderedMap) suggestionResponse.getValue());
+ for (Map.Entry<String, Object> suggestionResult : suggestionResults) {
+ if ("suggestions".equals(suggestionResult.getKey())) {
+ ArrayList<SimpleOrderedMap<Object>> suggestions = ((ArrayList<SimpleOrderedMap<Object>>) suggestionResult.getValue());
+ if (suggestions.isEmpty()) {
+ fakeDoc.addField(QueryImpl.REP_SUGGEST, "[]");
+ }
+ else {
+ for (SimpleOrderedMap<Object> suggestion : suggestions) {
+ fakeDoc.addField(QueryImpl.REP_SUGGEST, "{term=" + suggestion.get("term") + ",weight=" + suggestion.get("weight") + "}");
+ }
+ }
+ }
+ }
+ }
+ }
+ queue.add(new SolrResultRow("/", 1.0, fakeDoc));
+ noDocs = true;
+ }
+ }
+
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("query via {} failed.", solrServer, e);
Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml?rev=1683763&r1=1683762&r2=1683763&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml Fri Jun 5 14:23:19 2015
@@ -115,6 +115,9 @@
<field name="path_des" type="descendent_path" indexed="true" stored="false"/>
<field name="catch_all" type="text_general" indexed="true" stored="false" multiValued="true" termVectors="true"/> <!-- term vectors used for rep:similar -->
<field name=":path" type="string" indexed="true" stored="false" />
+ <field name=":indexed" type="tdate" indexed="true" stored="false" default="NOW" docValues="true"/>
+ <field name=":suggest-weight" type="tint" indexed="false" stored="false" default="1" docValues="true"/>
+ <field name=":suggest" type="string" indexed="true" stored="true" multiValued="true" />
<field name="_version_" type="long" indexed="true" stored="true"/>
<!-- sorting dynamic fields -->
@@ -130,6 +133,8 @@
<copyField source="path_exact" dest="path_des"/>
<copyField source="path_exact" dest="path_child"/>
<copyField source="path_exact" dest=":path"/>
- <copyField source="*" dest="catch_all"/>
+ <copyField source="*" dest="catch_all"/>
+ <copyField source="jcr:title" dest=":suggest"/>
+ <copyField source="jcr:description" dest=":suggest"/>
</schema>
Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/solrconfig.xml?rev=1683763&r1=1683762&r2=1683763&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/solrconfig.xml (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/main/resources/solr/oak/conf/solrconfig.xml Fri Jun 5 14:23:19 2015
@@ -1113,6 +1113,29 @@
-->
</requestHandler>
+
+ <searchComponent name="suggest" class="solr.SuggestComponent">
+ <lst name="suggester">
+ <str name="name">default</str>
+ <str name="lookupImpl">FuzzyLookupFactory</str>
+ <str name="dictionaryImpl">DocumentDictionaryFactory</str>
+ <str name="field">:suggest</str>
+ <str name="weightField">:suggest-weight</str>
+ <str name="suggestAnalyzerFieldType">string</str>
+ </lst>
+ </searchComponent>
+
+ <requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
+ <lst name="defaults">
+ <str name="suggest">true</str>
+ <str name="suggest.count">10</str>
+ </lst>
+ <arr name="components">
+ <str>suggest</str>
+ </arr>
+ </requestHandler>
+
+
<!-- Search Components
Search components are registered to SolrCore and used by
@@ -1207,6 +1230,7 @@
</lst>
<arr name="last-components">
<str>spellcheck</str>
+ <str>suggest</str>
</arr>
</requestHandler>
Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml?rev=1683763&r1=1683762&r2=1683763&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml Fri Jun 5 14:23:19 2015
@@ -120,7 +120,9 @@
<field name="catch_all" type="text_general" indexed="true" stored="false" multiValued="true" termVectors="true"/> <!-- term vectors used for rep:similar -->
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name=":path" type="string" indexed="true" stored="false"/>
- <field name=":indexed" type="tdate" indexed="true" stored="false" default="NOW" docValues="numeric"/>
+ <field name=":indexed" type="tdate" indexed="true" stored="false" default="NOW" docValues="true"/>
+ <field name=":suggest-weight" type="tint" indexed="false" stored="false" default="1" docValues="true"/>
+ <field name=":suggest" type="string" indexed="true" stored="true" multiValued="true" />
<!-- sorting dynamic fields -->
<dynamicField name="*_double_sort" type="tdouble" indexed="false" stored="false" multiValued="false" docValues="true"/>
@@ -135,4 +137,6 @@
<copyField source="path_exact" dest="path_child"/>
<copyField source="path_exact" dest=":path"/>
<copyField source="*" dest="catch_all"/>
+ <copyField source="jcr:title" dest=":suggest"/>
+ <copyField source="jcr:description" dest=":suggest"/>
</schema>
Modified: jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/solrconfig.xml?rev=1683763&r1=1683762&r2=1683763&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/solrconfig.xml (original)
+++ jackrabbit/oak/branches/1.0/oak-solr-core/src/test/resources/solr/oak/conf/solrconfig.xml Fri Jun 5 14:23:19 2015
@@ -935,6 +935,7 @@ current implementation relies on the upd
<!-- append spellchecking to our list of components -->
<arr name="last-components">
<str>spellcheck</str>
+ <str>suggest</str>
</arr>
</requestHandler>
@@ -1146,6 +1147,27 @@ current implementation relies on the upd
-->
</requestHandler>
+ <searchComponent name="suggest" class="solr.SuggestComponent">
+ <lst name="suggester">
+ <str name="name">default</str>
+ <str name="lookupImpl">FuzzyLookupFactory</str>
+ <str name="dictionaryImpl">DocumentDictionaryFactory</str>
+ <str name="field">:suggest</str>
+ <str name="weightField">:suggest-weight</str>
+ <str name="suggestAnalyzerFieldType">string</str>
+ </lst>
+ </searchComponent>
+
+ <requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
+ <lst name="defaults">
+ <str name="suggest">true</str>
+ <str name="suggest.count">10</str>
+ </lst>
+ <arr name="components">
+ <str>suggest</str>
+ </arr>
+ </requestHandler>
+
<!-- Search Components
Search components are registered to SolrCore and used by