Java Code Examples for org.apache.solr.common.SolrInputField#getValueCount()
The following examples show how to use
org.apache.solr.common.SolrInputField#getValueCount() .
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: AddUpdateCommand.java From lucene-solr with Apache License 2.0 | 6 votes |
/** Returns the indexed ID for this document. The returned BytesRef is retained across multiple calls, and should not be modified. */ public BytesRef getIndexedId() { if (indexedId == null) { IndexSchema schema = req.getSchema(); SchemaField sf = schema.getUniqueKeyField(); if (sf != null) { if (solrDoc != null) { SolrInputField field = solrDoc.getField(sf.getName()); int count = field==null ? 0 : field.getValueCount(); if (count == 0) { if (overwrite) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Document is missing mandatory uniqueKey field: " + sf.getName()); } } else if (count > 1) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Document contains multiple values for uniqueKey field: " + field); } else { BytesRefBuilder b = new BytesRefBuilder(); sf.getType().readableToIndexed(field.getFirstValue().toString(), b); indexedId = b.get(); } } } } return indexedId; }
Example 2
Source File: AddUpdateCommand.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * @return String id to hash */ public String getHashableId() { IndexSchema schema = req.getSchema(); SchemaField sf = schema.getUniqueKeyField(); if (sf != null) { if (solrDoc != null) { SolrInputField field = solrDoc.getField(sf.getName()); int count = field == null ? 0 : field.getValueCount(); if (count == 0) { if (overwrite) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Document is missing mandatory uniqueKey field: " + sf.getName()); } } else if (count > 1) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Document contains multiple values for uniqueKey field: " + field); } else { return field.getFirstValue().toString(); } } } return null; }
Example 3
Source File: AtomicUpdateDocumentMerger.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * * @param fullDoc the full doc to be compared against * @param partialDoc the sub document to be tested * @return whether partialDoc is derived from fullDoc */ public static boolean isDerivedFromDoc(SolrInputDocument fullDoc, SolrInputDocument partialDoc) { for(SolrInputField subSif: partialDoc) { Collection<Object> fieldValues = fullDoc.getFieldValues(subSif.getName()); if (fieldValues == null) return false; if (fieldValues.size() < subSif.getValueCount()) return false; Collection<Object> partialFieldValues = subSif.getValues(); // filter all derived child docs from partial field values since they fail List#containsAll check (uses SolrInputDocument#equals which fails). // If a child doc exists in partialDoc but not in full doc, it will not be filtered, and therefore List#containsAll will return false Stream<Object> nonChildDocElements = partialFieldValues.stream().filter(x -> !(isChildDoc(x) && (fieldValues.stream().anyMatch(y -> (isChildDoc(x) && isDerivedFromDoc((SolrInputDocument) y, (SolrInputDocument) x) ) ) ))); if (!nonChildDocElements.allMatch(fieldValues::contains)) return false; } return true; }
Example 4
Source File: FieldValueMutatingUpdateProcessor.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override protected final SolrInputField mutate(final SolrInputField src) { Collection<Object> values = src.getValues(); if(values == null) return src;//don't mutate SolrInputField result = new SolrInputField(src.getName()); for (final Object srcVal : values) { final Object destVal = mutateValue(srcVal); if (DELETE_VALUE_SINGLETON == destVal) { /* NOOP */ if (log.isDebugEnabled()) { log.debug("removing value from field '{}': {}", src.getName(), srcVal); } } else { if (destVal != srcVal) { if (log.isDebugEnabled()) { log.debug("replace value from field '{}': {} with {}", new Object[]{src.getName(), srcVal, destVal}); } } result.addValue(destVal); } } return 0 == result.getValueCount() ? null : result; }
Example 5
Source File: RowMutationHelper.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
private static RecordMutation createRecordMutation(SolrInputDocument doc, String id) { RecordMutation recordMutation = new RecordMutation(); // TODO: what's solr default behavior? recordMutation.setRecordMutationType(RecordMutationType.REPLACE_ENTIRE_RECORD); Record record = new Record(); record.setFamily(findFamily(doc)); record.setRecordId(id); for (String fieldName : doc.getFieldNames()) { if (!fieldName.contains(".")) { continue; } SolrInputField field = doc.getField(fieldName); String rawColumnName = fieldName.substring(fieldName.indexOf(".") + 1, fieldName.length()); if (field.getValueCount() > 1) { for (Object fieldVal : field.getValues()) { record.addToColumns(new Column(rawColumnName, fieldVal.toString())); } } else { record.addToColumns(new Column(rawColumnName, field.getFirstValue().toString())); } } recordMutation.setRecord(record); return recordMutation; }
Example 6
Source File: MCRSolrFileIndexHandler.java From mycore with GNU General Public License v3.0 | 5 votes |
private ModifiableSolrParams getSolrParams(Path file, BasicFileAttributes attrs) throws IOException { ModifiableSolrParams params = new ModifiableSolrParams(); SolrInputDocument doc = MCRSolrPathDocumentFactory.getInstance().getDocument(file, attrs); for (SolrInputField field : doc) { String name = "literal." + field.getName(); if (field.getValueCount() > 1) { String[] values = getValues(field.getValues()); params.set(name, values); } else { params.set(name, field.getValue().toString()); } } return params; }
Example 7
Source File: AllValuesOrNoneFieldMutatingUpdateProcessor.java From lucene-solr with Apache License 2.0 | 4 votes |
protected final SolrInputField mutate(final SolrInputField srcField) { Collection<Object> vals = srcField.getValues(); if(vals== null || vals.isEmpty()) return srcField; List<String> messages = null; SolrInputField result = new SolrInputField(srcField.getName()); for (final Object srcVal : vals) { final Object destVal = mutateValue(srcVal); if (SKIP_FIELD_VALUE_LIST_SINGLETON == destVal) { if (log.isDebugEnabled()) { log.debug("field '{}' {} value '{}' is not mutable, so no values will be mutated", new Object[]{srcField.getName(), srcVal.getClass().getSimpleName(), srcVal}); } return srcField; } if (DELETE_VALUE_SINGLETON == destVal) { if (log.isDebugEnabled()) { if (null == messages) { messages = new ArrayList<>(); } messages.add(String.format(Locale.ROOT, "removing value from field '%s': %s '%s'", srcField.getName(), srcVal.getClass().getSimpleName(), srcVal)); } } else { if (log.isDebugEnabled()) { if (null == messages) { messages = new ArrayList<>(); } messages.add(String.format(Locale.ROOT, "replace value from field '%s': %s '%s' with %s '%s'", srcField.getName(), srcVal.getClass().getSimpleName(), srcVal, destVal.getClass().getSimpleName(), destVal)); } result.addValue(destVal); } } if (null != messages && log.isDebugEnabled()) { for (String message : messages) { log.debug(message); } } return 0 == result.getValueCount() ? null : result; }