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 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); } } }
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);
LumongoUtil.handleLists(o, obj -> { LumongoUtil.handleLists(o, obj -> { if (obj instanceof Boolean) { String text = obj.toString(); LumongoUtil.handleLists(o, obj -> { String text = o.toString();
LumongoUtil.handleLists(storeFieldValues, (value) -> { String content = value.toString(); try (TokenStream tokenStream = analyzer.tokenStream(indexField, content)) {
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); } } }