use of org.apache.lucene.util.FixedBitSet in project SearchServices by Alfresco.
the class BitsFilter method or.
public void or(BitsFilter bitsFilter) {
List<FixedBitSet> andSets = bitsFilter.bitSets;
for (int i = 0; i < bitSets.size(); i++) {
FixedBitSet a = bitSets.get(i);
FixedBitSet b = andSets.get(i);
a.or(b);
}
}
use of org.apache.lucene.util.FixedBitSet in project SearchServices by Alfresco.
the class SolrDeniedScorer method createDenyScorer.
public static SolrDeniedScorer createDenyScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authority) throws IOException {
DocSet deniedDocs = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_DENIED_CACHE, authority);
if (deniedDocs == null) {
// Cache miss: query the index for ACL docs where the denial matches the authority.
DocSet aclDocs = searcher.getDocSet(new TermQuery(new Term(QueryConstants.FIELD_DENIED, authority)));
// Allocate a bitset to store the results.
deniedDocs = new BitDocSet(new FixedBitSet(searcher.maxDoc()));
// Translate from ACL docs to real docs
for (DocIterator it = aclDocs.iterator(); it.hasNext(); ) /**/
{
int docID = it.nextDoc();
// Obtain the ACL ID for this ACL doc.
long aclID = searcher.getSlowAtomicReader().getNumericDocValues(QueryConstants.FIELD_ACLID).get(docID);
SchemaField schemaField = searcher.getSchema().getField(QueryConstants.FIELD_ACLID);
Query query = schemaField.getType().getFieldQuery(null, schemaField, Long.toString(aclID));
// Find real docs that match the ACL ID
DocSet docsForAclId = searcher.getDocSet(query);
deniedDocs = deniedDocs.union(docsForAclId);
// Exclude the ACL docs from the results, we only want real docs that match.
// Probably not very efficient, what we really want is remove(docID)
deniedDocs = deniedDocs.andNot(aclDocs);
}
searcher.cacheInsert(CacheConstants.ALFRESCO_DENIED_CACHE, authority, deniedDocs);
}
return new SolrDeniedScorer(weight, deniedDocs, context, searcher);
}
use of org.apache.lucene.util.FixedBitSet in project SearchServices by Alfresco.
the class SolrReaderSetScorer method createReaderSetScorer.
public static SolrReaderSetScorer createReaderSetScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authorities, LeafReader reader) throws IOException {
DocSet readableDocSet = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_READER_CACHE, authorities);
if (readableDocSet == null) {
String[] auths = authorities.substring(1).split(authorities.substring(0, 1));
readableDocSet = new BitDocSet(new FixedBitSet(searcher.maxDoc()));
BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
for (String current : auths) {
bQuery.add(new TermQuery(new Term(QueryConstants.FIELD_READER, current)), Occur.SHOULD);
}
DocSet aclDocs = searcher.getDocSet(bQuery.build());
BooleanQuery.Builder aQuery = new BooleanQuery.Builder();
for (DocIterator it = aclDocs.iterator(); it.hasNext(); ) /**/
{
int docID = it.nextDoc();
// Obtain the ACL ID for this ACL doc.
long aclID = searcher.getSlowAtomicReader().getNumericDocValues(QueryConstants.FIELD_ACLID).get(docID);
SchemaField schemaField = searcher.getSchema().getField(QueryConstants.FIELD_ACLID);
Query query = schemaField.getType().getFieldQuery(null, schemaField, Long.toString(aclID));
aQuery.add(query, Occur.SHOULD);
if ((aQuery.build().clauses().size() > 999) || !it.hasNext()) {
DocSet docsForAclId = searcher.getDocSet(aQuery.build());
readableDocSet = readableDocSet.union(docsForAclId);
aQuery = new BooleanQuery.Builder();
}
}
// Exclude the ACL docs from the results, we only want real docs that match.
// Probably not very efficient, what we really want is remove(docID)
readableDocSet = readableDocSet.andNot(aclDocs);
searcher.cacheInsert(CacheConstants.ALFRESCO_READER_CACHE, authorities, readableDocSet);
}
// plus check of course, for presence in cache at start of method.
return new SolrReaderSetScorer(weight, readableDocSet, context, searcher);
}
use of org.apache.lucene.util.FixedBitSet in project SearchServices by Alfresco.
the class SolrDenySetScorer2 method createDenySetScorer.
public static SolrDenySetScorer2 createDenySetScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authorities, LeafReader reader) throws IOException {
DocSet deniedDocSet = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_DENIED_CACHE, authorities);
if (deniedDocSet == null) {
String[] auths = authorities.substring(1).split(authorities.substring(0, 1));
deniedDocSet = new BitDocSet(new FixedBitSet(searcher.maxDoc()));
BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
for (String current : auths) {
bQuery.add(new TermQuery(new Term(QueryConstants.FIELD_DENIED, current)), Occur.SHOULD);
}
WrappedQuery wrapped = new WrappedQuery(bQuery.build());
wrapped.setCache(false);
DocSet aclDocs = searcher.getDocSet(wrapped);
HashSet<Long> aclsFound = new HashSet<Long>(aclDocs.size());
NumericDocValues aclDocValues = searcher.getSlowAtomicReader().getNumericDocValues(QueryConstants.FIELD_ACLID);
for (DocIterator it = aclDocs.iterator(); it.hasNext(); ) /**/
{
int docID = it.nextDoc();
// Obtain the ACL ID for this ACL doc.
long aclID = aclDocValues.get(docID);
aclsFound.add(getLong(aclID));
}
if (aclsFound.size() > 0) {
for (LeafReaderContext readerContext : searcher.getSlowAtomicReader().leaves()) {
int maxDoc = readerContext.reader().maxDoc();
NumericDocValues fieldValues = DocValuesCache.getNumericDocValues(QueryConstants.FIELD_ACLID, readerContext.reader());
if (fieldValues != null) {
for (int i = 0; i < maxDoc; i++) {
long aclID = fieldValues.get(i);
Long key = getLong(aclID);
if (aclsFound.contains(key)) {
deniedDocSet.add(readerContext.docBase + i);
}
}
}
}
}
// Exclude the ACL docs from the results, we only want real docs that match.
// Probably not very efficient, what we really want is remove(docID)
deniedDocSet = deniedDocSet.andNot(aclDocs);
searcher.cacheInsert(CacheConstants.ALFRESCO_DENIED_CACHE, authorities, deniedDocSet);
}
// plus check of course, for presence in cache at start of method.
return new SolrDenySetScorer2(weight, deniedDocSet, context, searcher);
}
use of org.apache.lucene.util.FixedBitSet in project SearchServices by Alfresco.
the class SolrOwnerScorer method createOwnerScorer.
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);
}
Aggregations