List of usage examples for org.apache.solr.search DocSet exists
public boolean exists(int docid);
From source file:org.alfresco.solr.LegacySolrInformationServer.java
License:Open Source License
private void doUpdateDescendantAuxDocs(NodeMetaData parentNodeMetaData, boolean overwrite, SolrIndexSearcher solrIndexSearcher, LinkedHashSet<Long> stack, DocSet skippingDocs) throws AuthenticationException, IOException, JSONException { if ((skipDescendantAuxDocsForSpecificTypes && typesForSkippingDescendantAuxDocs.contains(parentNodeMetaData.getType())) || (skipDescendantAuxDocsForSpecificAspects && shouldBeIgnoredByAnyAspect(parentNodeMetaData.getAspects()))) { return;//w w w . j a v a 2 s.c o m } HashSet<Long> childIds = new HashSet<Long>(); if (parentNodeMetaData.getChildIds() != null) { childIds.addAll(parentNodeMetaData.getChildIds()); } BooleanQuery bQuery = new BooleanQuery(); bQuery.add(new TermQuery(new Term(QueryConstants.FIELD_PARENT, parentNodeMetaData.getNodeRef().toString())), Occur.MUST); DocSet docSet = solrIndexSearcher.getDocSet(bQuery); ResizeableArrayList<CacheEntry> indexedByDocId = (ResizeableArrayList<CacheEntry>) solrIndexSearcher .cacheLookup(AlfrescoSolrEventListener.ALFRESCO_ARRAYLIST_CACHE, AlfrescoSolrEventListener.KEY_DBID_LEAF_PATH_BY_DOC_ID); if (docSet instanceof BitDocSet) { BitDocSet source = (BitDocSet) docSet; OpenBitSet openBitSet = source.getBits(); int current = -1; while ((current = openBitSet.nextSetBit(current + 1)) != -1) { if (!skippingDocs.exists(current)) { CacheEntry entry = indexedByDocId.get(current); childIds.add(entry.getDbid()); } } } else { for (DocIterator it = docSet.iterator(); it.hasNext(); /* */) { int current = it.nextDoc(); if (!skippingDocs.exists(current)) { CacheEntry entry = indexedByDocId.get(current); childIds.add(entry.getDbid()); } } } for (Long childId : childIds) { if (!shouldElementBeIgnored(childId, solrIndexSearcher, skippingDocs)) { NodeMetaDataParameters nmdp = new NodeMetaDataParameters(); nmdp.setFromNodeId(childId); nmdp.setToNodeId(childId); nmdp.setIncludeAclId(true); nmdp.setIncludeAspects(true); nmdp.setIncludeChildAssociations(false); nmdp.setIncludeChildIds(true); nmdp.setIncludeNodeRef(true); nmdp.setIncludeOwner(true); nmdp.setIncludeParentAssociations(true); nmdp.setIncludePaths(true); nmdp.setIncludeProperties(false); nmdp.setIncludeType(true); nmdp.setIncludeTxnId(true); // call back to core tracker to talk to client List<NodeMetaData> nodeMetaDatas = coreTracker.getNodesMetaData(nmdp, MAX_RESULTS_NODES_META_DATA); for (NodeMetaData nodeMetaData : nodeMetaDatas) { if (mayHaveChildren(nodeMetaData)) { updateDescendantAuxDocs(nodeMetaData, overwrite, solrIndexSearcher, stack, skippingDocs); } // Avoid adding aux docs for stuff yet to be indexed or unindexed (via the index control aspect) log.info(".. checking aux doc exists in index before we update it"); Query query = new TermQuery(new Term(QueryConstants.FIELD_ID, "AUX-" + childId)); DocSet auxSet = solrIndexSearcher.getDocSet(query); if (auxSet.size() > 0) { log.debug("... cascade update aux doc " + childId); SolrInputDocument aux = createAuxDoc(nodeMetaData); AddUpdateCommand auxDocCmd = new AddUpdateCommand(); auxDocCmd.overwriteCommitted = overwrite; auxDocCmd.overwritePending = overwrite; auxDocCmd.solrDoc = aux; auxDocCmd.doc = toDocument(auxDocCmd.getSolrInputDocument(), core.getSchema(), dataModel); core.getUpdateHandler().addDoc(auxDocCmd); } else { log.debug("... no aux doc found to update " + childId); } } } } }
From source file:org.alfresco.solr.LegacySolrInformationServer.java
License:Open Source License
private boolean shouldElementBeIgnored(long dbId, SolrIndexSearcher solrIndexSearcher, DocSet skippingDocs) throws IOException { boolean result = false; if ((skipDescendantAuxDocsForSpecificTypes && !typesForSkippingDescendantAuxDocs.isEmpty()) || (skipDescendantAuxDocsForSpecificAspects && !aspectsForSkippingDescendantAuxDocs.isEmpty())) { BooleanQuery query = new BooleanQuery(); query.add(new TermQuery(new Term(QueryConstants.FIELD_DBID, NumericEncoder.encode(dbId))), Occur.MUST); DocSet docSet = solrIndexSearcher.getDocSet(query); int index = -1; if (docSet instanceof BitDocSet) { BitDocSet source = (BitDocSet) docSet; OpenBitSet openBitSet = source.getBits(); index = openBitSet.nextSetBit(index + 1); } else {// w w w .j a v a 2 s . com DocIterator it = docSet.iterator(); if (it.hasNext()) { index = it.nextDoc(); } } result = (-1 != index) && skippingDocs.exists(index); } return result; }
From source file:org.opensextant.solrtexttagger.TaggerRequestHandler.java
License:Open Source License
/** * 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. *//*from w ww .jav a2 s.c o m*/ 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 //note: before Solr 4.7 we could call docSet.getBits() but no longer. if (docSet instanceof BitDocSet) { docBits = ((BitDocSet) docSet).getBits(); } else { docBits = new Bits() { @Override public boolean get(int index) { return docSet.exists(index); } @Override public int length() { return searcher.maxDoc(); } }; } } else { docBits = searcher.getSlowAtomicReader().getLiveDocs(); } return docBits; }