Java Code Examples for org.apache.solr.search.SolrIndexSearcher#getDocSet()
The following examples show how to use
org.apache.solr.search.SolrIndexSearcher#getDocSet() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrCachingPathScorer.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
/** * Factory method used to create {@link SolrCachingPathScorer} instances. * @param acceptDocs */ public static SolrCachingPathScorer create(SolrCachingPathWeight weight, LeafReaderContext context, SolrIndexSearcher searcher, SolrPathQuery wrappedPathQuery) throws IOException { DocSet results = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_PATH_CACHE, wrappedPathQuery); if (results == null) { // Cache miss: get path query results and cache them WrappedQuery wrapped = new WrappedQuery(wrappedPathQuery); wrapped.setCache(false); results = searcher.getDocSet(wrapped); searcher.cacheInsert(CacheConstants.ALFRESCO_PATH_CACHE, wrappedPathQuery, results); } return new SolrCachingPathScorer(weight, results, context, searcher); }
Example 2
Source File: SolrOwnerScorer.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
public static SolrOwnerScorer createOwnerScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authority) throws IOException { if (AuthorityType.getAuthorityType(authority) == AuthorityType.USER) { DocSet ownedDocs = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_OWNERLOOKUP_CACHE, authority); if (ownedDocs == null) { // Cache miss: query the index for docs where the owner matches the authority. ownedDocs = searcher.getDocSet(new TermQuery(new Term(QueryConstants.FIELD_OWNER, authority))); searcher.cacheInsert(CacheConstants.ALFRESCO_OWNERLOOKUP_CACHE, authority, ownedDocs); } return new SolrOwnerScorer(weight, ownedDocs, context, searcher); } // Return an empty doc set, as the authority isn't a user. return new SolrOwnerScorer(weight, new BitDocSet(new FixedBitSet(0)), context, searcher); }
Example 3
Source File: TaggerRequestHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * The set of documents matching the provided 'fq' (filter query). Don't include deleted docs * either. If null is returned, then all docs are available. */ private Bits computeDocCorpus(SolrQueryRequest req) throws SyntaxError, IOException { final String[] corpusFilterQueries = req.getParams().getParams("fq"); final SolrIndexSearcher searcher = req.getSearcher(); final Bits docBits; if (corpusFilterQueries != null && corpusFilterQueries.length > 0) { List<Query> filterQueries = new ArrayList<Query>(corpusFilterQueries.length); for (String corpusFilterQuery : corpusFilterQueries) { QParser qParser = QParser.getParser(corpusFilterQuery, null, req); try { filterQueries.add(qParser.parse()); } catch (SyntaxError e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); } } final DocSet docSet = searcher.getDocSet(filterQueries);//hopefully in the cache docBits = docSet.getBits(); } else { docBits = searcher.getSlowAtomicReader().getLiveDocs(); } return docBits; }
Example 4
Source File: ParentNodeFacetTreeBuilder.java From BioSolr with Apache License 2.0 | 6 votes |
private Map<String, Set<String>> findParentIdsForNodes(SolrIndexSearcher searcher, Collection<String> nodeIds) throws IOException { Map<String, Set<String>> parentIds = new HashMap<>(); LOGGER.debug("Looking up parents for {} nodes", nodeIds.size()); Query filter = buildFilterQuery(getNodeField(), nodeIds); LOGGER.trace("Filter query: {}", filter); DocSet docs = searcher.getDocSet(filter); for (DocIterator it = docs.iterator(); it.hasNext(); ) { Document doc = searcher.doc(it.nextDoc(), docFields); String nodeId = doc.get(getNodeField()); Set<String> parentIdValues = new HashSet<>(Arrays.asList(doc.getValues(parentField))); parentIds.put(nodeId, parentIdValues); // Record the label, if required if (isLabelRequired(nodeId)) { recordLabel(nodeId, doc.getValues(getLabelField())); } } return parentIds; }
Example 5
Source File: SolrOwnerSetScorer.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
public static SolrOwnerSetScorer createOwnerSetScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authorities) throws IOException { DocSet authorityOwnedDocs = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_OWNERLOOKUP_CACHE, authorities); if(authorityOwnedDocs == null) { // Split the authorities. The first character in the authorities String // specifies the separator, e.g. ",jbloggs,abeecher" String[] auths = authorities.substring(1).split(authorities.substring(0, 1)); BooleanQuery.Builder bQuery = new BooleanQuery.Builder(); for(String current : auths) { if (AuthorityType.getAuthorityType(current) == AuthorityType.USER) { bQuery.add(new TermQuery(new Term(QueryConstants.FIELD_OWNER, current)), Occur.SHOULD); } } WrappedQuery wrapped = new WrappedQuery(bQuery.build()); wrapped.setCache(false); authorityOwnedDocs = searcher.getDocSet(wrapped); searcher.cacheInsert(CacheConstants.ALFRESCO_OWNERLOOKUP_CACHE, authorities, authorityOwnedDocs); } // TODO: Cache the final set? e.g. searcher.cacheInsert(authorities, authorityOwnedDocs) return new SolrOwnerSetScorer(weight, authorityOwnedDocs, context, searcher); }
Example 6
Source File: AuthorityCacheRegenerator.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings({ "rawtypes" }) @Override public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, Object oldKey, Object oldVal) throws IOException { if (oldKey instanceof Query) { // The authority cache contains results keyed by SolrAuthorityQuery // and SolrAuthoritySetQuery. Query authQuery = (Query) oldKey; // Execute the query on the new searcher - resulting in cache population as a side-effect. newSearcher.getDocSet(authQuery); } return true; }
Example 7
Source File: PathCacheRegenerator.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings({ "rawtypes" }) @Override public boolean regenerateItem(SolrIndexSearcher newSearcher, SolrCache newCache, SolrCache oldCache, Object oldKey, Object oldVal) throws IOException { if (oldKey instanceof SolrPathQuery) { SolrPathQuery pathQuery = (SolrPathQuery) oldKey; // Re-execute the path query in a cache-aware context - causing new results to be cached. SolrCachingPathQuery cachingPathQuery = new SolrCachingPathQuery(pathQuery); newSearcher.getDocSet(cachingPathQuery); } return true; }
Example 8
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Returns a count of the documents in the set which do not have any * terms for for the specified field. * * @see FacetParams#FACET_MISSING */ public static int getFieldMissingCount(SolrIndexSearcher searcher, DocSet docs, String fieldName) throws IOException { SchemaField sf = searcher.getSchema().getField(fieldName); DocSet hasVal = searcher.getDocSet (sf.getType().getRangeQuery(null, sf, null, null, false, false)); return docs.andNotSize(hasVal); }
Example 9
Source File: FilterQuery.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { // SolrRequestInfo reqInfo = SolrRequestInfo.getRequestInfo(); if (!(searcher instanceof SolrIndexSearcher)) { // delete-by-query won't have SolrIndexSearcher return new BoostQuery(new ConstantScoreQuery(q), 0).createWeight(searcher, scoreMode, 1f); } SolrIndexSearcher solrSearcher = (SolrIndexSearcher)searcher; DocSet docs = solrSearcher.getDocSet(q); // reqInfo.addCloseHook(docs); // needed for off-heap refcounting return new BoostQuery(new SolrConstantScoreQuery(docs.getTopFilter()), 0).createWeight(searcher, scoreMode, 1f); }
Example 10
Source File: FacetProcessor.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") static DocSet getFieldMissing(SolrIndexSearcher searcher, DocSet docs, String fieldName) throws IOException { SchemaField sf = searcher.getSchema().getField(fieldName); DocSet hasVal = searcher.getDocSet(sf.getType().getRangeQuery(null, sf, null, null, false, false)); DocSet answer = docs.andNot(hasVal); // hasVal.decref(); // OFF-HEAP return answer; }
Example 11
Source File: ChildNodeFacetTreeBuilder.java From BioSolr with Apache License 2.0 | 5 votes |
/** * Fetch facets for items containing a specific set of values. * @param searcher the searcher for the collection being used. * @param facetValues the incoming values to use as filters. * @param filterField the item field containing the child values, which will be used * to filter against. * @return a map of node value to child values for the items. * @throws IOException */ private Map<String, Set<String>> filterEntriesByField(SolrIndexSearcher searcher, Collection<String> facetValues, String filterField) throws IOException { Map<String, Set<String>> filteredEntries = new HashMap<>(); LOGGER.debug("Looking up {} entries in field {}", facetValues.size(), filterField); Query filter = buildFilterQuery(filterField, facetValues); LOGGER.trace("Filter query: {}", filter); DocSet docs = searcher.getDocSet(filter); for (DocIterator it = docs.iterator(); it.hasNext(); ) { Document doc = searcher.doc(it.nextDoc(), docFields); String nodeId = doc.get(getNodeField()); // Get the children for the node, if necessary Set<String> childIds; if (filterField.equals(getNodeField())) { // Filtering on the node field - child IDs are redundant childIds = Collections.emptySet(); } else { childIds = new HashSet<>(Arrays.asList(doc.getValues(filterField))); LOGGER.trace("Got {} children for node {}", childIds.size(), nodeId); } filteredEntries.put(nodeId, childIds); // Record the label, if required if (isLabelRequired(nodeId)) { recordLabel(nodeId, doc.getValues(getLabelField())); } } return filteredEntries; }