protected void waitForWarming() throws InterruptedException { waitForWarming(h.getCore()); }
@Before public void setUp() throws Exception { super.setUp(); solrServer = new EmbeddedSolrServer(h.getCoreContainer(), h.getCore().getName()); }
public static Object createDocObjects(Map<Comparable, Doc> fullModel, Comparator sort, int rows, Collection<String> fieldNames) { List<Doc> docList = new ArrayList<>(fullModel.values()); Collections.sort(docList, sort); List sortedDocs = new ArrayList(rows); for (Doc doc : docList) { if (sortedDocs.size() >= rows) break; Map<String,Object> odoc = toObject(doc, h.getCore().getLatestSchema(), fieldNames); sortedDocs.add(toObject(doc, h.getCore().getLatestSchema(), fieldNames)); } return sortedDocs; }
public LocalSolrQueryRequest makeRequest(String ... q) { if (q.length==1) { return new LocalSolrQueryRequest(TestHarness.this.getCore(), q[0], qtype, start, limit, args); } if (q.length%2 != 0) { throw new RuntimeException("The length of the string array (query arguments) needs to be even"); } Map.Entry<String, String> [] entries = new NamedListEntry[q.length / 2]; for (int i = 0; i < q.length; i += 2) { entries[i/2] = new NamedListEntry<String>(q[i], q[i+1]); } return new LocalSolrQueryRequest(TestHarness.this.getCore(), new NamedList(entries)); } }
/** * Generates a SolrQueryRequest */ public static SolrQueryRequest req(SolrParams params, String... moreParams) { ModifiableSolrParams mp = new ModifiableSolrParams(params); for (int i=0; i<moreParams.length; i+=2) { mp.add(moreParams[i], moreParams[i+1]); } return new LocalSolrQueryRequest(h.getCore(), mp); }
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(); }
public static String getQueryResponse(String wt, SolrParams params) throws Exception { ModifiableSolrParams p = new ModifiableSolrParams(params); p.set("wt", wt); String path = p.get("qt"); p.remove("qt"); p.set("indent","true"); DirectSolrConnection connection = new DirectSolrConnection(h.getCore()); String raw = connection.request(path, p, null); return raw; }
protected void processCommit(final String chain) throws IOException { SolrCore core = h.getCore(); UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain); assertNotNull("No Chain named: " + chain, pc); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams()); CommitUpdateCommand cmd = new CommitUpdateCommand(req,false); UpdateRequestProcessor processor = pc.createProcessor(req, rsp); try { processor.processCommit(cmd); } finally { req.close(); } }
protected void finish(final String chain) throws IOException { SolrCore core = h.getCore(); UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain); assertNotNull("No Chain named: " + chain, pc); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams()); UpdateRequestProcessor processor = pc.createProcessor(req, rsp); try { processor.finish(); } finally { IOUtils.closeQuietly(processor); req.close(); } }
/** * Test that the ContentHandler properly strips the illegal characters */ @Test public void testTransformValue() { String fieldName = "user_name"; assertFalse("foobar".equals(getFoobarWithNonChars())); Metadata metadata = new Metadata(); // load illegal char string into a metadata field and generate a new document, // which will cause the ContentHandler to be invoked. metadata.set(fieldName, getFoobarWithNonChars()); StripNonCharSolrContentHandlerFactory contentHandlerFactory = new StripNonCharSolrContentHandlerFactory(ExtractionDateUtil.DEFAULT_DATE_FORMATS); IndexSchema schema = h.getCore().getLatestSchema(); SolrContentHandler contentHandler = contentHandlerFactory.createSolrContentHandler(metadata, new MapSolrParams(new HashMap()), schema); SolrInputDocument doc = contentHandler.newDocument(); String foobar = doc.getFieldValue(fieldName).toString(); assertTrue("foobar".equals(foobar)); }
protected void processDeleteById(final String chain, String id) throws IOException { SolrCore core = h.getCore(); UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain); assertNotNull("No Chain named: " + chain, pc); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams()); DeleteUpdateCommand cmd = new DeleteUpdateCommand(req); cmd.setId(id); UpdateRequestProcessor processor = pc.createProcessor(req, rsp); try { processor.processDelete(cmd); } finally { req.close(); } }
@Test public void testSirenFieldType() throws Exception { final IndexSchema schema = h.getCore().getSchema(); final SchemaField ntriple = schema.getField(JSON_FIELD); assertNotNull(ntriple); final FieldType tmp = ntriple.getType(); assertTrue(tmp instanceof SirenField); }
@Test public void testSirenFieldType() throws Exception { final IndexSchema schema = h.getCore().getLatestSchema(); final SchemaField ntriple = schema.getField(JSON_FIELD); assertNotNull(ntriple); final FieldType tmp = ntriple.getType(); assertTrue(tmp instanceof ExtendedJsonField); }
/** Send JSON update commands */ public static String updateJ(String json, SolrParams args) throws Exception { SolrCore core = h.getCore(); if (args == null) { args = params("wt","json","indent","true"); } else { ModifiableSolrParams newArgs = new ModifiableSolrParams(args); if (newArgs.get("wt") == null) newArgs.set("wt","json"); if (newArgs.get("indent") == null) newArgs.set("indent","true"); args = newArgs; } DirectSolrConnection connection = new DirectSolrConnection(core); SolrRequestHandler handler = core.getRequestHandler("/update/json"); if (handler == null) { handler = new UpdateRequestHandler(); handler.init(null); } return connection.request(handler, args, json); }
@Test public void testConciseSirenFieldType() throws Exception { final IndexSchema schema = h.getCore().getLatestSchema(); SchemaField json = schema.getField("concise"); assertNotNull(json); FieldType tmp = json.getType(); assertTrue(tmp instanceof ConciseJsonField); json = schema.getField("concise-attribute-wildcard"); assertNotNull(json); tmp = json.getType(); assertTrue(tmp instanceof ConciseJsonField); }
@Test public void testSirenFieldTypeProperties() throws Exception { final IndexSchema schema = h.getCore().getSchema(); final FieldType type = schema.getField("json").getType(); assertTrue(type instanceof SirenField); assertFalse(type.isMultiValued()); assertTrue(type.isTokenized()); assertEquals(type.getPostingsFormat(), Siren10AForPostingsFormat.NAME); }
@Test public void testSirenFieldTypeProperties() throws Exception { final IndexSchema schema = h.getCore().getLatestSchema(); final FieldType type = schema.getField("json").getType(); assertTrue(type instanceof ExtendedJsonField); assertFalse(type.isMultiValued()); assertTrue(type.isTokenized()); assertEquals(type.getPostingsFormat(), Siren10AForPostingsFormat.NAME); }
@Test public void testSirenFieldAnalyzer() throws Exception { final IndexSchema schema = h.getCore().getLatestSchema(); final SchemaField ntriple = schema.getField(JSON_FIELD); final FieldType tmp = ntriple.getType(); assertTrue(tmp.getAnalyzer() instanceof TokenizerChain); final TokenizerChain ts = (TokenizerChain) tmp.getAnalyzer(); assertNotNull(ts.getTokenizerFactory()); assertTrue(ts.getTokenizerFactory() instanceof ExtendedJsonTokenizerFactory); // 3 filters for index analyzer assertNotNull(ts.getTokenFilterFactories()); assertEquals(3, ts.getTokenFilterFactories().length); assertTrue(ts.getTokenFilterFactories()[0] instanceof DatatypeAnalyzerFilterFactory); assertTrue(ts.getTokenFilterFactories()[1] instanceof PositionAttributeFilterFactory); assertTrue(ts.getTokenFilterFactories()[2] instanceof SirenPayloadFilterFactory); }
@Test public void testConciseSirenFieldAnalyzer() throws Exception { final IndexSchema schema = h.getCore().getLatestSchema(); final SchemaField json = schema.getField("concise"); final FieldType tmp = json.getType(); assertTrue(tmp.getAnalyzer() instanceof TokenizerChain); final TokenizerChain ts = (TokenizerChain) tmp.getAnalyzer(); assertNotNull(ts.getTokenizerFactory()); assertTrue(ts.getTokenizerFactory() instanceof ConciseJsonTokenizerFactory); // 4 filters for index analyzer assertNotNull(ts.getTokenFilterFactories()); assertEquals(4, ts.getTokenFilterFactories().length); assertTrue(ts.getTokenFilterFactories()[0] instanceof DatatypeAnalyzerFilterFactory); assertTrue(ts.getTokenFilterFactories()[1] instanceof PathEncodingFilterFactory); assertTrue(ts.getTokenFilterFactories()[2] instanceof PositionAttributeFilterFactory); assertTrue(ts.getTokenFilterFactories()[3] instanceof SirenPayloadFilterFactory); }
@Test public void testSirenFieldAnalyzer() throws Exception { final IndexSchema schema = h.getCore().getSchema(); final SchemaField ntriple = schema.getField(JSON_FIELD); final FieldType tmp = ntriple.getType(); assertTrue(tmp.getAnalyzer() instanceof TokenizerChain); final TokenizerChain ts = (TokenizerChain) tmp.getAnalyzer(); assertNotNull(ts.getTokenizerFactory()); assertTrue(ts.getTokenizerFactory() instanceof JsonTokenizerFactory); // 3 filters for index analyzer assertNotNull(ts.getTokenFilterFactories()); assertEquals(3, ts.getTokenFilterFactories().length); assertTrue(ts.getTokenFilterFactories()[0] instanceof DatatypeAnalyzerFilterFactory); assertTrue(ts.getTokenFilterFactories()[1] instanceof PositionAttributeFilterFactory); assertTrue(ts.getTokenFilterFactories()[2] instanceof SirenPayloadFilterFactory); // no query analyzer assertNull(tmp.getQueryAnalyzer()); }