SOLR-6365 refactoring and cleanup

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1622384 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2014-09-04 00:16:31 +00:00
parent f46b189256
commit 8306b8a464
5 changed files with 45 additions and 86 deletions

View File

@ -77,6 +77,12 @@ public class UpdateRequestHandler extends ContentStreamHandlerBase {
public void load(SolrQueryRequest req, SolrQueryResponse rsp, public void load(SolrQueryRequest req, SolrQueryResponse rsp,
ContentStream stream, UpdateRequestProcessor processor) throws Exception { ContentStream stream, UpdateRequestProcessor processor) throws Exception {
ContentStreamLoader ldr = pathVsLoaders.get(req.getContext().get("path"));
if(ldr != null){
ldr.load(req,rsp,stream,processor);
return;
}
String type = req.getParams().get(UpdateParams.ASSUME_CONTENT_TYPE); String type = req.getParams().get(UpdateParams.ASSUME_CONTENT_TYPE);
if(type == null) { if(type == null) {
type = stream.getContentType(); type = stream.getContentType();
@ -134,7 +140,7 @@ public class UpdateRequestHandler extends ContentStreamHandlerBase {
invariants = params; invariants = params;
} }
} }
private Map<String ,ContentStreamLoader> pathVsLoaders = new HashMap<>();
protected Map<String,ContentStreamLoader> createDefaultLoaders(NamedList args) { protected Map<String,ContentStreamLoader> createDefaultLoaders(NamedList args) {
SolrParams p = null; SolrParams p = null;
if(args!=null) { if(args!=null) {
@ -147,7 +153,11 @@ public class UpdateRequestHandler extends ContentStreamHandlerBase {
registry.put("application/javabin", new JavabinLoader().init(p) ); registry.put("application/javabin", new JavabinLoader().init(p) );
registry.put("text/csv", registry.get("application/csv") ); registry.put("text/csv", registry.get("application/csv") );
registry.put("text/xml", registry.get("application/xml") ); registry.put("text/xml", registry.get("application/xml") );
registry.put("text/json", registry.get("application/json") ); registry.put("text/json", registry.get("application/json"));
pathVsLoaders.put(JSON_PATH,registry.get("application/json"));
pathVsLoaders.put(DOC_PATH,registry.get("application/json"));
pathVsLoaders.put(CSV_PATH,registry.get("application/csv"));
return registry; return registry;
} }
@ -166,16 +176,18 @@ public class UpdateRequestHandler extends ContentStreamHandlerBase {
public static void addImplicits(List<PluginInfo> implicits) { public static void addImplicits(List<PluginInfo> implicits) {
implicits.add(getPluginInfo("/update",Collections.emptyMap())); implicits.add(getPluginInfo("/update",Collections.emptyMap()));
implicits.add(getPluginInfo("/update/json", singletonMap("update.contentType", "application/json"))); implicits.add(getPluginInfo(JSON_PATH, singletonMap("update.contentType", "application/json")));
implicits.add(getPluginInfo("/update/csv", singletonMap("update.contentType", "application/csv"))); implicits.add(getPluginInfo(CSV_PATH, singletonMap("update.contentType", "application/csv")));
implicits.add(getPluginInfo("/update/json/docs", makeMap("update.contentType", "application/json", "json.command","false"))); implicits.add(getPluginInfo(DOC_PATH, makeMap("update.contentType", "application/json", "json.command","false")));
} }
static PluginInfo getPluginInfo(String name, Map defaults){ static PluginInfo getPluginInfo(String name, Map defaults){
Map m = makeMap("name", name, "class", UpdateRequestHandler.class.getName()); Map m = makeMap("name", name, "class", UpdateRequestHandler.class.getName());
return new PluginInfo("requestHandler", m, new NamedList<>( singletonMap("defaults", new NamedList(defaults))) ,null); return new PluginInfo("requestHandler", m, new NamedList<>( singletonMap("defaults", new NamedList(defaults))) ,null);
} }
public static final String DOC_PATH = "/update/json/docs";
public static final String JSON_PATH = "/update/json";
public static final String CSV_PATH = "/update/csv";
} }

View File

@ -113,14 +113,11 @@ public class JsonLoader extends ContentStreamLoader {
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
void processUpdate() throws IOException void processUpdate() throws IOException
{ {
if("false".equals( req.getParams().get("json.command"))){ String path = (String) req.getContext().get("path");
if(UpdateRequestHandler.DOC_PATH.equals(path) || "false".equals( req.getParams().get("json.command"))){
String split = req.getParams().get("split"); String split = req.getParams().get("split");
if(split != null){ String[] f = req.getParams().getParams("f");
handleSplitMode(split); handleSplitMode(split,f);
} else {
handleStreamingSingleDocs();
}
return; return;
} }
int ev = parser.nextEvent(); int ev = parser.nextEvent();
@ -192,9 +189,9 @@ public class JsonLoader extends ContentStreamLoader {
} }
} }
private void handleSplitMode(String split) throws IOException { private void handleSplitMode(String split, String[] fields) throws IOException {
String[] fields = req.getParams().getParams("f"); if(split == null) split = "/";
req.getCore().getLatestSchema().getDefaultSearchFieldName(); if(fields == null || fields.length ==0) fields = new String[]{"/*"};
final boolean echo = "true".equals( req.getParams().get("echo")); final boolean echo = "true".equals( req.getParams().get("echo"));
JsonRecordReader jsonRecordReader = JsonRecordReader.getInst(split, Arrays.asList(fields)); JsonRecordReader jsonRecordReader = JsonRecordReader.getInst(split, Arrays.asList(fields));
jsonRecordReader.streamRecords(parser,new JsonRecordReader.Handler() { jsonRecordReader.streamRecords(parser,new JsonRecordReader.Handler() {

View File

@ -1049,5 +1049,11 @@
<str name="paramkey">param value</str> <str name="paramkey">param value</str>
</similarity> </similarity>
--> -->
<field name="_text" type="text_general" indexed="true" stored="false" multiValued="true"/>
<field name="_src" type="string" indexed="false" stored="true" multiValued="true"/>
<copyField source="*" dest="_text"/>
</schema> </schema>

View File

@ -858,7 +858,6 @@
<str name="echoParams">explicit</str> <str name="echoParams">explicit</str>
<str name="wt">json</str> <str name="wt">json</str>
<str name="indent">true</str> <str name="indent">true</str>
<str name="df">text</str>
</lst> </lst>
</requestHandler> </requestHandler>
@ -900,7 +899,6 @@
text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4 text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
title^10.0 description^5.0 keywords^5.0 author^2.0 resourcename^1.0 title^10.0 description^5.0 keywords^5.0 author^2.0 resourcename^1.0
</str> </str>
<str name="df">text</str>
<str name="mm">100%</str> <str name="mm">100%</str>
<str name="q.alt">*:*</str> <str name="q.alt">*:*</str>
<str name="rows">10</str> <str name="rows">10</str>
@ -971,58 +969,17 @@
<str>spellcheck</str> <str>spellcheck</str>
</arr> </arr>
</requestHandler> </requestHandler>
<paramSet path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
<lst name="defaults">
<str name="df">_text</str>
</lst>
</paramSet>
<paramSet path="/update/**">
<!-- Update Request Handler.
http://wiki.apache.org/solr/UpdateXmlMessages
The canonical Request Handler for Modifying the Index through
commands specified using XML, JSON, CSV, or JAVABIN
Note: Since solr1.1 requestHandlers requires a valid content
type header if posted in the body. For example, curl now
requires: -H 'Content-type:text/xml; charset=utf-8'
To override the request content type and force a specific
Content-type, use the request parameter:
?update.contentType=text/csv
This handler will pick a response format to match the input
if the 'wt' parameter is not explicit
-->
<requestHandler name="/update" class="solr.UpdateRequestHandler">
<!-- See below for information on defining
updateRequestProcessorChains that can be used by name
on each Update Request
-->
<lst name="defaults"> <lst name="defaults">
<str name="update.chain">add-unknown-fields-to-the-schema</str> <str name="update.chain">add-unknown-fields-to-the-schema</str>
</lst> </lst>
</requestHandler> </paramSet>
<requestHandler name="/update/json" class="solr.UpdateRequestHandler">
<!-- See below for information on defining
updateRequestProcessorChains that can be used by name
on each Update Request
-->
<lst name="defaults">
<str name="update.contentType">application/json</str>
<str name="update.chain">add-unknown-fields-to-the-schema</str>
</lst>
</requestHandler>
<requestHandler name="/update/json/docs" class="solr.UpdateRequestHandler">
<!-- See below for information on defining
updateRequestProcessorChains that can be used by name
on each Update Request
-->
<lst name="defaults">
<str name="update.contentType">application/json</str>
<str name="update.chain">add-unknown-fields-to-the-schema</str>
<bool name="json.command">false</bool>
</lst>
</requestHandler>
<!-- Solr Cell Update Request Handler <!-- Solr Cell Update Request Handler
@ -1335,7 +1292,6 @@
--> -->
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy"> <requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults"> <lst name="defaults">
<str name="df">text</str>
<!-- Solr will use suggestions from both the 'default' spellchecker <!-- Solr will use suggestions from both the 'default' spellchecker
and from the 'wordbreak' spellchecker and combine them. and from the 'wordbreak' spellchecker and combine them.
collations (re-written queries) can include a combination of collations (re-written queries) can include a combination of
@ -1372,7 +1328,6 @@
--> -->
<requestHandler name="/tvrh" class="solr.SearchHandler" startup="lazy"> <requestHandler name="/tvrh" class="solr.SearchHandler" startup="lazy">
<lst name="defaults"> <lst name="defaults">
<str name="df">text</str>
<bool name="tv">true</bool> <bool name="tv">true</bool>
</lst> </lst>
<arr name="last-components"> <arr name="last-components">
@ -1421,7 +1376,6 @@
<requestHandler name="/elevate" class="solr.SearchHandler" startup="lazy"> <requestHandler name="/elevate" class="solr.SearchHandler" startup="lazy">
<lst name="defaults"> <lst name="defaults">
<str name="echoParams">explicit</str> <str name="echoParams">explicit</str>
<str name="df">text</str>
</lst> </lst>
<arr name="last-components"> <arr name="last-components">
<str>elevator</str> <str>elevator</str>

View File

@ -826,7 +826,6 @@
<lst name="defaults"> <lst name="defaults">
<str name="echoParams">explicit</str> <str name="echoParams">explicit</str>
<int name="rows">10</int> <int name="rows">10</int>
<str name="df">text</str>
</lst> </lst>
<!-- In addition to defaults, "appends" params can be specified <!-- In addition to defaults, "appends" params can be specified
to identify values which should be appended to the list of to identify values which should be appended to the list of
@ -959,7 +958,6 @@
text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4 text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
title^10.0 description^5.0 keywords^5.0 author^2.0 resourcename^1.0 title^10.0 description^5.0 keywords^5.0 author^2.0 resourcename^1.0
</str> </str>
<str name="df">text</str>
<str name="mm">100%</str> <str name="mm">100%</str>
<str name="q.alt">*:*</str> <str name="q.alt">*:*</str>
<str name="rows">10</str> <str name="rows">10</str>
@ -1052,18 +1050,13 @@
This handler will pick a response format to match the input This handler will pick a response format to match the input
if the 'wt' parameter is not explicit if the 'wt' parameter is not explicit
--> -->
<requestHandler name="/update" class="solr.UpdateRequestHandler"> <!--<requestHandler name="/update" class="solr.UpdateRequestHandler">
<!-- See below for information on defining </requestHandler>-->
updateRequestProcessorChains that can be used by name <paramSet path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
on each Update Request <lst name="defaults">
--> <str name="df">text</str>
<!-- </lst>
<lst name="defaults"> </paramSet>
<str name="update.chain">dedupe</str>
</lst>
-->
</requestHandler>
<!-- The following are implicitly added <!-- The following are implicitly added
<requestHandler name="/update/json" class="solr.UpdateRequestHandler"> <requestHandler name="/update/json" class="solr.UpdateRequestHandler">
<lst name="defaults"> <lst name="defaults">
@ -1403,7 +1396,6 @@
--> -->
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy"> <requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults"> <lst name="defaults">
<str name="df">text</str>
<!-- Solr will use suggestions from both the 'default' spellchecker <!-- Solr will use suggestions from both the 'default' spellchecker
and from the 'wordbreak' spellchecker and combine them. and from the 'wordbreak' spellchecker and combine them.
collations (re-written queries) can include a combination of collations (re-written queries) can include a combination of
@ -1460,7 +1452,6 @@
--> -->
<requestHandler name="/tvrh" class="solr.SearchHandler" startup="lazy"> <requestHandler name="/tvrh" class="solr.SearchHandler" startup="lazy">
<lst name="defaults"> <lst name="defaults">
<str name="df">text</str>
<bool name="tv">true</bool> <bool name="tv">true</bool>
</lst> </lst>
<arr name="last-components"> <arr name="last-components">
@ -1606,7 +1597,6 @@
<requestHandler name="/elevate" class="solr.SearchHandler" startup="lazy"> <requestHandler name="/elevate" class="solr.SearchHandler" startup="lazy">
<lst name="defaults"> <lst name="defaults">
<str name="echoParams">explicit</str> <str name="echoParams">explicit</str>
<str name="df">text</str>
</lst> </lst>
<arr name="last-components"> <arr name="last-components">
<str>elevator</str> <str>elevator</str>