You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ho...@apache.org on 2007/01/29 21:33:25 UTC
svn commit: r501174 [1/2] - in /lucene/solr/trunk: ./ example/solr/conf/
lib/ src/java/org/apache/solr/core/ src/java/org/apache/solr/handler/
src/java/org/apache/solr/request/ src/java/org/apache/solr/util/
src/test/org/apache/solr/servlet/ src/test/t...
Author: hossman
Date: Mon Jan 29 12:33:21 2007
New Revision: 501174
URL: http://svn.apache.org/viewvc?view=rev&rev=501174
Log:
SOLR-104 - Support for Update Plugins: giving RequestHandlers access to ContentStreams, new URL structure allowing for more RESTful URLs, common baseclass for RequestHandlers, refactoring existing XML based updates into a RequestHandler
Added:
lucene/solr/trunk/lib/commons-fileupload-20070107.jar (with props)
lucene/solr/trunk/lib/commons-io-1.2.jar (with props)
lucene/solr/trunk/src/java/org/apache/solr/handler/
lucene/solr/trunk/src/java/org/apache/solr/handler/CommitRequestHandler.java (with props)
lucene/solr/trunk/src/java/org/apache/solr/handler/DumpRequestHandler.java (with props)
lucene/solr/trunk/src/java/org/apache/solr/handler/RequestHandlerBase.java (with props)
lucene/solr/trunk/src/java/org/apache/solr/handler/UpdateParams.java (with props)
lucene/solr/trunk/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java (with props)
lucene/solr/trunk/src/java/org/apache/solr/request/ContentStream.java (with props)
lucene/solr/trunk/src/test/org/apache/solr/servlet/
lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java (with props)
lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java (with props)
lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrRequestParsers.java (with props)
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/example/solr/conf/solrconfig.xml
lucene/solr/trunk/src/java/org/apache/solr/core/Config.java
lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
lucene/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java (contents, props changed)
lucene/solr/trunk/src/java/org/apache/solr/request/SolrParams.java
lucene/solr/trunk/src/java/org/apache/solr/request/SolrQueryRequest.java
lucene/solr/trunk/src/java/org/apache/solr/request/SolrQueryRequestBase.java
lucene/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java
lucene/solr/trunk/src/java/org/apache/solr/util/TestHarness.java
lucene/solr/trunk/src/test/test-files/solr/conf/solrconfig.xml
lucene/solr/trunk/src/webapp/WEB-INF/web.xml
lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrServlet.java
lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrUpdateServlet.java
Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Mon Jan 29 12:33:21 2007
@@ -60,6 +60,14 @@
7. SOLR-107: JAVA API: Change NamedList to use Java5 generics
and implement Iterable<Map.Entry> (Ryan McKinley via yonik)
+ 8. SOLR-104: Support for "Update Plugins" -- RequestHandlers that want
+ access to streams of data for doing updates. ContentStreams can come
+ from the raw POST body, multi-part form data, or remote URLs.
+ Included in this change is a new SlrDispatchFilter that allows
+ RequestHandlers registered with names that begin with a "/" to be
+ accessed using a URL structure based on that name.
+ (Ryan McKinley via hossman)
+
Changes in runtime behavior
1. Highlighting using DisMax will only pick up terms from the main
user query, not boost or filter queries (klaas).
Modified: lucene/solr/trunk/example/solr/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/example/solr/conf/solrconfig.xml?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/example/solr/conf/solrconfig.xml (original)
+++ lucene/solr/trunk/example/solr/conf/solrconfig.xml Mon Jan 29 12:33:21 2007
@@ -222,7 +222,9 @@
</query>
-
+ <!--Make sure your system has some authentication before enabling remote streaming! -->
+ <requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048" />
+
<!-- requestHandler plugins... incoming queries will be dispatched to the
correct handler based on the qt (query type) param matching the
name of registered handlers.
@@ -337,6 +339,22 @@
2<-1 5<-2 6<90%
</str>
</requestHandler>
+
+
+ <!-- Standard update plugin. If we put this on /update, it will get all the new goodness -->
+ <requestHandler name="/update/xml" class="solr.XmlUpdateRequestHandler" >
+ <!--
+ <lst name="defaults">
+ <str name="name">value</str>
+ </lst>
+ -->
+ </requestHandler>
+
+ <requestHandler name="/debug/dump" class="solr.DumpRequestHandler" />
+
+ <!-- NOTE, /update is mapped to a servlet, we can have the filter handle requests off that! -->
+ <requestHandler name="/update/commit" class="solr.CommitRequestHandler" />
+
<!-- queryResponseWriter plugins... query responses will be written using the
writer specified by the 'wt' request parameter matching the name of a registered
Added: lucene/solr/trunk/lib/commons-fileupload-20070107.jar
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/lib/commons-fileupload-20070107.jar?view=auto&rev=501174
==============================================================================
Binary file - no diff available.
Propchange: lucene/solr/trunk/lib/commons-fileupload-20070107.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lucene/solr/trunk/lib/commons-io-1.2.jar
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/lib/commons-io-1.2.jar?view=auto&rev=501174
==============================================================================
Binary file - no diff available.
Propchange: lucene/solr/trunk/lib/commons-io-1.2.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: lucene/solr/trunk/src/java/org/apache/solr/core/Config.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/Config.java?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/Config.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/Config.java Mon Jan 29 12:33:21 2007
@@ -181,7 +181,7 @@
private static final String project = "solr";
private static final String base = "org.apache" + "." + project;
- private static final String[] packages = {"","analysis.","schema.","search.","update.","core.","request.","util."};
+ private static final String[] packages = {"","analysis.","schema.","search.","update.","core.","request.","handler.","util."};
public static Class findClass(String cname, String... subpackages) {
ClassLoader loader = getClassLoader();
Modified: lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java Mon Jan 29 12:33:21 2007
@@ -21,6 +21,7 @@
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
+import org.apache.solr.handler.XmlUpdateRequestHandler;
import org.apache.solr.request.*;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SchemaField;
@@ -41,7 +42,10 @@
import javax.xml.xpath.XPathConstants;
import java.io.File;
import java.io.IOException;
+import java.io.PrintWriter;
import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
import java.io.Writer;
import java.util.*;
import java.util.concurrent.Callable;
@@ -241,6 +245,18 @@
void finalizer() { close(); }
+ ////////////////////////////////////////////////////////////////////////////////
+ // Update Handler
+ ////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * RequestHandlers need access to the updateHandler so they can all talk to the
+ * same RAM indexer.
+ */
+ public UpdateHandler getUpdateHandler()
+ {
+ return updateHandler;
+ }
////////////////////////////////////////////////////////////////////////////////
// Searcher Control
@@ -589,14 +605,7 @@
}
-
- public void execute(SolrQueryRequest req, SolrQueryResponse rsp) {
- SolrRequestHandler handler = getRequestHandler(req.getQueryType());
- if (handler==null) {
- log.warning("Unknown Request Handler '" + req.getQueryType() +"' :" + req);
- throw new SolrException(400,"Unknown Request Handler '" + req.getQueryType() + "'", true);
- }
-
+ public void execute(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp) {
// setup response header and handle request
final NamedList responseHeader = new NamedList();
rsp.add("responseHeader", responseHeader);
@@ -606,6 +615,16 @@
log.info(req.getParamString()+ " 0 "+
(int)(rsp.getEndTime() - req.getStartTime()));
}
+
+ @Deprecated
+ public void execute(SolrQueryRequest req, SolrQueryResponse rsp) {
+ SolrRequestHandler handler = getRequestHandler(req.getQueryType());
+ if (handler==null) {
+ log.warning("Unknown Request Handler '" + req.getQueryType() +"' :" + req);
+ throw new SolrException(400,"Unknown Request Handler '" + req.getQueryType() + "'", true);
+ }
+ execute(handler, req, rsp);
+ }
protected void setResponseHeaderValues(NamedList responseHeader,SolrQueryRequest req, SolrQueryResponse rsp) {
// TODO should check that responseHeader has not been replaced by handler
@@ -625,344 +644,12 @@
}
}
- XmlPullParserFactory factory;
- {
- try {
- factory = XmlPullParserFactory.newInstance();
- } catch (XmlPullParserException e) {
- throw new RuntimeException(e);
- }
- factory.setNamespaceAware(false);
- }
-
-
- private int findNextTag(XmlPullParser xpp, String tag) throws XmlPullParserException, IOException {
- int eventType;
- while((eventType=xpp.next()) != XmlPullParser.END_DOCUMENT) {
- if(eventType == XmlPullParser.START_TAG) {
- if (tag.equals(xpp.getName())) break;
- }
- }
- return eventType;
- }
-
-
- public void update(Reader reader, Writer writer) {
-
- // TODO: add param to specify maximum time to commit?
-
- // todo - might be nice to separate command parsing w/ a factory
- // then new commands could be added w/o risk to old ones
-
-
- XmlPullParser xpp = null;
- try {
- xpp = factory.newPullParser();
- } catch (XmlPullParserException e) {
- throw new RuntimeException(e);
- }
-
- long startTime=System.currentTimeMillis();
-
- try {
- xpp.setInput(reader);
- xpp.nextTag();
-
- String currTag = xpp.getName();
- if ("add".equals(currTag)) {
- log.finest("SolrCore.update(add)");
- AddUpdateCommand cmd = new AddUpdateCommand();
- cmd.allowDups=false; // the default
-
- int status=0;
- boolean pendingAttr=false, committedAttr=false;
- int attrcount = xpp.getAttributeCount();
- for (int i=0; i<attrcount; i++) {
- String attrName = xpp.getAttributeName(i);
- String attrVal = xpp.getAttributeValue(i);
- if ("allowDups".equals(attrName)) {
- cmd.allowDups = StrUtils.parseBoolean(attrVal);
- } else if ("overwritePending".equals(attrName)) {
- cmd.overwritePending = StrUtils.parseBoolean(attrVal);
- pendingAttr=true;
- } else if ("overwriteCommitted".equals(attrName)) {
- cmd.overwriteCommitted = StrUtils.parseBoolean(attrVal);
- committedAttr=true;
- } else {
- log.warning("Unknown attribute id in add:" + attrName);
- }
- }
-
- //set defaults for committed and pending based on allowDups value
- if (!pendingAttr) cmd.overwritePending=!cmd.allowDups;
- if (!committedAttr) cmd.overwriteCommitted=!cmd.allowDups;
-
- DocumentBuilder builder = new DocumentBuilder(schema);
- SchemaField uniqueKeyField = schema.getUniqueKeyField();
- int eventType=0;
- // accumulate responses
- List<String> added = new ArrayList<String>(10);
- while(true) {
- // this may be our second time through the loop in the case
- // that there are multiple docs in the add... so make sure that
- // objects can handle that.
-
- cmd.indexedId = null; // reset the id for this add
-
- if (eventType !=0) {
- eventType=xpp.getEventType();
- if (eventType==XmlPullParser.END_DOCUMENT) break;
- }
- // eventType = xpp.next();
- eventType = xpp.nextTag();
- if (eventType == XmlPullParser.END_TAG || eventType == XmlPullParser.END_DOCUMENT) break; // should match </add>
-
- readDoc(builder,xpp);
- builder.endDoc();
- cmd.doc = builder.getDoc();
- log.finest("adding doc...");
- updateHandler.addDoc(cmd);
- String docId = null;
- if (uniqueKeyField!=null)
- docId = schema.printableUniqueKey(cmd.doc);
- added.add(docId);
-
- } // end while
- // write log and result
- StringBuilder out = new StringBuilder();
- for (String docId: added)
- if(docId != null)
- out.append(docId + ",");
- String outMsg = out.toString();
- if(outMsg.length() > 0)
- outMsg = outMsg.substring(0, outMsg.length() - 1);
- log.info("added id={" + outMsg + "} in " + (System.currentTimeMillis()-startTime) + "ms");
- writer.write("<result status=\"0\"></result>");
-
- } // end add
-
- else if ("commit".equals(currTag) || "optimize".equals(currTag)) {
- log.finest("parsing "+currTag);
- try {
- CommitUpdateCommand cmd = new CommitUpdateCommand("optimize".equals(currTag));
-
- boolean sawWaitSearcher=false, sawWaitFlush=false;
- int attrcount = xpp.getAttributeCount();
- for (int i=0; i<attrcount; i++) {
- String attrName = xpp.getAttributeName(i);
- String attrVal = xpp.getAttributeValue(i);
- if ("waitFlush".equals(attrName)) {
- cmd.waitFlush = StrUtils.parseBoolean(attrVal);
- sawWaitFlush=true;
- } else if ("waitSearcher".equals(attrName)) {
- cmd.waitSearcher = StrUtils.parseBoolean(attrVal);
- sawWaitSearcher=true;
- } else {
- log.warning("unexpected attribute commit/@" + attrName);
- }
- }
-
- // If waitFlush is specified and waitSearcher wasn't, then
- // clear waitSearcher.
- if (sawWaitFlush && !sawWaitSearcher) {
- cmd.waitSearcher=false;
- }
-
- updateHandler.commit(cmd);
- if ("optimize".equals(currTag)) {
- log.info("optimize 0 "+(System.currentTimeMillis()-startTime));
- }
- else {
- log.info("commit 0 "+(System.currentTimeMillis()-startTime));
- }
- while (true) {
- int eventType = xpp.nextTag();
- if (eventType == XmlPullParser.END_TAG) break; // match </commit>
- }
- writer.write("<result status=\"0\"></result>");
- } catch (SolrException e) {
- log(e);
- if ("optimize".equals(currTag)) {
- log.info("optimize "+e.code+" "+
- (System.currentTimeMillis()-startTime));
- }
- else {
- log.info("commit "+e.code+" "+
- (System.currentTimeMillis()-startTime));
- }
- writeResult(writer,e);
- } catch (Exception e) {
- SolrException.log(log, "Exception during commit/optimize",e);
- writeResult(writer,e);
- }
- } // end commit
-
- else if ("delete".equals(currTag)) {
- log.finest("parsing delete");
- try {
- DeleteUpdateCommand cmd = new DeleteUpdateCommand();
- cmd.fromPending=true;
- cmd.fromCommitted=true;
- int attrcount = xpp.getAttributeCount();
- for (int i=0; i<attrcount; i++) {
- String attrName = xpp.getAttributeName(i);
- String attrVal = xpp.getAttributeValue(i);
- if ("fromPending".equals(attrName)) {
- cmd.fromPending = StrUtils.parseBoolean(attrVal);
- } else if ("fromCommitted".equals(attrName)) {
- cmd.fromCommitted = StrUtils.parseBoolean(attrVal);
- } else {
- log.warning("unexpected attribute delete/@" + attrName);
- }
- }
-
- int eventType = xpp.nextTag();
- currTag = xpp.getName();
- String val = xpp.nextText();
-
- if ("id".equals(currTag)) {
- cmd.id = val;
- updateHandler.delete(cmd);
- log.info("delete(id " + val + ") 0 " +
- (System.currentTimeMillis()-startTime));
- } else if ("query".equals(currTag)) {
- cmd.query = val;
- updateHandler.deleteByQuery(cmd);
- log.info("deleteByQuery(query " + val + ") 0 " +
- (System.currentTimeMillis()-startTime));
- } else {
- log.warning("unexpected XML tag /delete/"+currTag);
- throw new SolrException(400,"unexpected XML tag /delete/"+currTag);
- }
-
- writer.write("<result status=\"0\"></result>");
-
- while (xpp.nextTag() != XmlPullParser.END_TAG);
-
- } catch (SolrException e) {
- log(e);
- log.info("delete "+e.code+" "+(System.currentTimeMillis()-startTime));
- writeResult(writer,e);
- } catch (Exception e) {
- log(e);
- writeResult(writer,e);
- }
- } // end delete
-
-
- } catch (XmlPullParserException e) {
- log(e);
- writeResult(writer,e);
- } catch (IOException e) {
- log(e);
- writeResult(writer,e);
- } catch (SolrException e) {
- log(e);
- log.info("update "+e.code+" "+(System.currentTimeMillis()-startTime));
- writeResult(writer,e);
- } catch (Throwable e) {
- log(e);
- writeResult(writer,e);
- }
-
- }
-
- private void readDoc(DocumentBuilder builder, XmlPullParser xpp) throws IOException, XmlPullParserException {
- // xpp should be at <doc> at this point
-
- builder.startDoc();
-
- int attrcount = xpp.getAttributeCount();
- float docBoost = 1.0f;
-
- for (int i=0; i<attrcount; i++) {
- String attrName = xpp.getAttributeName(i);
- String attrVal = xpp.getAttributeValue(i);
- if ("boost".equals(attrName)) {
- docBoost = Float.parseFloat(attrVal);
- builder.setBoost(docBoost);
- } else {
- log.warning("Unknown attribute doc/@" + attrName);
- }
- }
- if (docBoost != 1.0f) builder.setBoost(docBoost);
-
- // while (findNextTag(xpp,"field") != XmlPullParser.END_DOCUMENT) {
-
- while(true) {
- int eventType = xpp.nextTag();
- if (eventType == XmlPullParser.END_TAG) break; // </doc>
-
- String tname=xpp.getName();
- // System.out.println("FIELD READER AT TAG " + tname);
-
- if (!"field".equals(tname)) {
- log.warning("unexpected XML tag doc/"+tname);
- throw new SolrException(400,"unexpected XML tag doc/"+tname);
- }
-
- //
- // get field name and parse field attributes
- //
- attrcount = xpp.getAttributeCount();
- String name=null;
- float boost=1.0f;
- boolean isNull=false;
-
- for (int i=0; i<attrcount; i++) {
- String attrName = xpp.getAttributeName(i);
- String attrVal = xpp.getAttributeValue(i);
- if ("name".equals(attrName)) {
- name=attrVal;
- } else if ("boost".equals(attrName)) {
- boost=Float.parseFloat(attrVal);
- } else if ("null".equals(attrName)) {
- isNull=StrUtils.parseBoolean(attrVal);
- } else {
- log.warning("Unknown attribute doc/field/@" + attrName);
- }
- }
-
- // now get the field value
- String val = xpp.nextText(); // todo... text event for <field></field>???
- // need this line for isNull???
- // Don't add fields marked as null (for now at least)
- if (!isNull) {
- if (boost != 1.0f) {
- builder.addField(name,val,boost);
- } else {
- builder.addField(name,val);
- }
- }
-
- // do I have to do a nextTag here to read the end_tag?
-
- } // end field loop
-
- }
final public static void log(Throwable e) {
SolrException.logOnce(log,null,e);
}
-
- final static void writeResult(Writer out, SolrException e) {
- try {
- XML.writeXML(out,"result",e.getMessage(),"status",e.code());
- } catch (Exception ee) {
- log.severe("Error writing to putput stream: "+ee);
- }
- }
-
- final static void writeResult(Writer out, Throwable e) {
- try {
- XML.writeXML(out,"result",SolrException.toStr(e),"status","1");
- } catch (Exception ee) {
- log.severe("Error writing to putput stream: "+ee);
- }
- }
-
private QueryResponseWriter defaultResponseWriter;
@@ -1030,6 +717,7 @@
return getQueryResponseWriter(request.getParam("wt"));
}
}
+
Added: lucene/solr/trunk/src/java/org/apache/solr/handler/CommitRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/CommitRequestHandler.java?view=auto&rev=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/CommitRequestHandler.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/CommitRequestHandler.java Mon Jan 29 12:33:21 2007
@@ -0,0 +1,71 @@
+/**
+ * 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.
+ */
+
+package org.apache.solr.handler;
+
+import java.io.IOException;
+
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.SolrParams;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrQueryResponse;
+import org.apache.solr.update.CommitUpdateCommand;
+
+public class CommitRequestHandler extends RequestHandlerBase
+{
+ @Override
+ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException
+ {
+ SolrParams params = req.getParams();
+
+ boolean optimize = params.getBool( UpdateParams.OPTIMIZE, false );
+ CommitUpdateCommand cmd = new CommitUpdateCommand( optimize );
+ cmd.waitFlush = params.getBool( UpdateParams.WAIT_FLUSH, cmd.waitFlush );
+ cmd.waitSearcher = params.getBool( UpdateParams.WAIT_SEARCHER, cmd.waitSearcher );
+
+ SolrCore.getSolrCore().getUpdateHandler().commit( cmd );
+
+ if( optimize ) {
+ rsp.add( "optimize", "true" );
+ }
+ else {
+ rsp.add( "commit", "true" );
+ }
+ }
+
+ //////////////////////// SolrInfoMBeans methods //////////////////////
+
+ @Override
+ public String getDescription() {
+ return "Commit all pending documents";
+ }
+
+ @Override
+ public String getVersion() {
+ return "$Revision:$";
+ }
+
+ @Override
+ public String getSourceId() {
+ return "$Id:$";
+ }
+
+ @Override
+ public String getSource() {
+ return "$URL:$";
+ }
+}
Propchange: lucene/solr/trunk/src/java/org/apache/solr/handler/CommitRequestHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/solr/trunk/src/java/org/apache/solr/handler/CommitRequestHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: lucene/solr/trunk/src/java/org/apache/solr/handler/DumpRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/DumpRequestHandler.java?view=auto&rev=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/DumpRequestHandler.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/DumpRequestHandler.java Mon Jan 29 12:33:21 2007
@@ -0,0 +1,85 @@
+/**
+ * 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.
+ */
+
+package org.apache.solr.handler;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.solr.request.ContentStream;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrQueryResponse;
+import org.apache.solr.util.NamedList;
+
+public class DumpRequestHandler extends RequestHandlerBase
+{
+ @Override
+ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException
+ {
+ // Show params
+ rsp.add( "params", req.getParams().toNamedList() );
+
+ // Write the streams...
+ if( req.getContentStreams() != null ) {
+ NamedList<Object> streams = new NamedList<Object>();
+ // Cycle through each stream
+ for( ContentStream content : req.getContentStreams() ) {
+ NamedList<Object> stream = new NamedList<Object>();
+ stream.add( "name", content.getName() );
+ stream.add( "fieldName", content.getSourceInfo() );
+ stream.add( "size", content.getSize() );
+ stream.add( "contentType", content.getContentType() );
+ stream.add( "stream", IOUtils.toString( content.getStream() ) );
+ streams.add( "stream", stream );
+ }
+ rsp.add( "streams", streams );
+ }
+
+ // Show the context
+ Map<Object,Object> context = req.getContext();
+ if( context != null ) {
+ NamedList ctx = new NamedList();
+ for( Map.Entry<Object,Object> entry : context.entrySet() ) {
+ ctx.add( entry.getKey().toString(), entry.getValue() );
+ }
+ rsp.add( "context", ctx );
+ }
+ }
+
+ //////////////////////// SolrInfoMBeans methods //////////////////////
+
+ @Override
+ public String getDescription() {
+ return "Dump handler (debug)";
+ }
+
+ @Override
+ public String getVersion() {
+ return "$Revision:$";
+ }
+
+ @Override
+ public String getSourceId() {
+ return "$Id:$";
+ }
+
+ @Override
+ public String getSource() {
+ return "$URL:$";
+ }
+}
Propchange: lucene/solr/trunk/src/java/org/apache/solr/handler/DumpRequestHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/solr/trunk/src/java/org/apache/solr/handler/DumpRequestHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: lucene/solr/trunk/src/java/org/apache/solr/handler/RequestHandlerBase.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/RequestHandlerBase.java?view=auto&rev=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/RequestHandlerBase.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/RequestHandlerBase.java Mon Jan 29 12:33:21 2007
@@ -0,0 +1,113 @@
+/**
+ * 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.
+ */
+
+package org.apache.solr.handler;
+
+import java.net.URL;
+
+import org.apache.solr.core.SolrException;
+import org.apache.solr.core.SolrInfoMBean;
+import org.apache.solr.request.SolrParams;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrQueryResponse;
+import org.apache.solr.request.SolrRequestHandler;
+import org.apache.solr.util.NamedList;
+import org.apache.solr.util.SolrPluginUtils;
+
+/**
+ *
+ */
+public abstract class RequestHandlerBase implements SolrRequestHandler, SolrInfoMBean {
+
+ // statistics
+ // TODO: should we bother synchronizing these, or is an off-by-one error
+ // acceptable every million requests or so?
+ long numRequests;
+ long numErrors;
+ protected SolrParams defaults;
+ protected SolrParams appends;
+ protected SolrParams invariants;
+
+ /** shorten the class references for utilities */
+ private static class U extends SolrPluginUtils {
+ /* :NOOP */
+ }
+
+ public void init(NamedList args) {
+ // Copied from StandardRequestHandler
+ if( args != null ) {
+ Object o = args.get("defaults");
+ if (o != null && o instanceof NamedList) {
+ defaults = SolrParams.toSolrParams((NamedList)o);
+ }
+ o = args.get("appends");
+ if (o != null && o instanceof NamedList) {
+ appends = SolrParams.toSolrParams((NamedList)o);
+ }
+ o = args.get("invariants");
+ if (o != null && o instanceof NamedList) {
+ invariants = SolrParams.toSolrParams((NamedList)o);
+ }
+ }
+ }
+
+ public abstract void handleRequestBody( SolrQueryRequest req, SolrQueryResponse rsp ) throws Exception;
+
+ public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
+ numRequests++;
+
+ try {
+ U.setDefaults(req,defaults,appends,invariants);
+ handleRequestBody( req, rsp );
+ }
+ catch( SolrException se ) {
+ numErrors++;
+ throw se;
+ }
+ catch( Exception e) {
+ numErrors++;
+ }
+ }
+
+
+ //////////////////////// SolrInfoMBeans methods //////////////////////
+
+ public String getName() {
+ return this.getClass().getName();
+ }
+
+ public abstract String getDescription();
+ public abstract String getSourceId();
+ public abstract String getSource();
+ public abstract String getVersion();
+
+ public Category getCategory() {
+ return Category.QUERYHANDLER;
+ }
+
+ public URL[] getDocs() {
+ return null; // this can be overridden, but not required
+ }
+
+ public NamedList getStatistics() {
+ NamedList lst = new NamedList();
+ lst.add("requests", numRequests);
+ lst.add("errors", numErrors);
+ return lst;
+ }
+}
+
Propchange: lucene/solr/trunk/src/java/org/apache/solr/handler/RequestHandlerBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/solr/trunk/src/java/org/apache/solr/handler/UpdateParams.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/UpdateParams.java?view=auto&rev=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/UpdateParams.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/UpdateParams.java Mon Jan 29 12:33:21 2007
@@ -0,0 +1,39 @@
+/**
+ * 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.
+ */
+
+package org.apache.solr.handler;
+
+/**
+ * A collection of params used by Update handlers
+ */
+public interface UpdateParams
+{
+ /** wait till the command has flushed */
+ public static String WAIT_FLUSH = "waitFlush";
+
+ /** wait for the search to warm up */
+ public static String WAIT_SEARCHER = "waitSearcher";
+
+ /** overwrite indexing fields */
+ public static String OVERWRITE = "overwrite";
+
+ /** Commit everything after the command completes */
+ public static String COMMIT = "commit";
+
+ /** Commit everything after the command completes */
+ public static String OPTIMIZE = "optimize";
+}
Propchange: lucene/solr/trunk/src/java/org/apache/solr/handler/UpdateParams.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/solr/trunk/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java?view=auto&rev=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java Mon Jan 29 12:33:21 2007
@@ -0,0 +1,399 @@
+/**
+ * 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.
+ */
+
+package org.apache.solr.handler;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.core.SolrException;
+import org.apache.solr.request.ContentStream;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrQueryResponse;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.schema.SchemaField;
+import org.apache.solr.servlet.SolrServlet;
+import org.apache.solr.update.AddUpdateCommand;
+import org.apache.solr.update.CommitUpdateCommand;
+import org.apache.solr.update.DeleteUpdateCommand;
+import org.apache.solr.update.DocumentBuilder;
+import org.apache.solr.update.UpdateHandler;
+import org.apache.solr.util.NamedList;
+import org.apache.solr.util.StrUtils;
+import org.apache.solr.util.XML;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlPullParserFactory;
+
+public class XmlUpdateRequestHandler extends RequestHandlerBase
+{
+ public static Logger log = Logger.getLogger(XmlUpdateRequestHandler.class.getName());
+
+ private XmlPullParserFactory factory;
+
+ // This must be called AFTER solrCore has initalized!
+ // otherwise you get a big bad error loop
+ public void init(NamedList args)
+ {
+ super.init( args );
+
+ try {
+ factory = XmlPullParserFactory.newInstance();
+ factory.setNamespaceAware(false);
+ }
+ catch (XmlPullParserException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ // TODO - this should be a general utility in another class
+ public static String getCharsetFromContentType( String contentType )
+ {
+ if( contentType != null ) {
+ int idx = contentType.toLowerCase().indexOf( "charset=" );
+ if( idx > 0 ) {
+ return contentType.substring( idx + "charset=".length() ).trim();
+ }
+ }
+ return null;
+ }
+
+
+ @Override
+ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
+ {
+ Iterable<ContentStream> streams = req.getContentStreams();
+ if( streams == null ) {
+ throw new SolrException( 400, "missing content stream" );
+ }
+
+
+ // Cycle through each stream
+ for( ContentStream stream : req.getContentStreams() ) {
+ String charset = getCharsetFromContentType( stream.getContentType() );
+ Reader reader = null;
+ if( charset == null ) {
+ reader = new InputStreamReader( stream.getStream() );
+ }
+ else {
+ reader = new InputStreamReader( stream.getStream(), charset );
+ }
+ rsp.add( "update", this.update( reader ) );
+
+ // Make sure its closed
+ try { reader.close(); } catch( Exception ex ){}
+ }
+ }
+
+
+ public NamedList update( Reader reader ) throws Exception
+ {
+ SolrCore core = SolrCore.getSolrCore();
+ IndexSchema schema = core.getSchema();
+ UpdateHandler updateHandler = core.getUpdateHandler();
+
+ // TODO: What results should be returned?
+ NamedList res = new NamedList();
+
+ XmlPullParser xpp = factory.newPullParser();
+ long startTime=System.currentTimeMillis();
+
+ xpp.setInput(reader);
+ xpp.nextTag();
+
+ String currTag = xpp.getName();
+ if ("add".equals(currTag)) {
+ log.finest("SolrCore.update(add)");
+ AddUpdateCommand cmd = new AddUpdateCommand();
+ cmd.allowDups=false; // the default
+
+ int status=0;
+ boolean pendingAttr=false, committedAttr=false;
+ int attrcount = xpp.getAttributeCount();
+ for (int i=0; i<attrcount; i++) {
+ String attrName = xpp.getAttributeName(i);
+ String attrVal = xpp.getAttributeValue(i);
+ if ("allowDups".equals(attrName)) {
+ cmd.allowDups = StrUtils.parseBoolean(attrVal);
+ } else if ("overwritePending".equals(attrName)) {
+ cmd.overwritePending = StrUtils.parseBoolean(attrVal);
+ pendingAttr=true;
+ } else if ("overwriteCommitted".equals(attrName)) {
+ cmd.overwriteCommitted = StrUtils.parseBoolean(attrVal);
+ committedAttr=true;
+ } else {
+ log.warning("Unknown attribute id in add:" + attrName);
+ }
+ }
+
+ //set defaults for committed and pending based on allowDups value
+ if (!pendingAttr) cmd.overwritePending=!cmd.allowDups;
+ if (!committedAttr) cmd.overwriteCommitted=!cmd.allowDups;
+
+ DocumentBuilder builder = new DocumentBuilder(schema);
+ SchemaField uniqueKeyField = schema.getUniqueKeyField();
+ int eventType=0;
+ // accumulate responses
+ List<String> added = new ArrayList<String>(10);
+ while(true) {
+ // this may be our second time through the loop in the case
+ // that there are multiple docs in the add... so make sure that
+ // objects can handle that.
+
+ cmd.indexedId = null; // reset the id for this add
+
+ if (eventType !=0) {
+ eventType=xpp.getEventType();
+ if (eventType==XmlPullParser.END_DOCUMENT) break;
+ }
+ // eventType = xpp.next();
+ eventType = xpp.nextTag();
+ if (eventType == XmlPullParser.END_TAG || eventType == XmlPullParser.END_DOCUMENT) break; // should match </add>
+
+ readDoc(builder,xpp);
+ builder.endDoc();
+ cmd.doc = builder.getDoc();
+ log.finest("adding doc...");
+ updateHandler.addDoc(cmd);
+ String docId = null;
+ if (uniqueKeyField!=null)
+ docId = schema.printableUniqueKey(cmd.doc);
+ added.add(docId);
+
+ } // end while
+ // write log and result
+ StringBuilder out = new StringBuilder();
+ for (String docId: added)
+ if(docId != null)
+ out.append(docId + ",");
+ String outMsg = out.toString();
+ if(outMsg.length() > 0)
+ outMsg = outMsg.substring(0, outMsg.length() - 1);
+ log.info("added id={" + outMsg + "} in " + (System.currentTimeMillis()-startTime) + "ms");
+
+ // Add output
+ res.add( "added", outMsg );
+ } // end add
+
+ else if ("commit".equals(currTag) || "optimize".equals(currTag)) {
+ log.finest("parsing "+currTag);
+
+ CommitUpdateCommand cmd = new CommitUpdateCommand("optimize".equals(currTag));
+
+ boolean sawWaitSearcher=false, sawWaitFlush=false;
+ int attrcount = xpp.getAttributeCount();
+ for (int i=0; i<attrcount; i++) {
+ String attrName = xpp.getAttributeName(i);
+ String attrVal = xpp.getAttributeValue(i);
+ if ("waitFlush".equals(attrName)) {
+ cmd.waitFlush = StrUtils.parseBoolean(attrVal);
+ sawWaitFlush=true;
+ } else if ("waitSearcher".equals(attrName)) {
+ cmd.waitSearcher = StrUtils.parseBoolean(attrVal);
+ sawWaitSearcher=true;
+ } else {
+ log.warning("unexpected attribute commit/@" + attrName);
+ }
+ }
+
+ // If waitFlush is specified and waitSearcher wasn't, then
+ // clear waitSearcher.
+ if (sawWaitFlush && !sawWaitSearcher) {
+ cmd.waitSearcher=false;
+ }
+
+ updateHandler.commit(cmd);
+ if ("optimize".equals(currTag)) {
+ log.info("optimize 0 "+(System.currentTimeMillis()-startTime));
+ }
+ else {
+ log.info("commit 0 "+(System.currentTimeMillis()-startTime));
+ }
+ while (true) {
+ int eventType = xpp.nextTag();
+ if (eventType == XmlPullParser.END_TAG) break; // match </commit>
+ }
+
+ // add debug output
+ res.add( cmd.optimize?"optimize":"commit", "" );
+ } // end commit
+
+ else if ("delete".equals(currTag)) {
+ log.finest("parsing delete");
+
+ DeleteUpdateCommand cmd = new DeleteUpdateCommand();
+ cmd.fromPending=true;
+ cmd.fromCommitted=true;
+ int attrcount = xpp.getAttributeCount();
+ for (int i=0; i<attrcount; i++) {
+ String attrName = xpp.getAttributeName(i);
+ String attrVal = xpp.getAttributeValue(i);
+ if ("fromPending".equals(attrName)) {
+ cmd.fromPending = StrUtils.parseBoolean(attrVal);
+ } else if ("fromCommitted".equals(attrName)) {
+ cmd.fromCommitted = StrUtils.parseBoolean(attrVal);
+ } else {
+ log.warning("unexpected attribute delete/@" + attrName);
+ }
+ }
+
+ int eventType = xpp.nextTag();
+ currTag = xpp.getName();
+ String val = xpp.nextText();
+
+ if ("id".equals(currTag)) {
+ cmd.id = val;
+ updateHandler.delete(cmd);
+ log.info("delete(id " + val + ") 0 " +
+ (System.currentTimeMillis()-startTime));
+ } else if ("query".equals(currTag)) {
+ cmd.query = val;
+ updateHandler.deleteByQuery(cmd);
+ log.info("deleteByQuery(query " + val + ") 0 " +
+ (System.currentTimeMillis()-startTime));
+ } else {
+ log.warning("unexpected XML tag /delete/"+currTag);
+ throw new SolrException(400,"unexpected XML tag /delete/"+currTag);
+ }
+
+ res.add( "delete", "" );
+
+ while (xpp.nextTag() != XmlPullParser.END_TAG);
+ } // end delete
+ return res;
+ }
+
+ private void readDoc(DocumentBuilder builder, XmlPullParser xpp) throws IOException, XmlPullParserException {
+ // xpp should be at <doc> at this point
+
+ builder.startDoc();
+
+ int attrcount = xpp.getAttributeCount();
+ float docBoost = 1.0f;
+
+ for (int i=0; i<attrcount; i++) {
+ String attrName = xpp.getAttributeName(i);
+ String attrVal = xpp.getAttributeValue(i);
+ if ("boost".equals(attrName)) {
+ docBoost = Float.parseFloat(attrVal);
+ builder.setBoost(docBoost);
+ } else {
+ log.warning("Unknown attribute doc/@" + attrName);
+ }
+ }
+ if (docBoost != 1.0f) builder.setBoost(docBoost);
+
+ // while (findNextTag(xpp,"field") != XmlPullParser.END_DOCUMENT) {
+
+ while(true) {
+ int eventType = xpp.nextTag();
+ if (eventType == XmlPullParser.END_TAG) break; // </doc>
+
+ String tname=xpp.getName();
+ // System.out.println("FIELD READER AT TAG " + tname);
+
+ if (!"field".equals(tname)) {
+ log.warning("unexpected XML tag doc/"+tname);
+ throw new SolrException(400,"unexpected XML tag doc/"+tname);
+ }
+
+ //
+ // get field name and parse field attributes
+ //
+ attrcount = xpp.getAttributeCount();
+ String name=null;
+ float boost=1.0f;
+ boolean isNull=false;
+
+ for (int i=0; i<attrcount; i++) {
+ String attrName = xpp.getAttributeName(i);
+ String attrVal = xpp.getAttributeValue(i);
+ if ("name".equals(attrName)) {
+ name=attrVal;
+ } else if ("boost".equals(attrName)) {
+ boost=Float.parseFloat(attrVal);
+ } else if ("null".equals(attrName)) {
+ isNull=StrUtils.parseBoolean(attrVal);
+ } else {
+ log.warning("Unknown attribute doc/field/@" + attrName);
+ }
+ }
+
+ // now get the field value
+ String val = xpp.nextText(); // todo... text event for <field></field>???
+ // need this line for isNull???
+ // Don't add fields marked as null (for now at least)
+ if (!isNull) {
+ if (boost != 1.0f) {
+ builder.addField(name,val,boost);
+ } else {
+ builder.addField(name,val);
+ }
+ }
+
+ // do I have to do a nextTag here to read the end_tag?
+
+ } // end field loop
+ }
+
+ /**
+ * A Convinince method for getting back a simple XML string indicating
+ * successs of failure from an XML formated Update (from the Reader)
+ */
+ public void doLegacyUpdate(Reader input, Writer output) {
+
+ try {
+ NamedList ignored = this.update( input );
+ output.write("<result status=\"0\"></result>");
+ }
+ catch( Exception ex ) {
+ try {
+ XML.writeXML(output,"result",SolrException.toStr(ex),"status","1");
+ } catch (Exception ee) {
+ log.severe("Error writing to output stream: "+ee);
+ }
+ }
+ }
+
+ //////////////////////// SolrInfoMBeans methods //////////////////////
+
+ @Override
+ public String getDescription() {
+ return "Add documents with XML";
+ }
+
+ @Override
+ public String getVersion() {
+ return "$Revision:$";
+ }
+
+ @Override
+ public String getSourceId() {
+ return "$Id:$";
+ }
+
+ @Override
+ public String getSource() {
+ return "$URL:$";
+ }
+}
Propchange: lucene/solr/trunk/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/solr/trunk/src/java/org/apache/solr/handler/XmlUpdateRequestHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: lucene/solr/trunk/src/java/org/apache/solr/request/ContentStream.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/ContentStream.java?view=auto&rev=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/ContentStream.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/ContentStream.java Mon Jan 29 12:33:21 2007
@@ -0,0 +1,29 @@
+/**
+ * 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.
+ */
+
+package org.apache.solr.request;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public interface ContentStream {
+ String getName();
+ String getSourceInfo();
+ String getContentType();
+ Long getSize(); // size if we know it, otherwise null
+ InputStream getStream() throws IOException;
+}
Propchange: lucene/solr/trunk/src/java/org/apache/solr/request/ContentStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: lucene/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java Mon Jan 29 12:33:21 2007
@@ -17,41 +17,34 @@
package org.apache.solr.request;
+import static org.apache.solr.request.SolrParams.FACET;
+import static org.apache.solr.request.SolrParams.FQ;
+import static org.apache.solr.request.SolrParams.Q;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.SolrInfoMBean;
import org.apache.solr.core.SolrException;
-
-import org.apache.solr.search.SolrIndexSearcher;
-import org.apache.solr.search.DocList;
-import org.apache.solr.search.DocSet;
+import org.apache.solr.handler.RequestHandlerBase;
+import org.apache.solr.schema.IndexSchema;
import org.apache.solr.search.DocListAndSet;
-import org.apache.solr.search.SolrQueryParser;
+import org.apache.solr.search.DocSet;
import org.apache.solr.search.QueryParsing;
-
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrQueryResponse;
-import org.apache.solr.request.SolrRequestHandler;
-
-import org.apache.solr.schema.IndexSchema;
-
-import org.apache.solr.util.NamedList;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.search.SolrQueryParser;
+import org.apache.solr.util.DisMaxParams;
import org.apache.solr.util.HighlightingUtils;
+import org.apache.solr.util.NamedList;
import org.apache.solr.util.SolrPluginUtils;
-import org.apache.solr.util.DisMaxParams;
-import static org.apache.solr.request.SolrParams.*;
-
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.apache.lucene.queryParser.QueryParser;
-
-/* this is the standard logging framework for Solr */
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.net.URL;
/**
* <p>
@@ -122,9 +115,7 @@
* :TODO: make bf,pf,qf multival params now that SolrParams supports them
* </pre>
*/
-public class DisMaxRequestHandler
- implements SolrRequestHandler, SolrInfoMBean {
-
+public class DisMaxRequestHandler extends RequestHandlerBase {
/**
* A field we can't ever find in any schema, so we can safely tell
@@ -133,15 +124,6 @@
*/
private static String IMPOSSIBLE_FIELD_NAME = "\uFFFC\uFFFC\uFFFC";
- // statistics
- // TODO: should we bother synchronizing these, or is an off-by-one error
- // acceptable every million requests or so?
- long numRequests;
- long numErrors;
-
- SolrParams defaults;
- SolrParams appends;
- SolrParams invariants;
/** shorten the class references for utilities */
private static class U extends SolrPluginUtils {
@@ -155,75 +137,25 @@
public DisMaxRequestHandler() {
super();
}
-
- /* returns URLs to the Wiki pages */
- public URL[] getDocs() {
- /* :TODO: need docs */
- return new URL[0];
- }
- public String getName() {
- return this.getClass().getName();
- }
-
- public NamedList getStatistics() {
- NamedList lst = new NamedList();
- lst.add("requests", numRequests);
- lst.add("errors", numErrors);
- return lst;
- }
-
- public String getVersion() {
- return "$Revision:$";
- }
-
- public String getDescription() {
- return "DisjunctionMax Request Handler: Does relevancy based queries "
- + "accross a variety of fields using configured boosts";
- }
-
- public Category getCategory() {
- return Category.QUERYHANDLER;
- }
-
- public String getSourceId() {
- return "$Id:$";
- }
-
- public String getSource() {
- return "$URL:$";
- }
-
+
/** sets the default variables for any usefull info it finds in the config
* if a config option is not inthe format expected, logs an warning
* and ignores it..
*/
public void init(NamedList args) {
-
+ // Handle an old format
if (-1 == args.indexOf("defaults",0)) {
// no explict defaults list, use all args implicitly
// indexOf so "<null name="defaults"/> is valid indicator of no defaults
defaults = SolrParams.toSolrParams(args);
} else {
- Object o = args.get("defaults");
- if (o != null && o instanceof NamedList) {
- defaults = SolrParams.toSolrParams((NamedList)o);
- }
- o = args.get("appends");
- if (o != null && o instanceof NamedList) {
- appends = SolrParams.toSolrParams((NamedList)o);
- }
- o = args.get("invariants");
- if (o != null && o instanceof NamedList) {
- invariants = SolrParams.toSolrParams((NamedList)o);
- }
+ // otherwise use the new one.
+ super.init( args );
}
}
- public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
- numRequests++;
-
- try {
- U.setDefaults(req,defaults,appends,invariants);
+ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
+ {
SolrParams params = req.getParams();
int flags = 0;
@@ -385,12 +317,6 @@
if(sumData != null)
rsp.add("highlighting", sumData);
}
-
- } catch (Exception e) {
- SolrException.log(SolrCore.log,e);
- rsp.setException(e);
- numErrors++;
- }
}
/**
@@ -410,5 +336,35 @@
return f.getFacetCounts();
}
+
+ //////////////////////// SolrInfoMBeans methods //////////////////////
+
+ @Override
+ public String getDescription() {
+ return "DisjunctionMax Request Handler: Does relevancy based queries "
+ + "accross a variety of fields using configured boosts";
+ }
+
+ @Override
+ public String getVersion() {
+ return "$Revision:$";
+ }
+
+ @Override
+ public String getSourceId() {
+ return "$Id:$";
+ }
+
+ @Override
+ public String getSource() {
+ return "$URL:$";
+ }
+ @Override
+ public URL[] getDocs() {
+ try {
+ return new URL[] { new URL("http://wiki.apache.org/solr/DisMaxRequestHandler") };
+ }
+ catch( MalformedURLException ex ) { return null; }
+ }
}
Propchange: lucene/solr/trunk/src/java/org/apache/solr/request/DisMaxRequestHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: lucene/solr/trunk/src/java/org/apache/solr/request/SolrParams.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/SolrParams.java?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/SolrParams.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/SolrParams.java Mon Jan 29 12:33:21 2007
@@ -127,6 +127,13 @@
*/
public static final String FACET_PREFIX = "facet.prefix";
+ /** If the content stream should come from a URL */
+ public static final String STREAM_URL = "stream.url";
+
+ /** If the content stream should come directly from a field */
+ public static final String STREAM_BODY = "stream.body";
+
+
/** returns the String value of a param, or null if not set */
public abstract String get(String param);
Modified: lucene/solr/trunk/src/java/org/apache/solr/request/SolrQueryRequest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/SolrQueryRequest.java?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/SolrQueryRequest.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/SolrQueryRequest.java Mon Jan 29 12:33:21 2007
@@ -39,6 +39,10 @@
* the original parameters returned by getOriginalParams()
*/
public void setParams(SolrParams params);
+
+ /** A Collection of ContentStreams passed to the request
+ */
+ public Iterable<ContentStream> getContentStreams();
/** Returns the original request parameters. As this
* does not normally include configured defaults
@@ -116,4 +120,6 @@
public long getElapsedTime();
******/
}
+
+
Modified: lucene/solr/trunk/src/java/org/apache/solr/request/SolrQueryRequestBase.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/SolrQueryRequestBase.java?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/SolrQueryRequestBase.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/SolrQueryRequestBase.java Mon Jan 29 12:33:21 2007
@@ -23,6 +23,7 @@
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrException;
+import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
@@ -56,6 +57,7 @@
protected final SolrParams origParams;
protected SolrParams params;
protected Map<Object,Object> context;
+ protected Iterable<ContentStream> streams;
public SolrQueryRequestBase(SolrCore core, SolrParams params) {
this.core = core;
@@ -115,15 +117,18 @@
return s==null ? defval : s;
}
+ @Deprecated
public String getQueryString() {
return params.get(SolrParams.Q);
}
+ @Deprecated
public String getQueryType() {
return params.get(SolrParams.QT);
}
// starting position in matches to return to client
+ @Deprecated
public int getStart() {
return params.getInt(SolrParams.START, 0);
}
@@ -175,6 +180,15 @@
}
}
+ /** A Collection of ContentStreams passed to the request
+ */
+ public Iterable<ContentStream> getContentStreams() {
+ return streams;
+ }
+
+ public void setContentStreams( Iterable<ContentStream> s ) {
+ streams = s;
+ }
public String getParamString() {
return origParams.toString();
Modified: lucene/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java Mon Jan 29 12:33:21 2007
@@ -19,9 +19,10 @@
import org.apache.lucene.search.*;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
-import java.net.URL;
import org.apache.solr.util.StrUtils;
import org.apache.solr.util.NamedList;
@@ -29,8 +30,11 @@
import org.apache.solr.util.SolrPluginUtils;
import org.apache.solr.search.*;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.SolrInfoMBean;
import org.apache.solr.core.SolrException;
+import org.apache.solr.handler.RequestHandlerBase;
+
+import com.sun.org.apache.xerces.internal.util.URI.MalformedURIException;
+
import static org.apache.solr.request.SolrParams.*;
/**
@@ -53,43 +57,17 @@
* </ul>
*
*/
-public class StandardRequestHandler implements SolrRequestHandler, SolrInfoMBean {
-
- // statistics
- // TODO: should we bother synchronizing these, or is an off-by-one error
- // acceptable every million requests or so?
- long numRequests;
- long numErrors;
- SolrParams defaults;
- SolrParams appends;
- SolrParams invariants;
+public class StandardRequestHandler extends RequestHandlerBase {
/** shorten the class references for utilities */
private static class U extends SolrPluginUtils {
/* :NOOP */
}
- public void init(NamedList args) {
- Object o = args.get("defaults");
- if (o != null && o instanceof NamedList) {
- defaults = SolrParams.toSolrParams((NamedList)o);
- }
- o = args.get("appends");
- if (o != null && o instanceof NamedList) {
- appends = SolrParams.toSolrParams((NamedList)o);
- }
- o = args.get("invariants");
- if (o != null && o instanceof NamedList) {
- invariants = SolrParams.toSolrParams((NamedList)o);
- }
-
- }
-
- public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
- numRequests++;
- try {
- U.setDefaults(req,defaults,appends,invariants);
+ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
+ {
+
SolrParams p = req.getParams();
String sreq = p.get(Q);
@@ -165,17 +143,6 @@
results.docList, query, req, new String[]{defaultField});
if(sumData != null)
rsp.add("highlighting", sumData);
-
- } catch (SolrException e) {
- rsp.setException(e);
- numErrors++;
- return;
- } catch (Exception e) {
- SolrException.log(SolrCore.log,e);
- rsp.setException(e);
- numErrors++;
- return;
- }
}
/**
@@ -199,23 +166,14 @@
//////////////////////// SolrInfoMBeans methods //////////////////////
-
- public String getName() {
- return StandardRequestHandler.class.getName();
- }
-
public String getVersion() {
- return SolrCore.version;
+ return "$Revision$";
}
public String getDescription() {
return "The standard Solr request handler";
}
- public Category getCategory() {
- return Category.QUERYHANDLER;
- }
-
public String getSourceId() {
return "$Id$";
}
@@ -225,14 +183,10 @@
}
public URL[] getDocs() {
- return null;
- }
-
- public NamedList getStatistics() {
- NamedList lst = new NamedList();
- lst.add("requests", numRequests);
- lst.add("errors", numErrors);
- return lst;
+ try {
+ return new URL[] { new URL("http://wiki.apache.org/solr/StandardRequestHandler") };
+ }
+ catch( MalformedURLException ex ) { return null; }
}
}
Modified: lucene/solr/trunk/src/java/org/apache/solr/util/TestHarness.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/util/TestHarness.java?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/util/TestHarness.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/util/TestHarness.java Mon Jan 29 12:33:21 2007
@@ -19,6 +19,7 @@
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
+import org.apache.solr.handler.XmlUpdateRequestHandler;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.QueryResponseWriter;
import org.apache.solr.request.SolrQueryRequest;
@@ -36,9 +37,12 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
+import java.io.Writer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -62,6 +66,7 @@
private SolrCore core;
private XPath xpath = XPathFactory.newInstance().newXPath();
private DocumentBuilder builder;
+ XmlUpdateRequestHandler updater;
/**
* Assumes "solrconfig.xml" is the config file to use, and
@@ -93,28 +98,36 @@
SolrConfig.initConfig(confFile);
core = new SolrCore(dataDirectory, new IndexSchema(schemaFile));
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+
+ updater = new XmlUpdateRequestHandler();
+ updater.init( null );
} catch (Exception e) {
throw new RuntimeException(e);
}
}
+
/**
* Processes an "update" (add, commit or optimize) and
* returns the response as a String.
+ *
+ * The better approach is to instanciate a Updatehandler directly
*
* @param xml The XML of the update
* @return The XML response to the update
*/
+ @Deprecated
public String update(String xml) {
StringReader req = new StringReader(xml);
StringWriter writer = new StringWriter(32000);
- core.update(req, writer);
+
+ updater.doLegacyUpdate(req, writer);
+
return writer.toString();
-
}
-
+
/**
* Validates that an "update" (add, commit or optimize) results in success.
Added: lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java?view=auto&rev=501174
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java (added)
+++ lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java Mon Jan 29 12:33:21 2007
@@ -0,0 +1,113 @@
+/**
+ * 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.
+ */
+
+package org.apache.solr.servlet;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequestWrapper;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.solr.core.Config;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.ContentStream;
+import org.apache.solr.request.MapSolrParams;
+import org.apache.solr.request.MultiMapSolrParams;
+import org.apache.solr.request.SolrParams;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.util.AbstractSolrTestCase;
+
+import junit.framework.TestCase;
+
+public class SolrRequestParserTest extends AbstractSolrTestCase {
+
+ public String getSchemaFile() { return "schema.xml"; }
+ public String getSolrConfigFile() { return "solrconfig.xml"; }
+
+ SolrRequestParsers parser;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ parser = new SolrRequestParsers( SolrCore.getSolrCore(), SolrConfig.config );
+ }
+
+ public void testStreamBody() throws Exception
+ {
+ String body1 = "AMANAPLANPANAMA";
+ String body2 = "qwertasdfgzxcvb";
+ String body3 = "1234567890";
+
+ Map<String,String[]> args = new HashMap<String, String[]>();
+ args.put( SolrParams.STREAM_BODY, new String[] {body1} );
+
+ // Make sure it got a single stream in and out ok
+ List<ContentStream> streams = new ArrayList<ContentStream>();
+ parser.buildRequestFrom( new MultiMapSolrParams( args ), streams );
+ assertEquals( 1, streams.size() );
+ assertEquals( body1, IOUtils.toString( streams.get(0).getStream() ) );
+
+ // Now add three and make sure they come out ok
+ streams = new ArrayList<ContentStream>();
+ args.put( SolrParams.STREAM_BODY, new String[] {body1,body2,body3} );
+ parser.buildRequestFrom( new MultiMapSolrParams( args ), streams );
+ assertEquals( 3, streams.size() );
+ ArrayList<String> input = new ArrayList<String>();
+ ArrayList<String> output = new ArrayList<String>();
+ input.add( body1 );
+ input.add( body2 );
+ input.add( body3 );
+ output.add( IOUtils.toString( streams.get(0).getStream() ) );
+ output.add( IOUtils.toString( streams.get(1).getStream() ) );
+ output.add( IOUtils.toString( streams.get(2).getStream() ) );
+ // sort them so the output is consistent
+ Collections.sort( input );
+ Collections.sort( output );
+ assertEquals( input.toString(), output.toString() );
+ }
+
+
+ public void testStreamURL() throws Exception
+ {
+ boolean ok = false;
+ String url = "http://svn.apache.org/repos/asf/lucene/solr/trunk/";
+ String txt = null;
+ try {
+ txt = IOUtils.toString( new URL(url).openStream() );
+ }
+ catch( Exception ex ) {
+ // TODO - should it fail/skip?
+ fail( "this test only works if you have a network connection." );
+ return;
+ }
+
+ Map<String,String[]> args = new HashMap<String, String[]>();
+ args.put( SolrParams.STREAM_URL, new String[] {url} );
+
+ // Make sure it got a single stream in and out ok
+ List<ContentStream> streams = new ArrayList<ContentStream>();
+ parser.buildRequestFrom( new MultiMapSolrParams( args ), streams );
+ assertEquals( 1, streams.size() );
+ assertEquals( txt, IOUtils.toString( streams.get(0).getStream() ) );
+ }
+}
Propchange: lucene/solr/trunk/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: lucene/solr/trunk/src/test/test-files/solr/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/test-files/solr/conf/solrconfig.xml?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/src/test/test-files/solr/conf/solrconfig.xml (original)
+++ lucene/solr/trunk/src/test/test-files/solr/conf/solrconfig.xml Mon Jan 29 12:33:21 2007
@@ -255,6 +255,8 @@
</lst>
</requestHandler>
+ <!-- enable streaming for testing... -->
+ <requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048" />
<admin>
<defaultQuery>solr</defaultQuery>
Modified: lucene/solr/trunk/src/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/webapp/WEB-INF/web.xml?view=diff&rev=501174&r1=501173&r2=501174
==============================================================================
--- lucene/solr/trunk/src/webapp/WEB-INF/web.xml (original)
+++ lucene/solr/trunk/src/webapp/WEB-INF/web.xml Mon Jan 29 12:33:21 2007
@@ -30,7 +30,18 @@
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"/>
-->
+ <!-- Any path (name) registered in solrconfig.xml will be sent to that filter -->
+ <filter>
+ <filter-name>SolrRequestFilter</filter-name>
+ <filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>SolrRequestFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+ <!-- Otherwise it will continue to the old servlets -->
+
<servlet>
<servlet-name>SolrServer</servlet-name>
<display-name>Solr</display-name>
Added: lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java?view=auto&rev=501174
==============================================================================
--- lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java (added)
+++ lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java Mon Jan 29 12:33:21 2007
@@ -0,0 +1,160 @@
+/**
+ * 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.
+ */
+
+package org.apache.solr.servlet;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.logging.Logger;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.solr.core.Config;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.core.SolrException;
+import org.apache.solr.request.QueryResponseWriter;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrQueryResponse;
+import org.apache.solr.request.SolrRequestHandler;
+
+/**
+ * This filter looks at the incoming URL maps them to handlers defined in solrconfig.xml
+ */
+public class SolrDispatchFilter implements Filter
+{
+ final Logger log = Logger.getLogger(SolrDispatchFilter.class.getName());
+
+ protected SolrCore core;
+ protected SolrRequestParsers parsers;
+
+ public void init(FilterConfig config) throws ServletException
+ {
+ log.info("SolrDispatchFilter.init()");
+ try {
+ Context c = new InitialContext();
+
+ /***
+ System.out.println("Enumerating JNDI Context=" + c);
+ NamingEnumeration<NameClassPair> en = c.list("java:comp/env");
+ while (en.hasMore()) {
+ NameClassPair ncp = en.next();
+ System.out.println(" ENTRY:" + ncp);
+ }
+ System.out.println("JNDI lookup=" + c.lookup("java:comp/env/solr/home"));
+ ***/
+
+ String home = (String)c.lookup("java:comp/env/solr/home");
+ if (home!=null) Config.setInstanceDir(home);
+ } catch (NoInitialContextException e) {
+ log.info("JNDI not configured for Solr (NoInitialContextEx)");
+ } catch (NamingException e) {
+ log.info("No /solr/home in JNDI");
+ }
+
+ log.info("user.dir=" + System.getProperty("user.dir"));
+ core = SolrCore.getSolrCore();
+ parsers = new SolrRequestParsers( core, SolrConfig.config );
+
+ log.info("SolrDispatchFilter.init() done");
+ }
+
+ public void destroy() {
+ core.close();
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
+ {
+ if( request instanceof HttpServletRequest) {
+ HttpServletRequest req = (HttpServletRequest)request;
+ try {
+ String path = req.getServletPath();
+ if( req.getPathInfo() != null ) {
+ // this lets you handle /update/commit when /update is a servlet
+ path += req.getPathInfo();
+ }
+ int idx = path.indexOf( ':' );
+ if( idx > 0 ) {
+ // save the portion after the ':' for a 'handler' path parameter
+ path = path.substring( 0, idx );
+ }
+
+ SolrRequestHandler handler = core.getRequestHandler( path );
+ if( handler != null ) {
+ SolrQueryRequest solrReq = parsers.parse( path, req );
+ SolrQueryResponse solrRsp = new SolrQueryResponse();
+ core.execute( handler, solrReq, solrRsp );
+ if( solrRsp.getException() != null ) {
+ sendError( (HttpServletResponse)response, solrRsp.getException() );
+ return;
+ }
+
+ // Now write it out
+ QueryResponseWriter responseWriter = core.getQueryResponseWriter(solrReq);
+ response.setContentType(responseWriter.getContentType(solrReq, solrRsp));
+ PrintWriter out = response.getWriter();
+ responseWriter.write(out, solrReq, solrRsp);
+ return;
+ }
+ }
+ catch( Throwable ex ) {
+ sendError( (HttpServletResponse)response, ex );
+ return;
+ }
+ }
+
+ // Otherwise let the webapp handle the request
+ chain.doFilter(request, response);
+ }
+
+ protected void sendError(HttpServletResponse res, Throwable ex) throws IOException
+ {
+ int code=500;
+ String trace = "";
+ if( ex instanceof SolrException ) {
+ code = ((SolrException)ex).code();
+ }
+
+ // For any regular code, don't include the stack trace
+ if( code == 500 || code < 100 ) {
+ StringWriter sw = new StringWriter();
+ ex.printStackTrace(new PrintWriter(sw));
+ trace = "\n\n"+sw.toString();
+
+ SolrException.logOnce(log,null,ex );
+
+ // non standard codes have undefined results with various servers
+ if( code < 100 ) {
+ log.warning( "invalid return code: "+code );
+ code = 500;
+ }
+ }
+ res.sendError( code, ex.getMessage() + trace );
+ }
+}
Propchange: lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java
------------------------------------------------------------------------------
svn:eol-style = native