lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r801417 - in /lucene/solr/trunk: ./ src/common/org/apache/solr/common/params/ src/java/org/apache/solr/core/ src/test/org/apache/solr/core/ src/test/test-files/solr/conf/
Date Wed, 05 Aug 2009 21:25:06 GMT
Author: gsingers
Date: Wed Aug  5 21:25:06 2009
New Revision: 801417

URL: http://svn.apache.org/viewvc?rev=801417&view=rev
Log:
SOLR-1237: firstSearcher and newSearcher now identify themselves as such when querying

Added:
    lucene/solr/trunk/src/common/org/apache/solr/common/params/EventParams.java   (with props)
    lucene/solr/trunk/src/test/org/apache/solr/core/MockQuerySenderListenerReqHandler.java
  (with props)
Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/src/java/org/apache/solr/core/AbstractSolrEventListener.java
    lucene/solr/trunk/src/java/org/apache/solr/core/QuerySenderListener.java
    lucene/solr/trunk/src/java/org/apache/solr/core/SolrEventListener.java
    lucene/solr/trunk/src/test/org/apache/solr/core/TestQuerySenderListener.java
    lucene/solr/trunk/src/test/test-files/solr/conf/solrconfig-querysender.xml

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=801417&r1=801416&r2=801417&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Wed Aug  5 21:25:06 2009
@@ -254,6 +254,10 @@
     that allows disabling of english possessive stemming (removal of trailing 's from tokens)
     (Robert Muir via yonik)
 
+66. SOLR-1237: firstSearcher and newSearcher can now be identified via the CommonParams.EVENT
(evt) parameter in a request.  This allows a
+  RequestHandler or SearchComponent to know when a newSearcher or firstSearcher event happened.
 QuerySenderListender is the only implementation
+  in Solr that implements this, but outside implementations may wish to.  See the AbstractSolrEventListener
for a helper method. (gsingers)
+
 
 Optimizations
 ----------------------

Added: lucene/solr/trunk/src/common/org/apache/solr/common/params/EventParams.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/common/org/apache/solr/common/params/EventParams.java?rev=801417&view=auto
==============================================================================
--- lucene/solr/trunk/src/common/org/apache/solr/common/params/EventParams.java (added)
+++ lucene/solr/trunk/src/common/org/apache/solr/common/params/EventParams.java Wed Aug  5
21:25:06 2009
@@ -0,0 +1,13 @@
+package org.apache.solr.common.params;
+
+
+/**
+ *
+ *
+ **/
+public interface EventParams {
+  /** Event param for things like newSearcher, firstSearcher**/
+  public static final String EVENT = "event";
+  public static final String NEW_SEARCHER = "newSearcher";
+  public static final String FIRST_SEARCHER = "firstSearcher";
+}

Propchange: lucene/solr/trunk/src/common/org/apache/solr/common/params/EventParams.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/AbstractSolrEventListener.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/AbstractSolrEventListener.java?rev=801417&r1=801416&r2=801417&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/AbstractSolrEventListener.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/AbstractSolrEventListener.java Wed Aug
 5 21:25:06 2009
@@ -18,6 +18,7 @@
 package org.apache.solr.core;
 
 import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.params.EventParams;
 import org.apache.solr.search.SolrIndexSearcher;
 
 /**
@@ -44,4 +45,25 @@
   public String toString() {
     return getClass().getName() + args;
   }
+
+  /**
+   * Add the {@link org.apache.solr.common.params.EventParams#EVENT} with either the {@link
org.apache.solr.common.params.EventParams#NEW_SEARCHER}
+   * or {@link org.apache.solr.common.params.EventParams#FIRST_SEARCHER} values depending
on the value of currentSearcher.
+   * <p/>
+   * Makes a copy of NamedList and then adds the parameters.
+   *
+   *
+   * @param currentSearcher If null, add FIRST_SEARCHER, otherwise NEW_SEARCHER
+   * @param nlst The named list to add the EVENT value to
+   */
+  protected NamedList addEventParms(SolrIndexSearcher currentSearcher, NamedList nlst) {
+    NamedList result = new NamedList();
+    result.addAll(nlst);
+    if (currentSearcher != null) {
+      result.add(EventParams.EVENT, EventParams.NEW_SEARCHER);
+    } else {
+      result.add(EventParams.EVENT, EventParams.FIRST_SEARCHER);
+    }
+    return result;
+  }
 }

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/QuerySenderListener.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/QuerySenderListener.java?rev=801417&r1=801416&r2=801417&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/QuerySenderListener.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/QuerySenderListener.java Wed Aug  5 21:25:06
2009
@@ -42,7 +42,8 @@
     for (NamedList nlst : (List<NamedList>)args.get("queries")) {
       try {
         // bind the request to a particular searcher (the newSearcher)
-        LocalSolrQueryRequest req = new LocalSolrQueryRequest(core,nlst) {
+        NamedList params = addEventParms(currentSearcher, nlst);
+        LocalSolrQueryRequest req = new LocalSolrQueryRequest(core,params) {
           @Override public SolrIndexSearcher getSearcher() { return searcher; }
           @Override public void close() { }
         };
@@ -75,5 +76,4 @@
   }
 
 
-
 }

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/SolrEventListener.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/SolrEventListener.java?rev=801417&r1=801416&r2=801417&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrEventListener.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrEventListener.java Wed Aug  5 21:25:06
2009
@@ -36,6 +36,28 @@
   /** The searchers passed here are only guaranteed to be valid for the duration
    * of this method call, so care should be taken not to spawn threads or asynchronous
    * tasks with references to these searchers.
+   * <p/>
+   * Implementations should add the {@link org.apache.solr.common.params.EventParams#EVENT}
parameter and set it to a value of either:
+   * <ul>
+   * <li>{@link org.apache.solr.common.params.EventParams#FIRST_SEARCHER} - First Searcher
event</li>
+   * <li>{@link org.apache.solr.common.params.EventParams#NEW_SEARCHER} - New Searcher
event</li>
+   * </ul>
+   *
+   * Sample:
+   * <pre>
+    if (currentSearcher != null) {
+      nlst.add(CommonParams.EVENT, CommonParams.NEW_SEARCHER);
+    } else {
+      nlst.add(CommonParams.EVENT, CommonParams.FIRST_SEARCHER);
+    }
+   *
+   * </pre>
+   *
+   * @see org.apache.solr.core.AbstractSolrEventListener#addEventParms(org.apache.solr.search.SolrIndexSearcher,
org.apache.solr.common.util.NamedList) 
+   *
+   * @param newSearcher The new {@link org.apache.solr.search.SolrIndexSearcher} to use
+   * @param currentSearcher The existing {@link org.apache.solr.search.SolrIndexSearcher}.
 null if this is a firstSearcher event.
+   *
    */
   public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher);
 

Added: lucene/solr/trunk/src/test/org/apache/solr/core/MockQuerySenderListenerReqHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/core/MockQuerySenderListenerReqHandler.java?rev=801417&view=auto
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/core/MockQuerySenderListenerReqHandler.java
(added)
+++ lucene/solr/trunk/src/test/org/apache/solr/core/MockQuerySenderListenerReqHandler.java
Wed Aug  5 21:25:06 2009
@@ -0,0 +1,40 @@
+package org.apache.solr.core;
+
+import org.apache.solr.handler.RequestHandlerBase;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrQueryResponse;
+
+
+/**
+ *
+ *
+ **/
+public class MockQuerySenderListenerReqHandler extends RequestHandlerBase {
+  public SolrQueryRequest req;
+  public SolrQueryResponse rsp;
+
+  public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
{
+    this.req = req;
+    this.rsp = rsp;
+  }
+
+  public String getDescription() {
+    String result = null;
+    return result;
+  }
+
+  public String getSourceId() {
+    String result = null;
+    return result;
+  }
+
+  public String getSource() {
+    String result = null;
+    return result;
+  }
+
+  public String getVersion() {
+    String result = null;
+    return result;
+  }
+}

Propchange: lucene/solr/trunk/src/test/org/apache/solr/core/MockQuerySenderListenerReqHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/solr/trunk/src/test/org/apache/solr/core/TestQuerySenderListener.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/core/TestQuerySenderListener.java?rev=801417&r1=801416&r2=801417&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/core/TestQuerySenderListener.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/core/TestQuerySenderListener.java Wed Aug 
5 21:25:06 2009
@@ -17,11 +17,10 @@
 
 package org.apache.solr.core;
 
-import org.apache.solr.handler.RequestHandlerBase;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrQueryResponse;
-import org.apache.solr.request.SolrRequestHandler;
 import org.apache.solr.util.AbstractSolrTestCase;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.common.params.EventParams;
+import org.apache.lucene.store.Directory;
 
 public class TestQuerySenderListener extends AbstractSolrTestCase {
 
@@ -35,5 +34,28 @@
     assertEquals( 1, core.firstSearcherListeners.size() );
     assertEquals( 1, core.newSearcherListeners.size() );
   }
+
+  public void testSearcherEvents() throws Exception {
+    SolrCore core = h.getCore();
+    SolrEventListener newSearcherListener = core.newSearcherListeners.get(0);
+    assertTrue("Not an instance of QuerySenderListener", newSearcherListener instanceof QuerySenderListener);
+    QuerySenderListener qsl = (QuerySenderListener) newSearcherListener;
+
+    SolrIndexSearcher currentSearcher = core.getSearcher().get();
+    qsl.newSearcher(currentSearcher, null);//test new Searcher
+    MockQuerySenderListenerReqHandler mock = (MockQuerySenderListenerReqHandler) core.getRequestHandler("mock");
+    assertNotNull("Mock is null", mock);
+    String evt = mock.req.getParams().get(EventParams.EVENT);
+    assertNotNull("Event is null", evt);
+    assertTrue(evt + " is not equal to " + EventParams.FIRST_SEARCHER, evt.equals(EventParams.FIRST_SEARCHER)
== true);
+    Directory dir = currentSearcher.getReader().directory();
+    SolrIndexSearcher newSearcher = new SolrIndexSearcher(core, core.getSchema(), "testQuerySenderListener",
dir, true, false);
+
+    qsl.newSearcher(newSearcher, currentSearcher);
+    evt = mock.req.getParams().get(EventParams.EVENT);
+    assertNotNull("Event is null", evt);
+    assertTrue(evt + " is not equal to " + EventParams.NEW_SEARCHER, evt.equals(EventParams.NEW_SEARCHER)
== true);
+  }
+
 }
 

Modified: lucene/solr/trunk/src/test/test-files/solr/conf/solrconfig-querysender.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/test-files/solr/conf/solrconfig-querysender.xml?rev=801417&r1=801416&r2=801417&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/test-files/solr/conf/solrconfig-querysender.xml (original)
+++ lucene/solr/trunk/src/test/test-files/solr/conf/solrconfig-querysender.xml Wed Aug  5
21:25:06 2009
@@ -34,8 +34,8 @@
          local query request for each NamedList in sequence. -->
     <listener event="newSearcher" class="solr.QuerySenderListener">
       <arr name="queries">
-        <lst> <str name="q">solr</str> <str name="start">0</str>
<str name="rows">10</str> </lst>
-        <lst> <str name="q">rocks</str> <str name="start">0</str>
<str name="rows">10</str> </lst>
+        <lst> <str name="q">solr</str> <str name="start">0</str>
<str name="rows">10</str> <str name="qt">mock</str></lst>
+        <lst> <str name="q">rocks</str> <str name="start">0</str>
<str name="rows">10</str> <str name="qt">mock</str></lst>
       </arr>
     </listener>
 
@@ -44,10 +44,15 @@
          requests or to gain prewarming data from. -->
     <listener event="firstSearcher" class="solr.QuerySenderListener">
       <arr name="queries">
-        <lst> <str name="q">fast_warm</str> <str name="start">0</str>
<str name="rows">10</str> </lst>
+        <lst> <str name="q">fast_warm</str> <str name="start">0</str>
<str name="rows">10</str>
+          <str name="qt">mock</str>
+        </lst>
       </arr>
     </listener>
   
   </query>
-  
+  <requestHandler name="mock" class="org.apache.solr.core.MockQuerySenderListenerReqHandler"
default="true">
+    <!-- default values for query parameters -->
+
+  </requestHandler>
 </config>



Mime
View raw message