public byte[] toData(int documentId) throws IOException { Document document = searcher.doc(documentId); return document.getBinaryValue(FieldNames.DATA); }
@Override public Map<Integer, Set<E>> getPatternsForAllTokens(String sentId) { try { TermQuery query = new TermQuery(new Term("sentid", sentId)); TopDocs tp = searcher.search(query,1); if (tp.totalHits > 0) { for (ScoreDoc s : tp.scoreDocs) { int docId = s.doc; Document d = searcher.doc(docId); byte[] st = d.getBinaryValue("patterns").bytes; ByteArrayInputStream baip = new ByteArrayInputStream(st); ObjectInputStream ois = new ObjectInputStream(baip); return (Map<Integer, Set<E>>) ois.readObject(); } } else throw new RuntimeException("Why no patterns for sentid " + sentId + ". Number of documents in index are " + size()); }catch(IOException e){ throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } return null; }
/** * Finds next element. * * @throws IgniteCheckedException If failed. */ @SuppressWarnings("unchecked") private void findNext() throws IgniteCheckedException { curr = null; while (idx < docs.length) { Document doc; try { doc = searcher.doc(docs[idx++].doc); } catch (IOException e) { throw new IgniteCheckedException(e); } ClassLoader ldr = null; if (ctx != null && ctx.deploy().enabled()) ldr = ctx.cache().internalCache(cacheName).context().deploy().globalLoader(); K k = unmarshall(doc.getBinaryValue(KEY_FIELD_NAME).bytes, ldr); if (filters != null && !filters.apply(k)) continue; V v = type.valueClass() == String.class ? (V)doc.get(VAL_STR_FIELD_NAME) : this.<V>unmarshall(doc.getBinaryValue(VAL_FIELD_NAME).bytes, ldr); assert v != null; curr = new IgniteBiTuple<>(k, v); break; } }
public ImageSearchHits search(Document doc, IndexReader reader) throws IOException { try { GlobalFeature queryFeature = feature.getClass().newInstance(); queryFeature.setByteArrayRepresentation(doc.getBinaryValue(featureFieldName).bytes, doc.getBinaryValue(featureFieldName).offset, doc.getBinaryValue(featureFieldName).length); return search(doc.getValues(hashesFieldName)[0].split(" "), queryFeature, reader); } catch (Exception e) { e.printStackTrace(); } return null; }
public ImageSearchHits search(Document doc, IndexReader reader) throws IOException { try { GlobalFeature queryFeature = feature.getClass().newInstance(); queryFeature.setByteArrayRepresentation(doc.getBinaryValue(featureFieldName).bytes, doc.getBinaryValue(featureFieldName).offset, doc.getBinaryValue(featureFieldName).length); return search(doc.getValues(hashesFieldName)[0].split(" "), queryFeature, reader); } catch (Exception e) { e.printStackTrace(); } return null; }
public ImageSearchHits search(Document doc, IndexReader reader) throws IOException { try { GlobalFeature queryFeature = feature.getClass().newInstance(); queryFeature.setByteArrayRepresentation(doc.getBinaryValue(featureFieldName).bytes, doc.getBinaryValue(featureFieldName).offset, doc.getBinaryValue(featureFieldName).length); return search(doc.getValues(hashesFieldName)[0].split(" "), queryFeature, reader); // return search(doc.getValues(hashesFieldName + "_q")[0].split(" "), queryFeature, reader); // just for debug if a query feature is stored in the index. } catch (Exception e) { e.printStackTrace(); } return null; }
public ImageSearchHits search(Document doc, IndexReader reader) throws IOException { try { GlobalFeature queryFeature = feature.getClass().newInstance(); queryFeature.setByteArrayRepresentation(doc.getBinaryValue(featureFieldName).bytes, doc.getBinaryValue(featureFieldName).offset, doc.getBinaryValue(featureFieldName).length); return search(doc.getValues(hashesFieldName)[0].split(" "), queryFeature, reader); // return search(doc.getValues(hashesFieldName + "_q")[0].split(" "), queryFeature, reader); // just for debug if a query feature is stored in the index. } catch (Exception e) { e.printStackTrace(); } return null; }
public ImageSearchHits search(Document doc, IndexReader reader) throws IOException { GlobalFeature queryFeature = null; try { queryFeature = feature.getClass().newInstance(); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); return null; } if (useDocValues) { docValues = MultiDocValues.getBinaryValues(reader, featureFieldName); // find the id of the document in the reader, then do search ... TODO: find another way instead of calling the searcher every time. TopDocs topDocs = searcher.search(new TermQuery(new Term(DocumentBuilder.FIELD_NAME_IDENTIFIER, doc.get(DocumentBuilder.FIELD_NAME_IDENTIFIER))), 1); if (topDocs.totalHits > 0) { int docID = topDocs.scoreDocs[0].doc; docValues.advanceExact(docID); queryFeature.setByteArrayRepresentation(docValues.binaryValue().bytes, docValues.binaryValue().offset, docValues.binaryValue().length); return search(MetricSpaces.generateBoostedQuery(queryFeature, numHashesUsedForQuery), queryFeature, searcher.getIndexReader()); } } else { queryFeature.setByteArrayRepresentation(doc.getBinaryValue(featureFieldName).bytes, doc.getBinaryValue(featureFieldName).offset, doc.getBinaryValue(featureFieldName).length); return search(MetricSpaces.generateBoostedQuery(queryFeature, numHashesUsedForQuery), queryFeature, reader); } return null; }
public ImageSearchHits search(Document doc, IndexReader reader) throws IOException { GlobalFeature queryFeature = null; try { queryFeature = feature.getClass().newInstance(); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); return null; } if (useDocValues) { docValues = MultiDocValues.getBinaryValues(reader, featureFieldName); // find the id of the document in the reader, then do search ... TODO: find another way instead of calling the searcher every time. TopDocs topDocs = searcher.search(new TermQuery(new Term(DocumentBuilder.FIELD_NAME_IDENTIFIER, doc.get(DocumentBuilder.FIELD_NAME_IDENTIFIER))), 1); if (topDocs.totalHits > 0) { int docID = topDocs.scoreDocs[0].doc; docValues.advanceExact(docID); queryFeature.setByteArrayRepresentation(docValues.binaryValue().bytes, docValues.binaryValue().offset, docValues.binaryValue().length); return search(MetricSpaces.generateBoostedQuery(queryFeature, numHashesUsedForQuery), queryFeature, searcher.getIndexReader()); } } else { queryFeature.setByteArrayRepresentation(doc.getBinaryValue(featureFieldName).bytes, doc.getBinaryValue(featureFieldName).offset, doc.getBinaryValue(featureFieldName).length); return search(MetricSpaces.generateBoostedQuery(queryFeature, numHashesUsedForQuery), queryFeature, reader); } return null; }
double tmpScore; for (int i = 0; i < docs.scoreDocs.length; i++) { feature.setByteArrayRepresentation(reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).bytes, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).offset, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).length); tmpScore = queryFeature.getDistance(feature); assert (tmpScore >= 0);
double tmpScore = 0d; for (int i = 0; i < docs.scoreDocs.length; i++) { feature.setByteArrayRepresentation(reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).bytes, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).offset, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).length); tmpScore = queryFeature.getDistance(feature); if (resultScoreDocs.size() < maximumHits) {
double tmpScore; for (int i = 0; i < docs.scoreDocs.length; i++) { feature.setByteArrayRepresentation(reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).bytes, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).offset, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).length); tmpScore = queryFeature.getDistance(feature); assert (tmpScore >= 0);
double tmpScore = 0d; for (int i = 0; i < docs.scoreDocs.length; i++) { feature.setByteArrayRepresentation(reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).bytes, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).offset, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).length); tmpScore = queryFeature.getDistance(feature); if (resultScoreDocs.size() < maximumHits) {
double tmpScore; for (int i = 0; i < docs.scoreDocs.length; i++) { feature.setByteArrayRepresentation(reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).bytes, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).offset, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).length); tmpScore = queryFeature.getDistance(feature); assert (tmpScore >= 0);
double tmpScore; for (int i = 0; i < docs.scoreDocs.length; i++) { feature.setByteArrayRepresentation(reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).bytes, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).offset, reader.document(docs.scoreDocs[i].doc).getBinaryValue(featureFieldName).length); tmpScore = queryFeature.getDistance(feature); assert (tmpScore >= 0);
public ImageSearchHits search(Document doc, IndexReader reader) throws IOException { try { LireFeature queryFeature = feature.getClass().newInstance(); queryFeature.setByteArrayRepresentation(doc.getBinaryValue(featureFieldName).bytes, doc.getBinaryValue(featureFieldName).offset, doc.getBinaryValue(featureFieldName).length); return search(doc.getValues(hashesFieldName)[0].split(" "), queryFeature, reader); } catch (Exception e) { e.printStackTrace(); } return null; }
public BytesRef getStoredValue(int docid) throws IOException { Document doc = in.document(docid); if (doc != null) { return doc.getBinaryValue(AbstractZoieIndexable.DOCUMENT_STORE_FIELD); } return null; }
private ServiceDocument getStateFromLuceneDocument(Document doc, String link) { BytesRef binaryStateField = doc.getBinaryValue(LUCENE_FIELD_NAME_BINARY_SERIALIZED_STATE); if (binaryStateField == null) { logWarning("State not found for %s", link); return null; } ServiceDocument state = (ServiceDocument) Utils.fromDocumentBytes( binaryStateField.bytes, binaryStateField.offset, binaryStateField.length); return state; }
/** * {@inheritDoc} */ @Override public Map<String, Object> get(String spaceId, String key) throws IOException { Document doc = doGet(spaceId, key); BytesRef data = doc != null ? doc.getBinaryValue(FIELD_DATA) : null; return data != null ? bytesToDocument(data.bytes) : null; }
@Override public byte[] getStoredValue(long uid) throws IOException { int docid = this.getDocIDMaper().getDocID(uid); if (docid<0) return null; if (docid>=0){ Document doc = document(docid); if (doc!=null){ return doc.getBinaryValue(AbstractZoieIndexable.DOCUMENT_STORE_FIELD); } } return null; }