org.apache.solr.common.SolrDocumentList Java Examples
The following examples show how to use
org.apache.solr.common.SolrDocumentList.
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: AbstractSolrInputOperator.java From attic-apex-malhar with Apache License 2.0 | 9 votes |
@Override public void emitTuples() { SolrParams solrQueryParams = getQueryParams(); try { SolrServer solrServer = solrServerConnector.getSolrServer(); QueryResponse response = solrServer.query(solrQueryParams); SolrDocumentList queriedDocuments = response.getResults(); for (SolrDocument solrDocument : queriedDocuments) { emitTuple(solrDocument); lastEmittedTuple = solrDocument; lastEmittedTimeStamp = System.currentTimeMillis(); logger.debug("Emiting document: " + solrDocument.getFieldValue("name")); } } catch (SolrServerException ex) { throw new RuntimeException("Unable to fetch documents from Solr server", ex); } }
Example #2
Source File: TestMerge.java From BioSolr with Apache License 2.0 | 6 votes |
/** * When [shard] is not in the field list, the [shard] field should not be returned, even * if score is in the field list. */ @Test public void testNotWantsShardWithScore() throws Exception { try (SolrCore core = h.getCoreContainer().getCore("merge")) { ModifiableSolrParams params = new ModifiableSolrParams(); params.add("q", "*:*"); params.add("sort", "letter asc"); params.add("fl", "*,score"); SolrDocumentList docs = queryDocs(core, "merge", params); assertEquals(3, docs.size()); for (SolrDocument doc : docs) { assertNull(doc.getFieldValue("[shard]")); assertEquals(1.0f, doc.getFieldValue("score")); } } }
Example #3
Source File: EmbeddedSolrServer.java From lucene-solr with Apache License 2.0 | 6 votes |
private JavaBinCodec createJavaBinCodec(final StreamingResponseCallback callback, final BinaryResponseWriter.Resolver resolver) { return new JavaBinCodec(resolver) { @Override public void writeSolrDocument(SolrDocument doc) { callback.streamSolrDocument(doc); //super.writeSolrDocument( doc, fields ); } @Override public void writeSolrDocumentList(SolrDocumentList docs) throws IOException { if (docs.size() > 0) { SolrDocumentList tmp = new SolrDocumentList(); tmp.setMaxScore(docs.getMaxScore()); tmp.setNumFound(docs.getNumFound()); tmp.setStart(docs.getStart()); docs = tmp; } callback.streamDocListInfo(docs.getNumFound(), docs.getStart(), docs.getMaxScore()); super.writeSolrDocumentList(docs); } }; }
Example #4
Source File: ContentEditor.java From jease with GNU General Public License v3.0 | 6 votes |
public String checkDuplication() { try { String solrurl = jease.Registry.getParameter(jease.Names.JEASE_SOLR_URL, ""); SolrClient client = new HttpSolrClient.Builder(solrurl).build(); SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setFilterQueries("jeaseid:\"" + id.getValue() + "\" "); query.setFilterQueries("jeasepath:\"" + getNode().getPath() + "\""); SolrDocumentList results = client.query(query).getResults(); if (results.size() > 0) { return results.get(0).getFieldValue("id").toString(); } } catch (Exception s) { s.printStackTrace(); } return ""; }
Example #5
Source File: DistributedExpandComponentTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private void assertExpandGroupCountAndOrder(String group, int count, Map<String, SolrDocumentList>expandedResults, String... docs) throws Exception { SolrDocumentList results = expandedResults.get(group); if(results == null) { throw new Exception("Group Not Found:"+group); } if(results.size() != count) { throw new Exception("Expected Count "+results.size()+" Not Found:"+count); } for(int i=0; i<docs.length;i++) { String id = docs[i]; SolrDocument doc = results.get(i); if(!doc.getFieldValue("id").toString().equals(id)) { throw new Exception("Id not in results or out of order:"+id+"!="+doc.getFieldValue("id")); } } }
Example #6
Source File: StoredFieldsShardResponseProcessor.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void process(ResponseBuilder rb, ShardRequest shardRequest) { boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0; ShardResponse srsp = shardRequest.responses.get(0); SolrDocumentList docs = (SolrDocumentList)srsp.getSolrResponse().getResponse().get("response"); String uniqueIdFieldName = rb.req.getSchema().getUniqueKeyField().getName(); for (SolrDocument doc : docs) { Object id = doc.getFieldValue(uniqueIdFieldName).toString(); ShardDoc shardDoc = rb.resultIds.get(id); FieldDoc fieldDoc = (FieldDoc) shardDoc; if (shardDoc != null) { if (returnScores && !Float.isNaN(fieldDoc.score)) { doc.setField("score", fieldDoc.score); } rb.retrievedDocuments.put(id, doc); } } }
Example #7
Source File: SolrSearchServerTest.java From vind with Apache License 2.0 | 6 votes |
@Before public void init() throws IOException, SolrServerException { MockitoAnnotations.initMocks(this); when(solrClient.ping()).thenReturn(solrPingResponse); when(solrPingResponse.getStatus()).thenReturn(0); when(solrPingResponse.getQTime()).thenReturn(10); when(solrClient.query(any(), any(SolrRequest.METHOD.class))).thenReturn(response); when(response.getResults()).thenReturn(new SolrDocumentList()); when(response.getResponse()).thenReturn(responseObject); when(responseObject.get("responseHeader")).thenReturn(responseObject); when(responseObject.get("params")).thenReturn(responseObject); when(responseObject.get("suggestion.field")).thenReturn("category"); when(solrClient.add(org.mockito.Matchers.<Collection<SolrInputDocument>>any())).thenReturn(iResponse); when(solrClient.add(any(SolrInputDocument.class))).thenReturn(iResponse); when(iResponse.getQTime()).thenReturn(10); when(iResponse.getElapsedTime()).thenReturn(15l); //we use the protected constructor to avoid schema checking server = new SolrSearchServerTestClass(solrClient); }
Example #8
Source File: SolrUtils.java From vind with Apache License 2.0 | 6 votes |
public static GetResult buildRealTimeGetResult(QueryResponse response, RealTimeGet query, DocumentFactory factory) { final String DOC = "doc"; long nResults = 0; List<Document> docResults = new ArrayList<>(); final SolrDocumentList results = response.getResults(); if(results != null && results.size() >0){ docResults = buildResultList(results, null, factory, null); nResults = docResults.size(); } else { final SolrDocument solrDoc = (SolrDocument)response.getResponse().get(DOC); if(solrDoc != null) { final SolrDocumentList solrDocuments = new SolrDocumentList(); solrDocuments.add(solrDoc); docResults = buildResultList(solrDocuments, null, factory, null); nResults = 1; } } return new GetResult(nResults,docResults,query,factory,response.getQTime()).setElapsedTime(response.getElapsedTime()); }
Example #9
Source File: SolrSearchServerTest.java From vind with Apache License 2.0 | 6 votes |
@Before public void init() throws IOException, SolrServerException { MockitoAnnotations.initMocks(this); when(solrClient.ping()).thenReturn(solrPingResponse); when(solrPingResponse.getStatus()).thenReturn(0); when(solrPingResponse.getQTime()).thenReturn(10); when(solrClient.query(any(), any(SolrRequest.METHOD.class))).thenReturn(response); when(response.getResults()).thenReturn(new SolrDocumentList()); when(response.getResults()).thenReturn(new SolrDocumentList()); when(solrClient.add(org.mockito.Matchers.<Collection<SolrInputDocument>>any())).thenReturn(iResponse); when(solrClient.add(any(SolrInputDocument.class))).thenReturn(iResponse); when(iResponse.getQTime()).thenReturn(10); when(iResponse.getElapsedTime()).thenReturn(15l); //we use the protected constructor to avoid schema checking server = new SolrSearchServer(solrClient, false); }
Example #10
Source File: Application.java From tools-journey with Apache License 2.0 | 6 votes |
@Override public void run(String... strings) throws IOException, SolrServerException { Product phone = new Product(); phone.setId("P0002"); phone.setName("Phone"); productRepository.save(phone); System.out.println(productRepository.findOne("P0001")); System.out.println(productRepository.findById("P0001")); SolrDocumentList list = client.getById("product", Lists.newArrayList("P0001", "P0002")); Iterator<SolrDocument> iterator = list.iterator(); while (iterator.hasNext()) { SolrDocument entry = iterator.next(); System.out.println(entry.entrySet()); } }
Example #11
Source File: AppATEGENIATest.java From jate with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void validate_indexing() { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("q", "*:*"); try { QueryResponse qResp = server.query(params); SolrDocumentList docList = qResp.getResults(); assert (docList.getNumFound() == 2000); } catch (SolrServerException e) { e.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } }
Example #12
Source File: TestMerge.java From BioSolr with Apache License 2.0 | 6 votes |
/** * Fields should not be returned if they are non-stored, even if asked for. */ @Test public void testNonStored() throws Exception { try (SolrCore core = h.getCoreContainer().getCore("merge")) { ModifiableSolrParams params = new ModifiableSolrParams(); params.add("q", "*:*"); params.add("sort", "letter asc"); params.add("fl", "required"); SolrDocumentList docs = queryDocs(core, "merge", params); assertEquals(3, docs.size()); SolrDocument doc0 = docs.get(0); assertNull(doc0.getFieldValue("required")); } }
Example #13
Source File: DistributedAlfrescoSolrFingerPrintIT.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testFingerPrint5() throws Exception { putHandleDefaults(); QueryResponse response = query(getDefaultTestClient(), true, "{\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [\"joel\"], \"tenants\": []}", params("q", "FINGERPRINT:" + NODES_METADATA[0].getNodeRef().getId() +"_70", "qt", "/afts", "shards.qt", "/afts", "start", "0", "fl", "DBID,score", "rows", "100")); SolrDocumentList docs = response.getResults(); assertEquals(2, docs.getNumFound()); SolrDocument doc0 = docs.get(0); long dbid0 = (long)doc0.getFieldValue("DBID"); assertEquals(dbid0, NODES[0].getId()); SolrDocument doc1 = docs.get(1); long dbid1 = (long)doc1.getFieldValue("DBID"); assertEquals(dbid1, NODES[2].getId()); }
Example #14
Source File: GetByIdTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testGetIds() throws Exception { SolrDocumentList rsp = getSolrClient().getById(Arrays.asList("0", "1", "2", "3", "4")); assertEquals(3, rsp.getNumFound()); assertEquals("1", rsp.get(0).get("id")); assertEquals("Microsoft", rsp.get(0).get("term_s")); assertEquals("MSFT", rsp.get(0).get("term2_s")); assertEquals("2", rsp.get(1).get("id")); assertEquals("Apple", rsp.get(1).get("term_s")); assertEquals("AAPL", rsp.get(1).get("term2_s")); assertEquals("3", rsp.get(2).get("id")); assertEquals("Yahoo", rsp.get(2).get("term_s")); assertEquals("YHOO", rsp.get(2).get("term2_s")); }
Example #15
Source File: TextIndexSolr5.java From BioSolr with Apache License 2.0 | 6 votes |
@Override public List<TextHit> query(Node property, String qs, int limit) { SolrDocumentList solrResults = solrQuery(qs, limit) ; List<TextHit> results = new ArrayList<>() ; for ( SolrDocument sd : solrResults ) { String str = (String)sd.getFieldValue(docDef.getEntityField()) ; // log.info("Entity: "+uriStr) ; Node n = TextQueryFuncs.stringToNode(str) ; Float score = (Float) sd.getFirstValue("score"); // capture literal value, if stored Node literal = null; String field = (property != null) ? docDef.getField(property) : docDef.getPrimaryField(); String value = (String) sd.getFirstValue(field); if (value != null) { literal = NodeFactory.createLiteral(value); // FIXME: language and datatype } TextHit hit = new TextHit(n, score.floatValue(), literal); results.add(hit) ; } if ( limit > 0 && results.size() > limit ) results = results.subList(0, limit) ; return results ; }
Example #16
Source File: NumFoundSearchComponent.java From BioSolr with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void handleResponses(ResponseBuilder rb, ShardRequest req) { System.out.println("===== HANDLE RESPONSES ====="); System.out.println("purpose=" + req.purpose); System.out.println("Shards: " + (req.shards != null ? String.join(" ", req.shards) : "(null)")); if ((req.purpose & ShardRequest.PURPOSE_GET_FIELDS) > 0) { Map<String, Long> numFounds = (Map<String, Long>)rb.req.getContext().get(COMPONENT_NAME + "numFounds"); Set<Object> joinIds = (Set<Object>)rb.req.getContext().get(COMPONENT_NAME + "joinIds"); for (ShardResponse rsp : req.responses) { NamedList response = rsp.getSolrResponse().getResponse(); SolrDocumentList results = (SolrDocumentList)response.get("response"); numFounds.put(rsp.getShard(), results.getNumFound()); NamedList counts = (NamedList)response.get("facet_counts"); if (counts != null) { NamedList fields = (NamedList)counts.get("facet_fields"); NamedList values = (NamedList)fields.get(joinField); for (int i = 0; i < values.size(); ++i) { joinIds.add(values.getName(i)); } } } } }
Example #17
Source File: DebugComponent.java From lucene-solr with Apache License 2.0 | 6 votes |
private NamedList<String> getTrackResponse(ShardResponse shardResponse) { NamedList<String> namedList = new SimpleOrderedMap<>(); if (shardResponse.getException() != null) { namedList.add("Exception", shardResponse.getException().getMessage()); return namedList; } NamedList<Object> responseNL = shardResponse.getSolrResponse().getResponse(); @SuppressWarnings("unchecked") NamedList<Object> responseHeader = (NamedList<Object>)responseNL.get("responseHeader"); if(responseHeader != null) { namedList.add("QTime", responseHeader.get("QTime").toString()); } namedList.add("ElapsedTime", String.valueOf(shardResponse.getSolrResponse().getElapsedTime())); namedList.add("RequestPurpose", shardResponse.getShardRequest().params.get(CommonParams.REQUEST_PURPOSE)); SolrDocumentList docList = (SolrDocumentList)shardResponse.getSolrResponse().getResponse().get("response"); if(docList != null) { namedList.add("NumFound", String.valueOf(docList.getNumFound())); } namedList.add("Response", String.valueOf(responseNL)); return namedList; }
Example #18
Source File: TestBaseStatsCache.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override protected void checkResponse(QueryResponse controlRsp, QueryResponse shardRsp) { System.out.println("======================= Control Response ======================="); System.out.println(controlRsp); System.out.println(""); System.out.println(""); System.out.println("======================= Shard Response ======================="); System.out.println(""); System.out.println(shardRsp); SolrDocumentList shardList = shardRsp.getResults(); SolrDocumentList controlList = controlRsp.getResults(); assertEquals(controlList.size(), shardList.size()); assertEquals(controlList.getNumFound(), shardList.getNumFound()); Iterator<SolrDocument> it = controlList.iterator(); Iterator<SolrDocument> it2 = shardList.iterator(); while (it.hasNext()) { SolrDocument controlDoc = it.next(); SolrDocument shardDoc = it2.next(); assertEquals(controlDoc.getFieldValue("score"), shardDoc.getFieldValue("score")); } }
Example #19
Source File: TestMerge.java From BioSolr with Apache License 2.0 | 6 votes |
/** * Default values in the schema should be used if no value is returned from shards. */ @Test public void testDefaultValue() throws Exception { try (SolrCore core = h.getCoreContainer().getCore("merge")) { ModifiableSolrParams params = new ModifiableSolrParams(); params.add("q", "*:*"); params.add("sort", "letter asc"); params.add("fl", "default"); SolrDocumentList docs = queryDocs(core, "merge", params); assertEquals(3, docs.size()); SolrDocument doc0 = docs.get(0); assertEquals("foo", doc0.getFieldValue("default")); } }
Example #20
Source File: TextIndexSolr5.java From BioSolr with Apache License 2.0 | 6 votes |
private SolrDocumentList solrQuery(String qs, int limit) { SolrQuery sq = new SolrQuery(qs) ; sq.setIncludeScore(true) ; if ( limit > 0 ) sq.setRows(limit) ; else sq.setRows(MAX_N) ; // The Solr default is 10. try { // Set default field. sq.add(CommonParams.DF, docDef.getPrimaryField()) ; QueryResponse rsp = solrClient.query(sq) ; SolrDocumentList docs = rsp.getResults() ; return docs ; } catch (SolrServerException | IOException e) { exception(e) ; return null ; } }
Example #21
Source File: MCROAISolrSearcher.java From mycore with GNU General Public License v3.0 | 6 votes |
@Override public Optional<Header> getHeader(String mcrId) { SolrQuery query = getBaseQuery(CommonParams.FQ); query.set(CommonParams.Q, "id:" + MCRSolrUtils.escapeSearchValue(mcrId)); query.setRows(1); // do the query SolrClient solrClient = MCRSolrClientFactory.getMainSolrClient(); try { QueryResponse response = solrClient.query(query); SolrDocumentList results = response.getResults(); if (!results.isEmpty()) { return Optional.of(toHeader(results.get(0), getSetResolver(results))); } } catch (Exception exc) { LOGGER.error("Unable to handle solr request", exc); } return Optional.empty(); }
Example #22
Source File: TestCloudPseudoReturnFields.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testAugmentersAndExplicit() throws Exception { for (SolrParams p : Arrays.asList(params("q", "*:*", "fl","id,[docid],[explain],x_alias:[value v=10 t=int]"), params("q", "*:*", "fl","id","fl","[docid],[explain],x_alias:[value v=10 t=int]"), params("q", "*:*", "fl","id","fl","[docid]","fl","[explain]","fl","x_alias:[value v=10 t=int]"))) { SolrDocumentList docs = assertSearch(p); assertEquals(p + " => " + docs, 5, docs.getNumFound()); // shouldn't matter what doc we pick... for (SolrDocument doc : docs) { String msg = p + " => " + doc; assertEquals(msg, 4, doc.size()); assertTrue(msg, doc.getFieldValue("id") instanceof String); assertTrue(msg, doc.getFieldValue("[docid]") instanceof Integer); assertTrue(msg, doc.getFieldValue("[explain]") instanceof String); assertTrue(msg, doc.getFieldValue("x_alias") instanceof Integer); assertEquals(msg, 10, doc.getFieldValue("x_alias")); } } }
Example #23
Source File: ACLRDTECTest.java From jate with GNU Lesser General Public License v3.0 | 6 votes |
public static long validate_indexing() { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("q", "*:*"); try { QueryResponse qResp = server.query(params); SolrDocumentList docList = qResp.getResults(); long numDocs = docList.getNumFound(); LOG.info(String.format("[%s] documents processed!", numDocs)); return numDocs; } catch (SolrServerException e) { e.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } return 0; }
Example #24
Source File: AbstractSolrSentryTestBase.java From incubator-sentry with Apache License 2.0 | 6 votes |
/** * Method to validate Solr update passes * @param solrUserName - User authenticated into Solr * @param collectionName - Name of the collection to which the data has to be updated * @param solrInputDoc - Instance of SolrInputDocument * @throws Exception */ protected void verifyUpdatePass(String solrUserName, String collectionName, SolrInputDocument solrInputDoc) throws Exception { String originalUser = getAuthenticatedUser(); try { SolrDocumentList orginalSolrDocs = getSolrDocs(collectionName, ALL_DOCS, true); setAuthenticationUser(solrUserName); CloudSolrServer cloudSolrServer = getCloudSolrServer(collectionName); try { cloudSolrServer.add(solrInputDoc); cloudSolrServer.commit(); } finally { cloudSolrServer.shutdown(); } orginalSolrDocs.add(ClientUtils.toSolrDocument(solrInputDoc)); SolrDocumentList solrRespDocs = getSolrDocs(collectionName, ALL_DOCS, true); // Validate Solr content to check whether the update command went through. validateSolrDocCountAndContent(orginalSolrDocs, solrRespDocs); } finally { setAuthenticationUser(originalUser); } }
Example #25
Source File: CarrotClusteringEngineTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private List<NamedList<Object>> checkEngine(CarrotClusteringEngine engine, int expectedNumDocs, int expectedNumClusters, Query query, SolrParams clusteringParams) throws IOException { // Get all documents to cluster return h.getCore().withSearcher(searcher -> { DocList docList = searcher.getDocList(query, (Query) null, new Sort(), 0, numberOfDocs); assertEquals("docList size", expectedNumDocs, docList.matches()); ModifiableSolrParams solrParams = new ModifiableSolrParams(); solrParams.add(clusteringParams); // Perform clustering LocalSolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), solrParams); Map<SolrDocument,Integer> docIds = new HashMap<>(docList.size()); SolrDocumentList solrDocList = ClusteringComponent.docListToSolrDocumentList( docList, searcher, engine.getFieldsToLoad(req), docIds ); @SuppressWarnings("unchecked") List<NamedList<Object>> results = (List<NamedList<Object>>) engine.cluster(query, solrDocList, docIds, req); req.close(); assertEquals("number of clusters: " + results, expectedNumClusters, results.size()); checkClusters(results, false); return results; }); }
Example #26
Source File: MCRSolrSearchUtils.java From mycore with GNU General Public License v3.0 | 6 votes |
@Override public void forEachRemaining(Consumer<? super SolrDocument> action) { if (action == null) { throw new NullPointerException(); } ModifiableSolrParams p = new ModifiableSolrParams(params); p.set("rows", (int) rows); long start = this.start, size = estimateSize(), fetched = 0; while (fetched < size) { p.set("start", (int) (start + fetched)); response = query(p); SolrDocumentList results = response.getResults(); for (SolrDocument doc : results) { action.accept(doc); } fetched += results.size(); } }
Example #27
Source File: SolrConnector.java From TagRec with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public Map<String, Set<String>> getTweets() { Map<String, Set<String>> tweets = new LinkedHashMap<String, Set<String>>(); SolrQuery solrParams = new SolrQuery(); solrParams.set("q", "*:*"); solrParams.set("fl", "text,hashtags"); solrParams.set("rows", Integer.MAX_VALUE); QueryResponse r = null; try { r = this.server.query(solrParams); SolrDocumentList docs = r.getResults(); for (SolrDocument d : docs) { tweets.put((String) d.get("text"), new LinkedHashSet<String>((List<String>) d.get("hashtags"))); } } catch (SolrServerException e) { e.printStackTrace(); } return tweets; }
Example #28
Source File: SolrJavaLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void whenAdd_thenVerifyAddedByQueryOnPrice() throws SolrServerException, IOException { SolrQuery query = new SolrQuery(); query.set("q", "price:599.99"); QueryResponse response = null; response = solrJavaIntegration.getSolrClient().query(query); SolrDocumentList docList = response.getResults(); assertEquals(1, docList.getNumFound()); for (SolrDocument doc : docList) { assertEquals("123456", (String) doc.getFieldValue("id")); assertEquals((Double) 599.99, (Double) doc.getFieldValue("price")); } }
Example #29
Source File: SolrMorphlineTest.java From kite with Apache License 2.0 | 6 votes |
@Test public void testLoadSolrWithChildDocuments() throws Exception { morphline = createMorphline("test-morphlines" + File.separator + "loadSolrWithChildDocuments"); Record record = new Record(); record.put(Fields.ID, "id0"); startSession(); Notifications.notifyBeginTransaction(morphline); assertTrue(morphline.process(record)); assertEquals(1, collector.getNumStartEvents()); Notifications.notifyCommitTransaction(morphline); // This parent block join returns the parent records for records // where the child documents contain "bar" in the id field. SolrDocumentList docs = query("{!parent which='content_type:parent'}id:bar").getResults(); assertEquals(1, docs.size()); assertEquals("id0", docs.get(0).getFirstValue(Fields.ID)); docs = query("*:*").getResults(); assertEquals(3, docs.size()); }
Example #30
Source File: SolrJavaLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void whenAdd_thenVerifyAddedByQueryOnId() throws SolrServerException, IOException { SolrQuery query = new SolrQuery(); query.set("q", "id:123456"); QueryResponse response = null; response = solrJavaIntegration.getSolrClient().query(query); SolrDocumentList docList = response.getResults(); assertEquals(1, docList.getNumFound()); for (SolrDocument doc : docList) { assertEquals("Kenmore Dishwasher", (String) doc.getFieldValue("name")); assertEquals((Double) 599.99, (Double) doc.getFieldValue("price")); } }