List of usage examples for org.apache.solr.common SolrInputDocument getChildDocuments
public List<SolrInputDocument> getChildDocuments()
From source file:com.ngdata.hbaseindexer.indexer.FusionDocumentWriter.java
License:Apache License
/** * shs: This method was modified from its original to add the input parameters 'parent' and 'docCount'. This was done * to enable recursion to be used to find all parent/child relationships to any level. * @param parent The parent document for the child document being passed in. Parent may be null if the child being * passed in is a member of the initial documents submitted. * @param child This is the child document. This document will be examined to determine if there are nested * child documents in it. * @param docCount This is the number of child documents for a parent. It is used as the child ID * @return The list of JSON formatted documents, denormalized (aka. flattened) and ready to be send to the * Fusion indexing pipeline endpoint. * @throws Exception/*from w w w .j a v a 2s . c om*/ */ protected List<Map<String, Object>> toJson(SolrInputDocument parent, SolrInputDocument child, int docCount) throws Exception { List<Map<String, Object>> docs = new ArrayList<Map<String, Object>>(); if (child != null) { List<SolrInputDocument> childDocs = child.getChildDocuments(); if (childDocs != null && !childDocs.isEmpty()) { // Recursive call back to 'toJsonDocs()' docs.addAll(toJsonDocs(child, childDocs, docCount++)); } else { // I'm not certain the increment should be on the docCount here... docs.add(doc2json(parent, child, docCount++)); } } return docs; }
From source file:org.apache.blur.slur.RowMutationHelper.java
License:Apache License
public static RowMutation from(SolrInputDocument doc, String table) { validateAsRow(doc);//from w ww.ja v a 2s . c o m RowMutation mutate = new RowMutation(); String rowid = extractRowId(doc); mutate.setRowId(rowid); mutate.setTable(table); List<RecordMutation> recordMutations = Lists.newArrayList(); if (doc.hasChildDocuments()) { for (SolrInputDocument child : doc.getChildDocuments()) { validateAsRecord(child); recordMutations.add(createRecordMutation(child, extractRecordId(child))); } } mutate.setRecordMutations(recordMutations); return mutate; }
From source file:org.craftercms.search.service.impl.DenormalizingPostProcessor.java
License:Open Source License
@Override public void postProcess(SolrInputDocument solrDoc) { if (solrDoc.hasChildDocuments()) { Collection<SolrInputDocument> childDocs = solrDoc.getChildDocuments(); Collection<SolrInputField> parentFields = getParentFields(solrDoc); Collection<SolrInputField> childrenFields = getChildrenFields(childDocs); if (copyChildrenFieldsToParent) { copyChildrenFieldsToParent(childrenFields, solrDoc); }//from w w w .j ava 2s . c om if (copyParentFieldsToChildren) { copyParentFieldsToChildren(parentFields, childDocs); } } }
From source file:org.craftercms.search.service.impl.RenameFieldsIfMultiValuePostProcessor.java
License:Open Source License
@Override public void postProcess(SolrInputDocument solrDoc) { String id = solrDoc.getFieldValue(idFieldName).toString(); List<SolrInputField> renamedFields = new ArrayList<>(); // Remap single value fields to multi value fields if they have more than one value for (Iterator<SolrInputField> iter = solrDoc.iterator(); iter.hasNext();) { SolrInputField field = iter.next(); SolrInputField renamedField = renameFieldIfMultiValue(id, field); if (renamedField != null) { renamedFields.add(renamedField); iter.remove();/* w w w . j ava 2 s . com*/ } } for (SolrInputField renamedField : renamedFields) { solrDoc.put(renamedField.getName(), renamedField); } // Do the same for child docs if (solrDoc.hasChildDocuments()) { for (SolrInputDocument childDoc : solrDoc.getChildDocuments()) { postProcess(childDoc); } } }
From source file:org.craftercms.search.service.impl.SolrDocumentBuilderImplTest.java
License:Open Source License
@Test public void testBuildForXml() throws Exception { Charset encoding = Charset.defaultCharset(); String xml = IOUtils.toString((new ClassPathResource("/docs/ipad.xml")).getInputStream(), encoding); SolrInputDocument doc = builder.build(SITE, IPAD_ID, xml, true); assertNotNull(doc);//from ww w . j av a2 s . com assertEquals(15, doc.size()); assertNull(doc.getFieldValue("code")); assertNotNull(doc.getFieldValue(DEFAULT_PUBLISHING_DATE_FIELD_NAME)); assertNotNull(doc.getFieldValue(DEFAULT_PUBLISHING_DATE_ALT_FIELD_NAME)); assertEquals(SITE, doc.getFieldValue(DEFAULT_SITE_FIELD_NAME)); assertEquals(SITE + ":" + IPAD_ID, doc.getFieldValue(DEFAULT_ID_FIELD_NAME)); assertEquals(SITE + ":" + IPAD_ID, doc.getFieldValue(DEFAULT_ROOT_ID_FIELD_NAME)); assertEquals(IPAD_ID, doc.getFieldValue(DEFAULT_LOCAL_ID_FIELD_NAME)); assertEquals("product", doc.getFieldValue(DEFAULT_CONTENT_TYPE_FIELD_NAME)); assertEquals("iPad Air 64GB", doc.getFieldValue("name_s")); assertEquals("iPad Air 64GB", doc.getFieldValue("name_t")); assertEquals("Apple MH182LL/A iPad Air 9.7-Inch Retina Display 64GB, Wi-Fi (Gold)", doc.getFieldValue("description_html").toString().trim()); assertEquals("2014-10-01T00:00:00.000Z", doc.getFieldValue("availableDate_dt")); assertEquals(Arrays.asList("Apple", "iPad", "Tablet"), doc.getFieldValues("tags.value_smv")); assertEquals(Arrays.asList("Silicon case with stand for iPad Air 64GB", "Lighting cable for iPad"), trimValues(doc.getFieldValues("accessories.item.description_html"))); assertEquals(Arrays.asList("Case", "Lighting Cable"), doc.getFieldValues("accessories.item.name_smv")); assertEquals(Arrays.asList("Black", "Blue", "Red"), doc.getFieldValues("accessories.item.colors.color_smv")); // Asset sub-docs List<SolrInputDocument> subDocs = doc.getChildDocuments(); assertNotNull(subDocs); assertEquals(2, subDocs.size()); // Assert first doc SolrInputDocument subDoc1 = subDocs.get(0); assertEquals(16, subDoc1.size()); assertNotNull(doc.getFieldValue(DEFAULT_PUBLISHING_DATE_FIELD_NAME)); assertNotNull(doc.getFieldValue(DEFAULT_PUBLISHING_DATE_ALT_FIELD_NAME)); assertEquals(SITE, subDoc1.getFieldValue(DEFAULT_SITE_FIELD_NAME)); assertEquals(SITE + ":" + IPAD_ID_ACCESSORIES0, subDoc1.getFieldValue(DEFAULT_ID_FIELD_NAME)); assertEquals(SITE + ":" + IPAD_ID, subDoc1.getFieldValue(DEFAULT_ROOT_ID_FIELD_NAME)); assertEquals(IPAD_ID_ACCESSORIES0, subDoc1.getFieldValue(DEFAULT_LOCAL_ID_FIELD_NAME)); assertEquals(SITE + ":" + IPAD_ID, subDoc1.getFieldValue(DEFAULT_PARENT_ID_FIELD_NAME)); assertEquals("product_accessories", subDoc1.getFieldValue(DEFAULT_CONTENT_TYPE_FIELD_NAME)); assertEquals("Case", subDoc1.getFieldValue("accessories.item.name_s")); assertEquals("Silicon case with stand for iPad Air 64GB", subDoc1.getFieldValue("accessories.item.description_html").toString().trim()); assertEquals(Arrays.asList("Black", "Blue", "Red"), subDoc1.getFieldValues("accessories.item.colors.color_smv")); assertEquals("iPad Air 64GB", subDoc1.getFieldValue("name_s")); assertEquals("iPad Air 64GB", subDoc1.getFieldValue("name_t")); assertEquals("Apple MH182LL/A iPad Air 9.7-Inch Retina Display 64GB, Wi-Fi (Gold)", subDoc1.getFieldValue("description_html").toString().trim()); assertEquals("2014-10-01T00:00:00.000Z", subDoc1.getFieldValue("availableDate_dt")); assertEquals(Arrays.asList("Apple", "iPad", "Tablet"), subDoc1.getFieldValues("tags.value_smv")); // Assert second doc SolrInputDocument subDoc2 = subDocs.get(1); assertEquals(15, subDoc2.size()); assertNotNull(doc.getFieldValue(DEFAULT_PUBLISHING_DATE_FIELD_NAME)); assertNotNull(doc.getFieldValue(DEFAULT_PUBLISHING_DATE_ALT_FIELD_NAME)); assertEquals(SITE, subDoc2.getFieldValue(DEFAULT_SITE_FIELD_NAME)); assertEquals(SITE + ":" + IPAD_ID_ACCESSORIES1, subDoc2.getFieldValue(DEFAULT_ID_FIELD_NAME)); assertEquals(SITE + ":" + IPAD_ID, subDoc1.getFieldValue(DEFAULT_ROOT_ID_FIELD_NAME)); assertEquals(IPAD_ID_ACCESSORIES1, subDoc2.getFieldValue(DEFAULT_LOCAL_ID_FIELD_NAME)); assertEquals(SITE + ":" + IPAD_ID, subDoc2.getFieldValue(DEFAULT_PARENT_ID_FIELD_NAME)); assertEquals("product_accessories", subDoc2.getFieldValue(DEFAULT_CONTENT_TYPE_FIELD_NAME)); assertEquals("Lighting Cable", subDoc2.getFieldValue("accessories.item.name_s")); assertEquals("Lighting cable for iPad", subDoc2.getFieldValue("accessories.item.description_html").toString().trim()); assertEquals("iPad Air 64GB", subDoc2.getFieldValue("name_s")); assertEquals("iPad Air 64GB", subDoc2.getFieldValue("name_t")); assertEquals("Apple MH182LL/A iPad Air 9.7-Inch Retina Display 64GB, Wi-Fi (Gold)", subDoc2.getFieldValue("description_html").toString().trim()); assertEquals("2014-10-01T00:00:00.000Z", subDoc2.getFieldValue("availableDate_dt")); assertEquals(Arrays.asList("Apple", "iPad", "Tablet"), subDoc2.getFieldValues("tags.value_smv")); }