public SolrInputDocument toSolrInputDocument(SolrDocument d) { final SolrInputDocument doc = new SolrInputDocument(); for (String name : d.getFieldNames()) { doc.addField(name, d.getFieldValue(name)); } return doc; } }
/** * @param doc TreeNode document representation */ public void remove(SolrDocument 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); }
/** * Given a list of Sku IDs from solr, this method will look up the IDs via the skuDao and build out * actual Sku instances. It will return a Sku list that is sorted by the order of the IDs in the passed * in list. * * @param response * @return the actual Sku instances as a result of the search */ protected List<Sku> getSkus(List<SolrDocument> responseDocuments) { final List<Long> skuIds = new ArrayList<>(); for (SolrDocument doc : responseDocuments) { skuIds.add((Long) doc.getFieldValue(shs.getIndexableIdFieldName())); } List<Sku> skus = skuDao.readSkusByIds(skuIds); extensionManager.getProxy().batchFetchCatalogDataForSkus(skus); // We have to sort the skus list by the order of the skuIds list to maintain sortability in the UI if (skus != null) { Collections.sort(skus, new Comparator<Sku>() { @Override public int compare(Sku o1, Sku o2) { return new Integer(skuIds.indexOf(o1.getId())).compareTo(skuIds.indexOf(o2.getId())); } }); } return skus; }
/** * Writes each SolrDocument to a record. */ public static RecordSet solrDocumentsToRecordSet(final List<SolrDocument> docs, final RecordSchema schema) { final List<Record> lr = new ArrayList<Record>(); for (SolrDocument doc : docs) { final Map<String, Object> recordValues = new LinkedHashMap<>(); for (RecordField field : schema.getFields()){ final Object fieldValue = doc.getFieldValue(field.getFieldName()); if (fieldValue != null) { if (field.getDataType().getFieldType().equals(RecordFieldType.ARRAY)){ recordValues.put(field.getFieldName(), ((List<Object>) fieldValue).toArray()); } else { recordValues.put(field.getFieldName(), fieldValue); } } } lr.add(new MapRecord(schema, recordValues)); } return new ListRecordSet(schema, lr); }
double score = Double.parseDouble(hit.getFieldValue("score").toString()); result.add(new RawQuery.Result<String>(hit.getFieldValue(keyIdField).toString(), score));
/** * Given a list of product IDs from solr, this method will look up the IDs via the productDao and build out * actual Product instances. It will return a Products that is sorted by the order of the IDs in the passed * in list. * * @param response * @return the actual Product instances as a result of the search */ protected List<Product> getProducts(List<SolrDocument> responseDocuments) { final List<Long> productIds = new ArrayList<>(); for (SolrDocument doc : responseDocuments) { productIds.add((Long) doc.getFieldValue(shs.getIndexableIdFieldName())); } List<Product> products = productDao.readProductsByIds(productIds); extensionManager.getProxy().batchFetchCatalogData(products); // We have to sort the products list by the order of the productIds list to maintain sortability in the UI if (products != null) { Collections.sort(products, new Comparator<Product>() { @Override public int compare(Product o1, Product o2) { Long o1id = shs.getIndexableId(o1); Long o2id = shs.getIndexableId(o2); return new Integer(productIds.indexOf(o1id)).compareTo(productIds.indexOf(o2id)); } }); } extensionManager.getProxy().modifySearchResults(responseDocuments, products); return products; }
result.add(hit.getFieldValue(keyIdField).toString());
public static Document toDocument(SolrDocument solrDocument) { Map<String, Object> document = new HashMap<>(); solrDocument.getFieldNames().stream() .filter(name -> !name.equals(SolrDao.VERSION_FIELD)) .forEach(name -> document.put(name, solrDocument.getFieldValue(name))); reformatComments(solrDocument, document); insertChildAlerts(solrDocument, document); return new Document(document, (String) solrDocument.getFieldValue(Constants.GUID), (String) solrDocument.getFieldValue(Constants.SENSOR_TYPE), 0L); }
protected static void insertChildAlerts(SolrDocument solrDocument, Map<String, Object> document) { // Make sure to put child alerts in if (solrDocument.hasChildDocuments() && solrDocument .getFieldValue(Constants.SENSOR_TYPE) .equals(MetaAlertConstants.METAALERT_TYPE)) { List<Map<String, Object>> childDocuments = new ArrayList<>(); for (SolrDocument childDoc : solrDocument.getChildDocuments()) { Map<String, Object> childDocMap = new HashMap<>(); childDoc.getFieldNames().stream() .filter(name -> !name.equals(SolrDao.VERSION_FIELD)) .forEach(name -> childDocMap.put(name, childDoc.getFieldValue(name))); childDocuments.add(childDocMap); } document.put(MetaAlertConstants.ALERT_FIELD, childDocuments); } }
public static SearchResult getSearchResult(SolrDocument solrDocument, List<String> fields, Function<String, String> indexSupplier) { SearchResult searchResult = new SearchResult(); searchResult.setId((String) solrDocument.getFieldValue(Constants.GUID)); searchResult.setIndex(indexSupplier.apply((String) solrDocument.getFieldValue(Constants.SENSOR_TYPE))); Map<String, Object> docSource = toDocument(solrDocument).getDocument(); final Map<String, Object> source = new HashMap<>(); if (fields != null) { fields.forEach(field -> source.put(field, docSource.get(field))); } else { source.putAll(docSource); } searchResult.setSource(source); return searchResult; }
/** * Get date value * * @param doc * @param field * @return */ private Date dGet(SolrDocument doc, String field) { return (Date) doc.getFieldValue(field); }
@Override public Object get(String name) { return this.doc != null ? this.doc.getFieldValue(name) : null; }
@Override public Map<String,Object> next() { SolrDocument solrDocument = solrDocumentIterator.next(); HashMap<String,Object> map = new HashMap<>(); Collection<String> fields = solrDocument.getFieldNames(); for (String field : fields) { Object fieldValue = solrDocument.getFieldValue(field); map.put(field, fieldValue); } return map; }
void prettyPrint(PrintStream out, SolrDocument 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.getFieldValue(field))); } out.println(); } }
public static TarjontaTila createTila(SolrDocument doc) { String tila = "" + doc.getFieldValue(TILA); if (tila.isEmpty()) { return null; } try { return TarjontaTila.valueOf(tila); } catch (Exception e) { log.debug("Ignored unknown state: " + tila, e); return null; } }
@Override public AuthorityValue fromSolr(SolrDocument solrDocument) { String type = (String) solrDocument.getFieldValue("authority_type"); AuthorityValue value = authorityTypes.getEmptyAuthorityValue(type); value.setValues(solrDocument); return value; }
public static void doQuery(SolrClient ss, String id) throws SolrServerException, IOException { SolrParams p = new SolrQuery("id:\"" + id + "\""); QueryResponse r = ss.query(p); System.out.println("GOT collection " + r.getResults().get(0).getFieldValue("collection")); System.out.println("GOT collections " + r.getResults().get(0).getFieldValue("collections")); System.out.println("STILL GOT crawl_date " + r.getResults().get(0).getFieldValue("crawl_date")); }
@Override public Stream<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever information, BaseTransaction tx) throws BackendException { final String collection = query.getStore(); final String keyIdField = getKeyFieldId(collection); return executeQuery(query.hasLimit() ? query.getLimit() : null, query.getOffset(), collection, runCommonQuery(query, information, tx, collection, keyIdField), doc -> { final double score = Double.parseDouble(doc.getFieldValue("score").toString()); return new RawQuery.Result<>(doc.getFieldValue(keyIdField).toString(), score); }); }
@Override public void process(SolrDocument doc) throws IOException, SolrServerException { doc.removeFields("isBot"); doc.addField("isBot", true); SolrInputDocument newInput = ClientUtils.toSolrInputDocument(doc); solr.add(newInput); log.info("Marked " + doc.getFieldValue("ip") + " as bot"); } };
@Override public Object getValueAt(int rowIndex, int columnIndex) { String columnName = getColumnName(columnIndex); if(response.getHighlighting() != null && response.getHighlighting().get(columnName) != null) { System.out.println(response.getHighlighting().get(columnName)); } return response.getResults().get(rowIndex).getFieldValue(columnName); }