if (document.getField(categorySortFieldName) == null && displayOrder != null) { document.addField(categorySortFieldName, displayOrder);
/** * @param fieldname * @return */ public SolrInputField getField(String fieldname) { return doc.getField(fieldname); }
/** * @param fieldname * @return */ public SolrInputField getField(String fieldname) { return doc.getField(fieldname); }
private String extractIdFromSolrInputDocument(SolrInputDocument solrInputDocument) { Assert.notNull(solrInputDocument.getField(idFieldName), "Unable to find field '" + idFieldName + "' in SolrDocument."); Assert.notNull(solrInputDocument.getField(idFieldName).getValue(), "ID must not be 'null'."); return solrInputDocument.getField(idFieldName).getValue().toString(); }
/** Get the first value for a field. * * @param name name of the field to fetch * @return first value of the field or null if not present */ public Object getFieldValue(String name) { SolrInputField field = getField(name); Object o = null; if (field!=null) o = field.getFirstValue(); return o; }
/** Get the first value for a field. * * @param name name of the field to fetch * @return first value of the field or null if not present */ @Override public Object getFieldValue(String name) { SolrInputField field = getField(name); Object o = null; if (field!=null) o = field.getFirstValue(); return o; }
/** Get all the values for a field. * * @param name name of the field to fetch * @return value of the field or null if not set */ @Override public Collection<Object> getFieldValues(String name) { SolrInputField field = getField(name); if (field!=null) { return field.getValues(); } return null; }
/** Get the first value for a field. * * @param name name of the field to fetch * @return first value of the field or null if not present */ public Object getFieldValue(String name) { SolrInputField field = getField(name); Object o = null; if (field!=null) o = field.getFirstValue(); return o; }
/** Get all the values for a field. * * @param name name of the field to fetch * @return value of the field or null if not set */ public Collection<Object> getFieldValues(String name) { SolrInputField field = getField(name); if (field!=null) { return field.getValues(); } return null; }
/** Get all the values for a field. * * @param name name of the field to fetch * @return value of the field or null if not set */ public Collection<Object> getFieldValues(String name) { SolrInputField field = getField(name); if (field!=null) { return field.getValues(); } return null; }
@Override public int compare(SolrInputDocument doc1, SolrInputDocument doc2) { SolrInputField f1 = doc1.getField(fieldName); SolrInputField f2 = doc2.getField(fieldName); if (f1 == f2) { return 0; } else if (f1 == null) { return -1; } else if (f2 == null) { return 1; } Object v1 = f1.getFirstValue(); Object v2 = f2.getFirstValue(); return child.compare(v1, v2); }
@Override public int compare(SolrInputDocument doc1, SolrInputDocument doc2) { SolrInputField f1 = doc1.getField(fieldName); SolrInputField f2 = doc2.getField(fieldName); if (f1 == f2) { return 0; } else if (f1 == null) { return -1; } else if (f2 == null) { return 1; } Object v1 = f1.getFirstValue(); Object v2 = f2.getFirstValue(); return child.compare(v1, v2); }
/** * Indexes the document in both the control client, and a randomly selected client */ protected void indexDoc(SolrInputDocument doc) throws IOException, SolrServerException { controlClient.add(doc); if (shardCount == 0) {//mostly for temp debugging return; } int which = (doc.getField(id).toString().hashCode() & 0x7fffffff) % clients.size(); SolrClient client = clients.get(which); client.add(doc); }
/** * Write the document to the solr index * * @param doc the solr document * @throws IOException if IO error */ protected void writeDocument(SolrInputDocument doc) throws IOException { try { getSolr().add(doc); } catch (Exception e) { try { log.error("An error occurred for document: " + doc.getField("id").getFirstValue() + ", source: " + doc .getField("source").getFirstValue() + ", field: " + doc.getField("field") .getFirstValue() + ", full-text: " + doc .getField("full-text").getFirstValue(), e); } catch (Exception e1) { //shouldn't happen } log.error(e.getMessage(), e); } }
@Override public Object get(String key) { // We have to override this because in Solr 5.5 SolrInputDocument#get wrongly forwards to #getFirstValue if (isNull()) { return null; } SolrInputField field = ((SolrInputDocument) this.doc).getField(key); if (field == null) { return null; } return field.getValue(); }
public void classifyDocument(SolrInputDocument doc) throws IOException { try { //<start id="mahout.bayes.classify"/> SolrInputField field = doc.getField(inputField); String[] tokens = tokenizeField(inputField, field); ClassifierResult result = ctx.classifyDocument(tokens, defaultCategory); if (result != null && result.getLabel() != NO_LABEL) { doc.addField(outputField, result.getLabel()); } //<end id="mahout.bayes.classify"/> } catch (InvalidDatastoreException e) { throw new IOException("Invalid Classifier Datastore", e); } }
private IndexResult indexSingleDocument(Document doc, int withinMs) { final SolrInputDocument document = createInputDocument(doc); try { if (solrClientLogger.isTraceEnabled()) { solrClientLogger.debug(">>> add({}): {}", doc.getId(), ClientUtils.toXML(document)); } else { solrClientLogger.debug(">>> add({})", doc.getId()); } removeNonParentDocument(doc, withinMs); final UpdateResponse response = withinMs < 0 ? this.solrClient.add(document) : this.solrClient.add(document, withinMs); return new IndexResult(Long.valueOf(response.getQTime())).setElapsedTime(response.getElapsedTime()); } catch (SolrServerException | IOException e) { log.error("Cannot index document {}", document.getField(ID) , e); throw new SearchServerException("Cannot index document", e); } }
public String getPrintableId(IndexSchema schema) { SchemaField sf = schema.getUniqueKeyField(); if (indexedId != null) { return schema.getUniqueKeyField().getType().indexedToReadable(indexedId); } if (doc != null) { return schema.printableUniqueKey(doc); } if (solrDoc != null) { SolrInputField field = solrDoc.getField(sf.getName()); if (field != null) { return field.getFirstValue().toString(); } } return "(null)"; }