private void commitDocumentChanges(String collectionName, Collection<SolrInputDocument> documents) throws SolrServerException, IOException { if (documents.size() == 0) return; try { solrClient.request(newUpdateRequest().add(documents), collectionName); } catch (HttpSolrClient.RemoteSolrException rse) { logger.error("Unable to save documents to Solr as one of the shape objects stored were not compatible with Solr.", rse); logger.error("Details in failed document batch: "); for (SolrInputDocument d : documents) { Collection<String> fieldNames = d.getFieldNames(); for (String name : fieldNames) { logger.error(name + ":" + d.getFieldValue(name).toString()); } } throw rse; } }
/** * @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); }
/** * @param fieldname * @return */ public Object getFieldValue(String fieldname) { return doc.getFieldValue(fieldname); }
/** * 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 fieldname * @return */ public Object getFieldValue(String fieldname) { return doc.getFieldValue(fieldname); }
protected String getId(SolrInputDocument sdoc, SolrParams params) { Object idObj = sdoc.getFieldValue(ID); // blech String id = idObj != null ? idObj.toString() : "null"; // should only happen on client side return id; }
protected String getId(SolrInputDocument sdoc, SolrParams params) { Object idObj = sdoc.getFieldValue("id"); // blech String id = idObj != null ? idObj.toString() : "null"; // should only happen on client side return id; }
/** * @see org.opencms.search.I_CmsSearchDocument#getContentBlob() */ public byte[] getContentBlob() { Object o = m_doc.getFieldValue(CmsSearchField.FIELD_CONTENT_BLOB); if (o != null) { if (o instanceof byte[]) { return (byte[])o; } return o.toString().getBytes(); } return null; }
protected String getCurrentFieldValue(SolrInputDocument doc, String fieldName) { StringBuffer sb = new StringBuffer(); if (doc.containsKey(fieldName)) { Object content = doc.getFieldValue(fieldName); if (content instanceof String) { sb.append((String) doc.getFieldValue(fieldName)); sb.append(" "); } else { log.warn("Field " + fieldName + " not a String value, not including in detection"); } } return sb.toString(); }
@Override public void processAdd(AddUpdateCommand cmd) throws IOException { SolrInputDocument doc = cmd.getSolrInputDocument(); String appid = (String)doc.getFieldValue( "appid" ); String docid = (String)doc.getFieldValue( "docid" ); doc.addField("uniqueid", appid + "-" + docid); // pass it up the chain super.processAdd(cmd); }
/** * Adds field name and single-valued value to the {@link SolrInputDocument} iff the value isn't already stored in * the 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 addSingleValuedField(@Nonnull final SolrInputDocument doc, @Nonnull final String fieldName, @Nonnull final Object fieldValue) { if (!fieldValue.equals(doc.getFieldValue(fieldName))) { doc.addField(fieldName, fieldValue); } }
/** * Adds field name and single-valued value to the {@link SolrInputDocument} iff the value isn't already stored in * the 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 addSingleValuedField(@Nonnull final SolrInputDocument doc, @Nonnull final String fieldName, @Nonnull final Object fieldValue) { if (!fieldValue.equals(doc.getFieldValue(fieldName))) { doc.addField(fieldName, fieldValue); } }
/** * Adds field name and single-valued value to the {@link SolrInputDocument} iff the value isn't already stored in * the 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 addSingleValuedField(@Nonnull final SolrInputDocument doc, @Nonnull final String fieldName, @Nonnull final Object fieldValue) { if (!fieldValue.equals(doc.getFieldValue(fieldName))) { doc.addField(fieldName, fieldValue); } }
public SolrClient client(SolrInputDocument sdoc, SolrParams params) { String idStr = null; if (sdoc != null) { idStr = sdoc.getFieldValue(idField).toString(); } else if (params!=null) { idStr = params.get(idField); } int hash; if (idStr != null) { // make the client chosen the same for a duplicate ID hash = idStr.hashCode() ^ hashSeed; } else { hash = r.nextInt(); } return clients.get( (hash & Integer.MAX_VALUE) % clients.size() ); }
/** * @see org.opencms.search.I_CmsSearchDocument#getFieldValueAsString(java.lang.String) */ public String getFieldValueAsString(String fieldName) { List<String> values = getMultivaluedFieldAsStringList(fieldName); if ((values != null) && !values.isEmpty()) { return CmsStringUtil.listAsString(values, "\n"); } else { Object o = m_doc.getFieldValue(fieldName); if (o != null) { return o.toString(); } } return null; }
/** * get value of field in SolrDocument, field must have only one value * @param d * @param fieldname * @param type optional type to generate solr field name * @return */ static public String getStringFieldValue( SolrInputDocument d, String fieldname, WikittyTypes type) { String solrFieldName = SolrUtil.getSolrFieldName(fieldname, type); Object value = d.getFieldValue(solrFieldName); String result = convertToString(value, solrFieldName); return result; }
private void commitDocumentChanges(String collectionName, Collection<SolrInputDocument> documents) throws SolrServerException, IOException { if (documents.size() == 0) return; try { solrClient.request(newUpdateRequest().add(documents), collectionName); } catch (HttpSolrClient.RemoteSolrException rse) { logger.error("Unable to save documents to Solr as one of the shape objects stored were not compatible with Solr.", rse); logger.error("Details in failed document batch: "); for (SolrInputDocument d : documents) { Collection<String> fieldNames = d.getFieldNames(); for (String name : fieldNames) { logger.error(name + ":" + d.getFieldValue(name).toString()); } } throw rse; } }
private void commitChanges(String collectionName, Collection<SolrInputDocument> documents) throws SolrServerException, IOException { if (documents.size() == 0) return; try { solrClient.request(newUpdateRequest().add(documents), collectionName); } catch (final HttpSolrClient.RemoteSolrException rse) { logger.error("Unable to save documents to Solr as one of the shape objects stored were not compatible with Solr.", rse); logger.error("Details in failed document batch: "); for (final SolrInputDocument d : documents) { final Collection<String> fieldNames = d.getFieldNames(); for (final String name : fieldNames) { logger.error(name + ":" + d.getFieldValue(name)); } } throw rse; } }
@Override public int sliceHash(String id, SolrInputDocument doc, SolrParams params, DocCollection collection) { String shardFieldName = getRouteField(collection); if (shardFieldName != null && doc != null) { Object o = doc.getFieldValue(shardFieldName); if (o == null) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No value for :" + shardFieldName + ". Unable to identify shard"); id = o.toString(); } if (id.indexOf(SEPARATOR) < 0) { return Hash.murmurhash3_x86_32(id, 0, id.length(), 0); } return new KeyParser(id).getHash(); }
@Override public int sliceHash(String id, SolrInputDocument doc, SolrParams params, DocCollection collection) { String shardFieldName = getRouteField(collection); if (shardFieldName != null && doc != null) { Object o = doc.getFieldValue(shardFieldName); if (o == null) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No value for :" + shardFieldName + ". Unable to identify shard"); id = o.toString(); } if (id.indexOf(SEPARATOR) < 0) { return Hash.murmurhash3_x86_32(id, 0, id.length(), 0); } return new KeyParser(id).getHash(); }