List of usage examples for org.apache.solr.search BitDocSet getBits
@Override
public FixedBitSet getBits()
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;/*from ww w . j av a 2 s . co 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 ww . j a v a2 s . c o m DocIterator it = docSet.iterator(); if (it.hasNext()) { index = it.nextDoc(); } } result = (-1 != index) && skippingDocs.exists(index); } return result; }
From source file:org.alfresco.solr.LegacySolrInformationServer.java
License:Open Source License
private void deleteByQuery(SolrIndexSearcher solrIndexSearcher, Query query) throws IOException { HashSet<String> idsToDelete = new HashSet<String>(); DocSet docSet = solrIndexSearcher.getDocSet(query); if (docSet instanceof BitDocSet) { BitDocSet source = (BitDocSet) docSet; OpenBitSet openBitSet = source.getBits(); int current = -1; while ((current = openBitSet.nextSetBit(current + 1)) != -1) { Document doc = solrIndexSearcher.doc(current, Collections.singleton(QueryConstants.FIELD_ID)); Fieldable fieldable = doc.getFieldable(QueryConstants.FIELD_ID); if (fieldable != null) { idsToDelete.add(fieldable.stringValue()); }/*from ww w . ja v a2 s . c o m*/ } } else { for (DocIterator it = docSet.iterator(); it.hasNext(); /* */) { Document doc = solrIndexSearcher.doc(it.nextDoc(), Collections.singleton(QueryConstants.FIELD_ID)); Fieldable fieldable = doc.getFieldable(QueryConstants.FIELD_ID); if (fieldable != null) { idsToDelete.add(fieldable.stringValue()); } } } for (String idToDelete : idsToDelete) { DeleteUpdateCommand docCmd = new DeleteUpdateCommand(); docCmd.id = idToDelete; docCmd.fromPending = true; docCmd.fromCommitted = true; core.getUpdateHandler().delete(docCmd); } }
From source file:org.alfresco.solr.query.SolrCachingAuxDocScorer.java
License:Open Source License
public static SolrCachingAuxDocScorer createAuxDocScorer(SolrIndexSearcher searcher, Similarity similarity, Query query, SolrIndexReader reader) throws IOException { // Get hold of solr top level searcher // Execute query with caching // translate reults to leaf docs // build ordered doc list DocSet auxDocSet = searcher.getDocSet(new ContextAwareQuery(query, null)); ResizeableArrayList<CacheEntry> indexedByDocId = (ResizeableArrayList<CacheEntry>) searcher.cacheLookup( AlfrescoSolrEventListener.ALFRESCO_ARRAYLIST_CACHE, AlfrescoSolrEventListener.KEY_DBID_LEAF_PATH_BY_DOC_ID); // List<ScoreDoc> auxDocs = pathCollector.getDocs(); OpenBitSet translated = new OpenBitSet(searcher.getReader().maxDoc()); if (auxDocSet instanceof BitDocSet) { BitDocSet source = (BitDocSet) auxDocSet; OpenBitSet openBitSet = source.getBits(); int current = -1; while ((current = openBitSet.nextSetBit(current + 1)) != -1) { CacheEntry entry = indexedByDocId.get(current); translated.set(entry.getLeaf()); }/* w w w . j ava 2 s . c o m*/ } else { for (DocIterator it = auxDocSet.iterator(); it.hasNext(); /* */) { CacheEntry entry = indexedByDocId.get(it.nextDoc()); translated.set(entry.getLeaf()); } } return new SolrCachingAuxDocScorer(similarity, new BitDocSet(translated), reader); }
From source file:org.alfresco.solr.query.SolrCachingReaderScorer.java
License:Open Source License
public static SolrCachingReaderScorer createReaderScorer(SolrIndexSearcher searcher, Similarity similarity, String authority, SolrIndexReader reader) throws IOException { // Get hold of solr top level searcher // Execute query with caching // translate reults to leaf docs // build ordered doc list long[] aclByDocId = (long[]) searcher.cacheLookup(AlfrescoSolrEventListener.ALFRESCO_CACHE, AlfrescoSolrEventListener.KEY_ACL_ID_BY_DOC_ID); HashMap<AlfrescoSolrEventListener.AclLookUp, AlfrescoSolrEventListener.AclLookUp> lookups = (HashMap<AlfrescoSolrEventListener.AclLookUp, AlfrescoSolrEventListener.AclLookUp>) searcher .cacheLookup(AlfrescoSolrEventListener.ALFRESCO_CACHE, AlfrescoSolrEventListener.KEY_ACL_LOOKUP); ResizeableArrayList<AlfrescoSolrEventListener.CacheEntry> aclThenLeafOrderedEntries = (ResizeableArrayList<AlfrescoSolrEventListener.CacheEntry>) searcher .cacheLookup(AlfrescoSolrEventListener.ALFRESCO_ARRAYLIST_CACHE, AlfrescoSolrEventListener.KEY_DBID_LEAF_PATH_BY_ACL_ID_THEN_LEAF); DocSet aclDocSet;/* w w w . j av a 2 s . com*/ if (authority.contains("|")) { BooleanQuery bQuery = new BooleanQuery(); for (String current : authority.split("\\|")) { bQuery.add(new TermQuery(new Term("READER", current)), Occur.SHOULD); } aclDocSet = searcher.getDocSet(bQuery); } else { aclDocSet = searcher.getDocSet(new TermQuery(new Term("READER", authority))); } BitDocSet readableDocSet = new BitDocSet(new OpenBitSet(searcher.getReader().maxDoc())); AlfrescoSolrEventListener.AclLookUp key = new AlfrescoSolrEventListener.AclLookUp(0); if (aclDocSet instanceof BitDocSet) { BitDocSet source = (BitDocSet) aclDocSet; OpenBitSet openBitSet = source.getBits(); int current = -1; while ((current = openBitSet.nextSetBit(current + 1)) != -1) { long acl = aclByDocId[current]; key.setAclid(acl); AlfrescoSolrEventListener.AclLookUp value = lookups.get(key); if (value != null) { for (int i = value.getStart(); i < value.getEnd(); i++) { readableDocSet.add(aclThenLeafOrderedEntries.get(i).getLeaf()); } } } } else { for (DocIterator it = aclDocSet.iterator(); it.hasNext(); /* */) { int doc = it.nextDoc(); long acl = aclByDocId[doc]; key.setAclid(acl); AlfrescoSolrEventListener.AclLookUp value = lookups.get(key); if (value != null) { for (int i = value.getStart(); i < value.getEnd(); i++) { readableDocSet.add(aclThenLeafOrderedEntries.get(i).getLeaf()); } } } } return new SolrCachingReaderScorer(similarity, readableDocSet, reader); }