@Override public OIdentifiable next() { if (localIndex == array.length) { localIndex = 0; fetchMoreResult(); } final ScoreDoc score = array[localIndex++]; Document ret = null; OContextualRecordId res = null; try { ret = queryContext.searcher.doc(score.doc); String rId = ret.get(OLuceneIndexManagerAbstract.RID); res = new OContextualRecordId(rId); manager.onRecordAddedToResultSet(queryContext, res, ret, score); } catch (IOException e) { e.printStackTrace(); } index++; return res; }
public void setElement(OIdentifiable element) { if (element instanceof OElement) { this.element = element; } else if (element instanceof OIdentifiable) { this.element = element.getRecord(); } else { this.element = element; } if (element instanceof OContextualRecordId) { this.addMetadata(((OContextualRecordId) element).getContext()); } }
@Override public void onRecordAddedToResultSet(QueryContext queryContext, OContextualRecordId recordId, Document ret, final ScoreDoc score) { recordId.setContext(new HashMap<String, Object>() { { put("score", score.score); } }); }
@Override public void onRecordAddedToResultSet(OLuceneQueryContext queryContext, OContextualRecordId recordId, Document ret, final ScoreDoc score) { recordId.setContext(new HashMap<String, Object>() {{ HashMap<String, TextFragment[]> frag = queryContext.getFragments(); frag.entrySet().stream().forEach(f -> { TextFragment[] fragments = f.getValue(); StringBuilder hlField = new StringBuilder(); for (int j = 0; j < fragments.length; j++) { if ((fragments[j] != null) && (fragments[j].getScore() > 0)) { hlField.append(fragments[j].toString()); } } put("$" + f.getKey() + "_hl", hlField.toString()); }); put("$score", score.score); }}); }
Map<String, Object> meta = ((OContextualRecordId) iCurrentRecord).getContext(); if (meta != null && meta.containsKey(varName)) { return meta.get(varName);
private OContextualRecordId toRecordId(Document doc, ScoreDoc score) { String rId = doc.get(OLuceneIndexEngineAbstract.RID); OContextualRecordId res = new OContextualRecordId(rId); IndexReader indexReader = queryContext.getSearcher().getIndexReader(); try { for (String field : highlighted) { String text = doc.get(field); TokenStream tokenStream = TokenSources.getAnyTokenStream(indexReader, score.doc, field, doc, engine.indexAnalyzer()); TextFragment[] frag = highlighter.getBestTextFragments(tokenStream, text, true, maxNumFragments); queryContext.addHighlightFragment(field, frag); } engine.onRecordAddedToResultSet(queryContext, res, doc, score); return res; } catch (IOException | InvalidTokenOffsetsException e) { throw OException.wrapException(new OLuceneIndexException("error while highlighting"), e); } }
@Override public void onRecordAddedToResultSet(OLuceneQueryContext queryContext, OContextualRecordId recordId, Document doc, ScoreDoc score) { OSpatialQueryContext spatialContext = (OSpatialQueryContext) queryContext; if (spatialContext.spatialArgs != null) { Point docPoint = (Point) ctx.readShape(doc.get(strategy.getFieldName())); double docDistDEG = ctx.getDistCalc().distance(spatialContext.spatialArgs.getShape().getCenter(), docPoint); final double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM); recordId.setContext(new HashMap<String, Object>() { { put("distance", docDistInKM); } }); } }
if (!(id instanceof ORecord)) { record = getDatabase().load(id.getIdentity(), null, !isUseCache()); if (id instanceof OContextualRecordId && ((OContextualRecordId) id).getContext() != null) { Map<String, Object> ridContext = ((OContextualRecordId) id).getContext(); for (String key : ridContext.keySet()) { context.setVariable(key, ridContext.get(key));
@Override public void onRecordAddedToResultSet(QueryContext queryContext, OContextualRecordId recordId, Document doc, ScoreDoc score) { SpatialQueryContext spatialContext = (SpatialQueryContext) queryContext; if (spatialContext.spatialArgs != null) { Point docPoint = (Point) ctx.readShape(doc.get(strategy.getFieldName())); double docDistDEG = ctx.getDistCalc().distance(spatialContext.spatialArgs.getShape().getCenter(), docPoint); final double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM); recordId.setContext(new HashMap<String, Object>() { { put("distance", docDistInKM); } }); } }
@Override public void onRecordAddedToResultSet(OLuceneQueryContext queryContext, OContextualRecordId recordId, Document doc, ScoreDoc score) { OSpatialQueryContext spatialContext = (OSpatialQueryContext) queryContext; if (spatialContext.spatialArgs != null) { updateLastAccess(); openIfClosed(); Point docPoint = (Point) ctx.readShape(doc.get(strategy.getFieldName())); double docDistDEG = ctx.getDistCalc().distance(spatialContext.spatialArgs.getShape().getCenter(), docPoint); final double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM); recordId.setContext(new HashMap<String, Object>() { { put("distance", docDistInKM); } }); } }