List of usage examples for org.apache.lucene.index MultiDocValues getSortedSetValues
public static SortedSetDocValues getSortedSetValues(final IndexReader r, final String field) throws IOException
From source file:com.github.flaxsearch.util.ReaderManager.java
License:Apache License
default SortedSetDocValues getSortedSetDocValues(Integer segment, String field) throws IOException { if (segment == null) return MultiDocValues.getSortedSetValues(getIndexReader(), field); return getLeafReader(segment).getSortedSetDocValues(field); }
From source file:net.semanticmetadata.lire.solr.FastLireRequestHandler.java
License:Open Source License
/** * Handles the get parameters id, field and rows. * * @param req/*from w ww . j a va2 s.c o m*/ * @param rsp * @throws java.io.IOException * @throws InstantiationException * @throws IllegalAccessException */ private void handleIdSearch(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException, InstantiationException, IllegalAccessException { SolrIndexSearcher searcher = req.getSearcher(); try { TopDocs hits = searcher.search(new TermQuery(new Term("id", req.getParams().get("id"))), 1); String paramField = "cl_ha"; if (req.getParams().get("field") != null) paramField = req.getParams().get("field"); LireFeature queryFeature = (LireFeature) FeatureRegistry.getClassForHashField(paramField).newInstance(); rsp.add("QueryField", paramField); rsp.add("QueryFeature", queryFeature.getClass().getName()); numberOfQueryTerms = req.getParams().getDouble("accuracy", DEFAULT_NUMBER_OF_QUERY_TERMS); numberOfCandidateResults = req.getParams().getInt("candidates", DEFAULT_NUMBER_OF_CANDIDATES); if (hits.scoreDocs.length > 0) { // Using DocValues to get the actual data from the index. // BinaryDocValues binaryValues = MultiDocValues.getBinaryValues(searcher.getIndexReader(), FeatureRegistry.getFeatureFieldName(paramField)); // *** # // if (binaryValues == null) // System.err.println("Could not find the DocValues of the query document. Are they in the index?"); // BytesRef bytesRef = new BytesRef(); SortedSetDocValues sortedSetValues = MultiDocValues.getSortedSetValues(searcher.getIndexReader(), paramField); long valueCount = sortedSetValues.getValueCount(); List<Term> termFilter = Lists.newArrayList(); for (int i = 0; i < valueCount; i++) { BytesRef v = new BytesRef(); sortedSetValues.lookupOrd(i, v); termFilter.add(new Term(paramField, v)); } int[] hashes = null; int paramRows = defaultNumberOfResults; if (req.getParams().getInt("rows") != null) paramRows = req.getParams().getInt("rows"); /** // bytesRef = binaryValues.get(hits.scoreDocs[0].doc); binaryValues.get(hits.scoreDocs[0].doc,bytesRef); // Document d = searcher.getIndexReader().document(hits.scoreDocs[0].doc); // String histogramFieldName = paramField.replace("_ha", "_hi"); queryFeature.setByteArrayRepresentation(bytesRef.bytes, bytesRef.offset, bytesRef.length); int paramRows = defaultNumberOfResults; if (req.getParams().getInt("rows") != null) paramRows = req.getParams().getInt("rows"); // Re-generating the hashes to save sgenerateHashespace (instead of storing them in the index) int[] hashes = BitSampling.generateHashes(queryFeature.getDoubleHistogram()); List<Term> termFilter = createTermFilter(hashes, paramField); **/ doSearch(req, rsp, searcher, paramField, paramRows, termFilter, createQuery(hashes, paramField, numberOfQueryTerms), queryFeature); } else { rsp.add("Error", "Did not find an image with the given id " + req.getParams().get("id")); } } catch (Exception e) { rsp.add("Error", "There was an error with your search for the image with the id " + req.getParams().get("id") + ": " + e.getMessage()); } }
From source file:org.apache.solr.index.SlowCompositeReaderWrapper.java
License:Apache License
@Override public SortedSetDocValues getSortedSetDocValues(String field) throws IOException { ensureOpen();//from w ww.jav a 2 s . co m OrdinalMap map = null; synchronized (cachedOrdMaps) { map = cachedOrdMaps.get(field); if (map == null) { // uncached, or not a multi dv SortedSetDocValues dv = MultiDocValues.getSortedSetValues(in, field); if (dv instanceof MultiDocValues.MultiSortedSetDocValues) { map = ((MultiDocValues.MultiSortedSetDocValues) dv).mapping; if (map.owner == getCoreCacheKey() && merging == false) { cachedOrdMaps.put(field, map); } } return dv; } } assert map != null; int size = in.leaves().size(); final SortedSetDocValues[] values = new SortedSetDocValues[size]; final int[] starts = new int[size + 1]; long cost = 0; for (int i = 0; i < size; i++) { LeafReaderContext context = in.leaves().get(i); final LeafReader reader = context.reader(); final FieldInfo fieldInfo = reader.getFieldInfos().fieldInfo(field); if (fieldInfo != null && fieldInfo.getDocValuesType() != DocValuesType.SORTED_SET) { return null; } SortedSetDocValues v = reader.getSortedSetDocValues(field); if (v == null) { v = DocValues.emptySortedSet(); } values[i] = v; starts[i] = context.docBase; cost += v.cost(); } starts[size] = maxDoc(); return new MultiDocValues.MultiSortedSetDocValues(values, starts, map, cost); }
From source file:org.apache.tika.eval.tools.SlowCompositeReaderWrapper.java
License:Apache License
@Override public SortedSetDocValues getSortedSetDocValues(String field) throws IOException { ensureOpen();/*from www . jav a 2 s .c o m*/ OrdinalMap map = null; synchronized (cachedOrdMaps) { map = cachedOrdMaps.get(field); if (map == null) { // uncached, or not a multi dv SortedSetDocValues dv = MultiDocValues.getSortedSetValues(in, field); if (dv instanceof MultiDocValues.MultiSortedSetDocValues) { map = ((MultiDocValues.MultiSortedSetDocValues) dv).mapping; IndexReader.CacheHelper cacheHelper = getReaderCacheHelper(); if (cacheHelper != null && map.owner == cacheHelper.getKey()) { cachedOrdMaps.put(field, map); } } return dv; } } assert map != null; int size = in.leaves().size(); final SortedSetDocValues[] values = new SortedSetDocValues[size]; final int[] starts = new int[size + 1]; long cost = 0; for (int i = 0; i < size; i++) { LeafReaderContext context = in.leaves().get(i); final LeafReader reader = context.reader(); final FieldInfo fieldInfo = reader.getFieldInfos().fieldInfo(field); if (fieldInfo != null && fieldInfo.getDocValuesType() != DocValuesType.SORTED_SET) { return null; } SortedSetDocValues v = reader.getSortedSetDocValues(field); if (v == null) { v = DocValues.emptySortedSet(); } values[i] = v; starts[i] = context.docBase; cost += v.cost(); } starts[size] = maxDoc(); return new MultiDocValues.MultiSortedSetDocValues(values, starts, map, cost); }