org.apache.solr.handler.UpdateRequestHandler Java Examples
The following examples show how to use
org.apache.solr.handler.UpdateRequestHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SolrTestCaseJ4.java From lucene-solr with Apache License 2.0 | 6 votes |
public static void addDoc(String doc, String updateRequestProcessorChain) throws Exception { Map<String, String[]> params = new HashMap<>(); MultiMapSolrParams mmparams = new MultiMapSolrParams(params); params.put(UpdateParams.UPDATE_CHAIN, new String[]{updateRequestProcessorChain}); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) { }; UpdateRequestHandler handler = new UpdateRequestHandler(); handler.init(null); ArrayList<ContentStream> streams = new ArrayList<>(2); streams.add(new ContentStreamBase.StringStream(doc)); req.setContentStreams(streams); handler.handleRequestBody(req, new SolrQueryResponse()); req.close(); }
Example #2
Source File: BaseTestRuleBasedAuthorizationPlugin.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testAllPermissionAllowsActionsWhenUserHasCorrectRole() { SolrRequestHandler handler = new UpdateRequestHandler(); assertThat(handler, new IsInstanceOf(PermissionNameProvider.class)); setUserRole("dev", "dev"); setUserRole("admin", "admin"); addPermission("all", "dev", "admin"); checkRules(makeMap("resource", "/update", "userPrincipal", "dev", "requestType", RequestType.UNKNOWN, "collectionRequests", "go", "handler", handler, "params", new MapSolrParams(singletonMap("key", "VAL2"))) , STATUS_OK); handler = new PropertiesRequestHandler(); assertThat(handler, new IsNot<>(new IsInstanceOf(PermissionNameProvider.class))); checkRules(makeMap("resource", "/admin/info/properties", "userPrincipal", "dev", "requestType", RequestType.UNKNOWN, "collectionRequests", "go", "handler", handler, "params", new MapSolrParams(emptyMap())) , STATUS_OK); }
Example #3
Source File: BaseTestRuleBasedAuthorizationPlugin.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testAllPermissionAllowsActionsWhenAssociatedRoleIsWildcard() { SolrRequestHandler handler = new UpdateRequestHandler(); assertThat(handler, new IsInstanceOf(PermissionNameProvider.class)); setUserRole("dev", "dev"); setUserRole("admin", "admin"); addPermission("all", "*"); checkRules(makeMap("resource", "/update", "userPrincipal", "dev", "requestType", RequestType.UNKNOWN, "collectionRequests", "go", "handler", new UpdateRequestHandler(), "params", new MapSolrParams(singletonMap("key", "VAL2"))) , STATUS_OK); handler = new PropertiesRequestHandler(); assertThat(handler, new IsNot<>(new IsInstanceOf(PermissionNameProvider.class))); checkRules(makeMap("resource", "/admin/info/properties", "userPrincipal", "dev", "requestType", RequestType.UNKNOWN, "collectionRequests", "go", "handler", handler, "params", new MapSolrParams(emptyMap())) , STATUS_OK); }
Example #4
Source File: BaseTestRuleBasedAuthorizationPlugin.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testAllPermissionDeniesActionsWhenUserIsNotCorrectRole() { SolrRequestHandler handler = new UpdateRequestHandler(); assertThat(handler, new IsInstanceOf(PermissionNameProvider.class)); setUserRole("dev", "dev"); setUserRole("admin", "admin"); addPermission("all", "admin"); checkRules(makeMap("resource", "/update", "userPrincipal", "dev", "requestType", RequestType.UNKNOWN, "collectionRequests", "go", "handler", new UpdateRequestHandler(), "params", new MapSolrParams(singletonMap("key", "VAL2"))) , FORBIDDEN); handler = new PropertiesRequestHandler(); assertThat(handler, new IsNot<>(new IsInstanceOf(PermissionNameProvider.class))); checkRules(makeMap("resource", "/admin/info/properties", "userPrincipal", "dev", "requestType", RequestType.UNKNOWN, "collectionRequests", "go", "handler", handler, "params", new MapSolrParams(emptyMap())) , FORBIDDEN); }
Example #5
Source File: UniqFieldsUpdateProcessorFactoryTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private void addDoc(String doc) throws Exception { Map<String, String[]> params = new HashMap<>(); MultiMapSolrParams mmparams = new MultiMapSolrParams(params); params.put(UpdateParams.UPDATE_CHAIN, new String[] { "uniq-fields" }); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) { }; UpdateRequestHandler handler = new UpdateRequestHandler(); handler.init(null); ArrayList<ContentStream> streams = new ArrayList<>(2); streams.add(new ContentStreamBase.StringStream(doc)); req.setContentStreams(streams); handler.handleRequestBody(req, new SolrQueryResponse()); req.close(); }
Example #6
Source File: TestHarness.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Create a TestHarness using a specific config * @param config the ConfigSolr to use */ public TestHarness(NodeConfig config, CoresLocator coresLocator) { container = new CoreContainer(config, coresLocator); container.load(); updater = new UpdateRequestHandler(); updater.init(null); }
Example #7
Source File: MaxSizeAutoCommitTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { System.setProperty("solr.ulog", "solr.UpdateLog"); initCore("solrconfig-tlog.xml", "schema.xml"); core = h.getCore(); updateHandler = (DirectUpdateHandler2) core.getUpdateHandler(); // we don't care about auto-commit's opening a new Searcher in this test, just skip it. updateHandler.softCommitTracker.setOpenSearcher(false); updateHandler.commitTracker.setOpenSearcher(false); // we don't care about soft commit's at all updateHandler.softCommitTracker.setTimeUpperBound(-1); updateHandler.softCommitTracker.setDocsUpperBound(-1); updateHandler.softCommitTracker.setTLogFileSizeUpperBound(-1); hardCommitTracker = updateHandler.commitTracker; // Only testing file-size based auto hard commits - disable other checks hardCommitTracker.setTimeUpperBound(-1); hardCommitTracker.setDocsUpperBound(-1); hardCommitTracker.setTLogFileSizeUpperBound(MAX_FILE_SIZE); monitor = new MockEventListener(); updateHandler.registerCommitCallback(monitor); updateRequestHandler = new UpdateRequestHandler(); updateRequestHandler.init( null ); }
Example #8
Source File: OntologyUpdateProcessorFactoryTest.java From BioSolr with Apache License 2.0 | 5 votes |
static void addDoc(String doc, String chain) throws Exception { Map<String, String[]> params = new HashMap<>(); MultiMapSolrParams mmparams = new MultiMapSolrParams(params); params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain }); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), mmparams) { }; UpdateRequestHandler handler = new UpdateRequestHandler(); handler.init(null); ArrayList<ContentStream> streams = new ArrayList<>(2); streams.add(new ContentStreamBase.StringStream(doc)); req.setContentStreams(streams); handler.handleRequestBody(req, new SolrQueryResponse()); req.close(); }
Example #9
Source File: JsonLoader.java From lucene-solr with Apache License 2.0 | 4 votes |
AddUpdateCommand parseAdd() throws IOException { AddUpdateCommand cmd = new AddUpdateCommand(req); cmd.commitWithin = commitWithin; cmd.overwrite = overwrite; while (true) { int ev = parser.nextEvent(); if (ev == JSONParser.STRING) { if (parser.wasKey()) { String key = parser.getString(); if ("doc".equals(key)) { if (cmd.solrDoc != null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Multiple documents in same" + " add command at [" + parser.getPosition() + "]"); } ev = assertNextEvent(JSONParser.OBJECT_START); cmd.solrDoc = parseDoc(ev); } else if (UpdateRequestHandler.OVERWRITE.equals(key)) { cmd.overwrite = parser.getBoolean(); // reads next boolean } else if (UpdateRequestHandler.COMMIT_WITHIN.equals(key)) { cmd.commitWithin = (int) parser.getLong(); } else if ("boost".equals(key)) { String boost = parser.getNumberChars().toString(); String message = "Ignoring document boost: " + boost + " as index-time boosts are not supported anymore"; if (WARNED_ABOUT_INDEX_TIME_BOOSTS.compareAndSet(false, true)) { log.warn(message); } else { log.debug(message); } } else { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown key '" + key + "' at [" + parser.getPosition() + "]"); } } else { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Should be a key " + " at [" + parser.getPosition() + "]"); } } else if (ev == JSONParser.OBJECT_END) { if (cmd.solrDoc == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Missing solr document at [" + parser.getPosition() + "]"); } return cmd; } else { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Got: " + JSONParser.getEventString(ev) + " at [" + parser.getPosition() + "]"); } } }