/** * Walk the category hierarchy upwards, adding a field for each level to the solr document * * @param document the solr document for the product * @param cache the catalog structure cache * @param categoryId the current category id */ protected void buildFullCategoryHierarchy(SolrInputDocument document, CatalogStructure cache, Long categoryId, Set<Long> indexedParents) { Long catIdToAdd = shs.getCategoryId(categoryId); Collection<Object> existingValues = document.getFieldValues(shs.getCategoryFieldName()); if (existingValues == null || !existingValues.contains(catIdToAdd)) { document.addField(shs.getCategoryFieldName(), catIdToAdd); } Set<Long> parents = cache.getParentCategoriesByCategory().get(categoryId); for (Long parent : parents) { if (!indexedParents.contains(parent)) { indexedParents.add(parent); buildFullCategoryHierarchy(document, cache, parent, indexedParents); } } }
/** * @see org.opencms.search.I_CmsSearchDocument#getMultivaluedFieldAsStringList(java.lang.String) */ public List<String> getMultivaluedFieldAsStringList(String fieldName) { List<String> result = new ArrayList<String>(); Collection<Object> coll = m_doc.getFieldValues(fieldName); if (coll != null) { for (Object o : coll) { if (o != null) { result.add(o.toString()); } } return result; } return null; }
private Collection<Object> getFieldValue(Object doc, String fieldName) { if (doc instanceof SolrDocument) { return ((SolrDocument)doc).getFieldValues(fieldName); } else if (doc instanceof SolrInputDocument) { return ((SolrInputDocument)doc).getFieldValues(fieldName); } throw new IllegalArgumentException("Unexpected object type: "+doc.getClass().getName()); }
private Collection<Object> getFieldValue(Object doc, String fieldName) { if (doc instanceof SolrDocument) { return ((SolrDocument)doc).getFieldValues(fieldName); } else if (doc instanceof SolrInputDocument) { return ((SolrInputDocument)doc).getFieldValues(fieldName); } throw new IllegalArgumentException("Unexpected object type: "+doc.getClass().getName()); }
static public Collection<String> getStringFieldValues ( SolrInputDocument d, String fieldname, WikittyTypes type) { // petit hack, car la methode retourne un Collection<Object> alors // qu'il sagit en fait d'un Collection<String>, de cette facon on force // la conversion en passant par une colleciton non typee String solrFieldName = SolrUtil.getSolrFieldName(fieldname, type); Collection tmp = d.getFieldValues(solrFieldName); Collection<String> result = (Collection<String>)tmp; return result; }
private void addField(SolrInputDocument doc, String fieldName, String value, float boost) { final Collection<Object> existingValues = doc.getFieldValues(fieldName); if (existingValues == null || !existingValues.contains(value)) { doc.addField(fieldName, value, boost); } }
/** * Adds a value to a document field, ensuring that the value is not duplicated. * * @param solrDocument the document to add the field value to * @param fieldName the field name * @param fieldValue the field value to add */ protected void addFieldValueOnce(SolrInputDocument solrDocument, String fieldName, Object fieldValue) { Collection<Object> fieldValues = solrDocument.getFieldValues(fieldName); if (fieldValues == null || !fieldValues.contains(fieldValue)) { solrDocument.addField(fieldName, fieldValue); } }
/** * Adds field name and multi-valued field value to the {@link SolrInputDocument} iff this value isn't already stored * in given field. * * @param doc the Solr input document * @param fieldName the name of the field to be added * @param fieldValue the value of the field being added */ private void addMultivaluedField(@Nonnull final SolrInputDocument doc, @Nonnull final String fieldName, @Nonnull final Object fieldValue) { if (!Optional.fromNullable(doc.getFieldValues(fieldName)).or(Collections.emptyList()).contains(fieldValue)) { doc.addField(fieldName, fieldValue); } }
/** * Adds field name and multi-valued field value to the {@link SolrInputDocument} iff this value isn't already stored * in given field. * * @param doc the Solr input document * @param fieldName the name of the field to be added * @param fieldValue the value of the field being added */ private void addMultivaluedField(@Nonnull final SolrInputDocument doc, @Nonnull final String fieldName, @Nonnull final Object fieldValue) { if (!Optional.fromNullable(doc.getFieldValues(fieldName)).or(Collections.emptyList()).contains(fieldValue)) { doc.addField(fieldName, fieldValue); } }
/** * Adds field name and multi-valued field value to the {@link SolrInputDocument} iff this value isn't already stored * in given field. * * @param doc the Solr input document * @param fieldName the name of the field to be added * @param fieldValue the value of the field being added */ private void addMultivaluedField(@Nonnull final SolrInputDocument doc, @Nonnull final String fieldName, @Nonnull final Object fieldValue) { if (!Optional.fromNullable(doc.getFieldValues(fieldName)).or(Collections.emptyList()).contains(fieldValue)) { doc.addField(fieldName, fieldValue); } }
/** * Pretty-print each solrDocument in the results to stdout * * @param out * @param doc */ protected static void prettyPrint(PrintStream out, SolrInputDocument doc) { List<String> sortedFieldNames = new ArrayList<String>( doc.getFieldNames()); Collections.sort(sortedFieldNames); out.println(); for (String field : sortedFieldNames) { out.println(String.format("\t%s: %s", field, doc.getFieldValues(field))); } out.println(); }
/** * Pretty-print each solrDocument in the results to stdout * * @param out * @param doc */ protected static void prettyPrint(PrintStream out, SolrInputDocument doc) { List<String> sortedFieldNames = new ArrayList<String>( doc.getFieldNames()); Collections.sort(sortedFieldNames); out.println(); for (String field : sortedFieldNames) { out.println(String.format("\t%s: %s", field, doc.getFieldValues(field))); } out.println(); }
/** * Update the {@code doc} with the {@code tissue} associated with it. * * @param doc the {@link SolrInputDocument} containing cancer data * @param tissue the tissue affected by the cancer */ private void updateTissue(@Nonnull final SolrInputDocument doc, @Nonnull final String tissue) { final Collection<Object> storedTissues = doc.getFieldValues(TISSUE); if (valueIsNotYetAdded(storedTissues, tissue)) { doc.addField(TISSUE, tissue); } }
private static void setSolrUpdateField(SolrInputDocument doc, String field, String value) { Map<String, String> operation = new HashMap<String, String>(); operation.put("set", value); // Check to see if this value is already in: boolean newValue = true; if (doc.getFieldValues(field) != null) { for (Object val : doc.getFieldValues(field)) { @SuppressWarnings("unchecked") Map<String, String> cmap = (Map<String, String>) val; if (cmap.values().contains(value)) newValue = false; } } // Add it if it is a new value: if (newValue) { LOG.info("Adding value: " + value + " to field: " + field + " for URI " + doc.getFieldValue(SolrFields.SOLR_URL)); doc.addField(field, operation); } else { LOG.debug("Skipping addition of existing field value: " + value + " to field: " + field); } }
private static void setSolrUpdateField(SolrInputDocument doc, String field, String value) { Map<String, String> operation = new HashMap<String, String>(); operation.put("set", value); // Check to see if this value is already in: boolean newValue = true; if (doc.getFieldValues(field) != null) { for (Object val : doc.getFieldValues(field)) { @SuppressWarnings("unchecked") Map<String, String> cmap = (Map<String, String>) val; if (cmap.values().contains(value)) newValue = false; } } // Add it if it is a new value: if (newValue) { LOG.info("Adding value: " + value + " to field: " + field + " for URI " + doc.getFieldValue(SolrFields.SOLR_URL)); doc.addField(field, operation); } else { LOG.debug("Skipping addition of existing field value: " + value + " to field: " + field); } }
/** * Add the field, truncating the value if it's larger than the given limit. * * @param solr_property * @param value * @param truncateTo */ public void addFieldTruncated(String solr_property, String value, int truncateTo) { value = sanitizeString(value, truncateTo); // If the value is not empty: if (value != null && !value.isEmpty()) { // Check if the value is already set: Collection<Object> values = doc.getFieldValues(solr_property); if (values == null || !values.contains(value)) { doc.addField(solr_property, value); } } }
/** * Updates the parents of the cancer that is currently being processed. * * @param doc the {@link SolrInputDocument} into which data is written * @param parent the {@link SolrInputDocument} that contains data for cancer that is a parent to the cancer stored * in {@code doc} */ private void updateParents(@Nonnull final SolrInputDocument doc, @Nullable final SolrInputDocument parent) { if (parent != null) { final String parentId = (String) parent.getFieldValue(ID); final Collection<Object> storedParents = doc.getFieldValues(IS_A); if (valueIsNotYetAdded(storedParents, parentId)) { doc.addField(IS_A, parentId); } final Set<Object> ancestorSet = new HashSet<>(); ancestorSet.add(parentId); final Collection<Object> parentIds = parent.getFieldValues(TERM_CATEGORY); if (CollectionUtils.isNotEmpty(parentIds)) { ancestorSet.addAll(parentIds); } doc.addField(TERM_CATEGORY, ancestorSet); } }
/** * Tries to extract the name of the cancer from the provided raw {@code value name} string, and writes it into * {@code doc}. * * @param doc the {@link SolrInputDocument} into which data is written * @param value the provided raw cancer name */ private void updateCancerName(@Nonnull final SolrInputDocument doc, @Nonnull final String value) { final String storedName = (String) doc.getFieldValue(NAME); final Collection<Object> synonyms = doc.getFieldValues(SYNONYM); if (StringUtils.isBlank(storedName)) { doc.setField(NAME, value); } else if (!storedName.equals(value) && valueIsNotYetAdded(synonyms, value)) { doc.addField(SYNONYM, value); } }
/** * Ajout les attachment du TreeNode passe en parametre sous forme de doc Solr * @param doc TreeNode document representation */ public void add(SolrInputDocument doc) { String id = (String)doc.getFieldValue(WikittySolrConstant.SOLR_ID); Collection att = doc.getFieldValues(SolrUtil.getSolrFieldName( WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_ATTACHMENT, TYPE.WIKITTY)); add(id, att); }
/** * @param doc TreeNode document representation */ public void remove(SolrInputDocument doc) { String id = (String)doc.getFieldValue(WikittySolrConstant.SOLR_ID); Collection att = doc.getFieldValues(SolrUtil.getSolrFieldName( WikittyTreeNode.FQ_FIELD_WIKITTYTREENODE_ATTACHMENT, TYPE.WIKITTY)); remove(id, att); }