use of org.apache.solr.search.DocSet in project SearchServices by Alfresco.
the class SolrDenySetScorer method createDenySetScorer.
public static SolrDenySetScorer 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);
}
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());
deniedDocSet = deniedDocSet.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)
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 SolrDenySetScorer(weight, deniedDocSet, context, searcher);
}
use of org.apache.solr.search.DocSet in project SearchServices by Alfresco.
the class SolrOwnerSetScorer method createOwnerSetScorer.
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);
}
Aggregations