public static Document getDocumentFromResultDocument(Lumongo.ResultDocumentOrBuilder rd) { if (rd.hasDocument()) { return LumongoUtil.byteArrayToMongoDocument(rd.getDocument().toByteArray()); } return null; }
public void index(Document document, String storedFieldName, Object storedValue, String indexedFieldName) throws Exception { LumongoUtil.handleLists(storedValue, obj -> { try { handleValue(document, storedFieldName, obj, indexedFieldName); } catch (Exception e) { throw new RuntimeException(e); } }); }
public ResultDocBuilder setDocument(Document document) { resultDocumentBuilder.setDocument(ByteString.copyFrom(LumongoUtil.mongoDocumentToByteArray(document))); return this; }
public Document getDocument() { if (fetchResponse.hasResultDocument()) { ResultDocument rd = fetchResponse.getResultDocument(); if (rd.hasDocument()) { return LumongoUtil.byteArrayToMongoDocument(rd.getDocument().toByteArray()); } } return null; }
public static void handleLists(Object o, Consumer<? super Object> action) { if (o instanceof Collection) { Collection<?> c = (Collection<?>) o; c.stream().filter(Objects::nonNull).forEach(obj -> { if (obj instanceof Collection) { handleLists(obj, action); } else { action.accept(obj); } }); } else if (o instanceof Object[]) { Object[] arr = (Object[]) o; for (Object obj : arr) { if (obj != null) { action.accept(action); } } } else { if (o != null) { action.accept(o); } } }
public AssociatedBuilder setDocument(Document document) { adBuilder.setDocument(ByteString.copyFrom(LumongoUtil.mongoDocumentToByteArray(document))); return this; }
Document document; if (resultDocument.hasDocument()) { document = LumongoUtil.byteArrayToMongoDocument(resultDocument.getDocument().toByteArray());
LumongoUtil.handleLists(o, obj -> { if (obj instanceof Date) { LocalDate localDate = ((Date) (obj)).toInstant().atZone(ZoneId.of("UTC")).toLocalDate(); LumongoUtil.handleLists(o, obj -> { String string = obj.toString(); addFacet(doc, facetName, string);
private ResultDocument filterDocument(ResultDocument rd, List<String> fieldsToReturn, List<String> fieldsToMask, org.bson.Document mongoDocument) { ResultDocument.Builder resultDocBuilder = rd.toBuilder(); if (!fieldsToReturn.isEmpty()) { for (String key : new ArrayList<>(mongoDocument.keySet())) { if (!fieldsToReturn.contains(key)) { mongoDocument.remove(key); } } } if (!fieldsToMask.isEmpty()) { for (String field : fieldsToMask) { mongoDocument.remove(field); } } ByteString document = ByteString.copyFrom(LumongoUtil.mongoDocumentToByteArray(mongoDocument)); resultDocBuilder.setDocument(document); return resultDocBuilder.build(); }
BytesRef metaRef = d.getBinaryValue(LumongoConstants.STORED_META_FIELD); org.bson.Document metaMongoDoc = new org.bson.Document(); metaMongoDoc.putAll(LumongoUtil.byteArrayToMongoDocument(metaRef.bytes));
LumongoUtil.handleLists(o, obj -> { LumongoUtil.handleLists(o, obj -> { if (obj instanceof Boolean) { String text = obj.toString(); LumongoUtil.handleLists(o, obj -> { String text = o.toString();
public void index(String uniqueId, long timestamp, org.bson.Document mongoDocument, List<Metadata> metadataList) throws Exception { reopenIndexWritersIfNecessary(); Document luceneDocument = new Document(); addStoredFieldsForDocument(mongoDocument, luceneDocument); luceneDocument.add(new StringField(LumongoConstants.ID_FIELD, uniqueId, Store.YES)); luceneDocument.add(new LongPoint(LumongoConstants.TIMESTAMP_FIELD, timestamp)); luceneDocument.add(new StoredField(LumongoConstants.TIMESTAMP_FIELD, timestamp)); if (indexConfig.getIndexSettings().getStoreDocumentInIndex()) { luceneDocument.add(new StoredField(LumongoConstants.STORED_DOC_FIELD, new BytesRef(LumongoUtil.mongoDocumentToByteArray(mongoDocument)))); org.bson.Document metadataMongoDoc = new org.bson.Document(); for (Metadata metadata : metadataList) { metadataMongoDoc.put(metadata.getKey(), metadata.getValue()); } luceneDocument.add(new StoredField(LumongoConstants.STORED_META_FIELD, new BytesRef(LumongoUtil.mongoDocumentToByteArray(metadataMongoDoc)))); } luceneDocument = facetsConfig.build(taxoWriter, luceneDocument); Term term = new Term(LumongoConstants.ID_FIELD, uniqueId); indexWriter.updateDocument(term, luceneDocument); possibleCommit(); }
if (resultDocument.hasDocument()) { Document mongoDocument = new Document(); mongoDocument.putAll(LumongoUtil.byteArrayToMongoDocument(resultDocument.getDocument().toByteArray())); System.out.println(mongoDocument);
private void handleHighlight(List<LumongoHighlighter> highlighterList, ScoredResult.Builder srBuilder, org.bson.Document doc) { for (LumongoHighlighter highlighter : highlighterList) { HighlightRequest highlightRequest = highlighter.getHighlight(); String indexField = highlightRequest.getField(); String storedFieldName = indexConfig.getStoredFieldName(indexField); if (storedFieldName != null) { HighlightResult.Builder highLightResult = HighlightResult.newBuilder(); highLightResult.setField(storedFieldName); Object storeFieldValues = ResultHelper.getValueFromMongoDocument(doc, storedFieldName); LumongoUtil.handleLists(storeFieldValues, (value) -> { String content = value.toString(); TokenStream tokenStream = perFieldAnalyzer.tokenStream(indexField, content); try { TextFragment[] bestTextFragments = highlighter .getBestTextFragments(tokenStream, content, false, highlightRequest.getNumberOfFragments()); for (TextFragment bestTextFragment : bestTextFragments) { if (bestTextFragment != null && bestTextFragment.getScore() > 0) { highLightResult.addFragments(bestTextFragment.toString()); } } } catch (Exception e) { throw new RuntimeException(e); } }); srBuilder.addHighlightResult(highLightResult); } } }
LumongoUtil.handleLists(storeFieldValues, (value) -> { String content = value.toString(); try (TokenStream tokenStream = analyzer.tokenStream(indexField, content)) {