mirror of https://github.com/apache/lucene.git
SOLR-1237: firstSearcher and newSearcher now identify themselves as such when querying
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@801417 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
167a03b576
commit
ece497f832
|
@ -254,6 +254,10 @@ New Features
|
|||
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
|
||||
----------------------
|
||||
|
|
|
@ -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";
|
||||
}
|
|
@ -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 @@ class AbstractSolrEventListener implements SolrEventListener {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ class QuerySenderListener extends AbstractSolrEventListener {
|
|||
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 @@ class QuerySenderListener extends AbstractSolrEventListener {
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,28 @@ public interface SolrEventListener {
|
|||
/** 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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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 @@ public class TestQuerySenderListener extends AbstractSolrTestCase {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue