Java Code Examples for org.alfresco.repo.search.adaptor.lucene.QueryConstants

The following examples show how to use org.alfresco.repo.search.adaptor.lucene.QueryConstants. These examples are extracted from open source projects. 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
protected BitsFilter getACLFilter(String[] auths, String field, SolrIndexSearcher searcher) throws IOException
{
    HybridBitSet aclBits = getACLSet(auths, field, searcher);
    List<LeafReaderContext> leaves = searcher.getTopReaderContext().leaves();
    List<FixedBitSet> bitSets = new ArrayList<FixedBitSet>(leaves.size());

    for(LeafReaderContext readerContext :  leaves)
    {
    	LeafReader reader = readerContext.reader();
        int maxDoc = reader.maxDoc();
        FixedBitSet bits = new FixedBitSet(maxDoc);
        bitSets.add(bits);

        NumericDocValues fieldValues = DocValuesCache.getNumericDocValues(QueryConstants.FIELD_ACLID, reader);
        if (fieldValues != null) {
            for (int i = 0; i < maxDoc; i++) {
                long aclID = fieldValues.get(i);
                if (aclBits.get(aclID)) {
                    bits.set(i);
                }
            }
        }
    }

    return new BitsFilter(bitSets);
}
 
Example 2
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
public DelegatingCollector getFilterCollector(IndexSearcher searcher)
{
    String[] auths = authorities.substring(1).split(authorities.substring(0, 1));
    try
    {
        HybridBitSet denySet = getACLSet(auths, QueryConstants.FIELD_DENIED, (SolrIndexSearcher) searcher);
        if(denySet instanceof EmptyHybridBitSet)
        {
            return new AllAccessCollector();
        }
        else
        {
            return new AccessControlCollector(denySet);
        }
    }
    catch(Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
Example 4
@Before
public void prepare() throws Exception
{
    AclChangeSet aclChangeSet = getAclChangeSet(1);
    acl = getAcl(aclChangeSet);
    Acl acl2 = getAcl(aclChangeSet);

    AclReaders aclReaders = getAclReaders(aclChangeSet, acl, singletonList("joel"), singletonList("phil"), null);
    AclReaders aclReaders2 = getAclReaders(aclChangeSet, acl2, singletonList("jim"), singletonList("phil"), null);

    indexAclChangeSet(aclChangeSet,
            asList(acl, acl2),
            asList(aclReaders, aclReaders2));

    // Check for the ACL state stamp.
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term(QueryConstants.FIELD_SOLR4_ID, "TRACKER!STATE!ACLTX")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(LegacyNumericRangeQuery.newLongRange(QueryConstants.FIELD_S_ACLTXID, aclChangeSet.getId(), aclChangeSet.getId() + 1, true, false), BooleanClause.Occur.MUST));
    BooleanQuery waitForQuery = builder.build();
    waitForDocCount(waitForQuery, 1, MAX_WAIT_TIME);
}
 
Example 5
/**
 * Creates and indexes a transaction with a certain number of nodes.
 *
 * @param howManyTestNodes how many nodes we want to index.
 * @param acl the related ACL.
 * @param sampleTextContent a sample text content that will be used to assert nodes have been actually indexed.
 */
private static void createAndIndexTransactionWithSomeNodes(int howManyTestNodes, Acl acl, String sampleTextContent)
{
    try
    {
        Transaction txn = getTransaction(0, howManyTestNodes);
        Map.Entry<List<Node>, List<NodeMetaData>> data = TestDataProvider.nSampleNodesWithSampleContent(acl, txn, howManyTestNodes);

        indexTransaction(txn, data.getKey(), data.getValue(), range(0, howManyTestNodes).mapToObj(index -> sampleTextContent).collect(Collectors.toList()));

        BooleanQuery.Builder builder = new BooleanQuery.Builder();
        builder.add(new BooleanClause(new TermQuery(new Term(QueryConstants.FIELD_SOLR4_ID, "TRACKER!STATE!TX")), BooleanClause.Occur.MUST));
        builder.add(new BooleanClause(LongPoint.newExactQuery(QueryConstants.FIELD_S_TXID, txn.getId()), BooleanClause.Occur.MUST));
        BooleanQuery waitForQuery = builder.build();

        waitForDocCountAllCores(waitForQuery, 1, MAX_WAIT_TIME);
    }
    catch (Exception exception)
    {
        throw new RuntimeException(exception);
    }
}
 
Example 6
private Acl createAndIndexSomeAclData() throws Exception
{
    AclChangeSet aclChangeSet = getAclChangeSet(1);

    Acl acl = getAcl(aclChangeSet);
    Acl acl2 = getAcl(aclChangeSet);

    AclReaders aclReaders = getAclReaders(aclChangeSet, acl, singletonList("joel"), singletonList("phil"), null);
    AclReaders aclReaders2 = getAclReaders(aclChangeSet, acl2, singletonList("jim"), singletonList("phil"), null);

    indexAclChangeSet(aclChangeSet, asList(acl, acl2), asList(aclReaders, aclReaders2));

    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term(QueryConstants.FIELD_SOLR4_ID, "TRACKER!STATE!ACLTX")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(LegacyNumericRangeQuery.newLongRange(QueryConstants.FIELD_S_ACLTXID, aclChangeSet.getId(), aclChangeSet.getId() + 1, true, false), BooleanClause.Occur.MUST));
    BooleanQuery waitForQuery = builder.build();
    waitForDocCount(waitForQuery, 1, MAX_WAIT_TIME);

    return acl;
}
 
Example 7
/**
 * Setup, indexes and returns the ACL used within the tests.
 *
 * @return the ACL used within the test.
 */
private Acl getTestAcl() throws Exception
{
    AclChangeSet aclChangeSet = getAclChangeSet(1);
    Acl acl = getAcl(aclChangeSet);
    AclReaders aclReaders = getAclReaders(aclChangeSet, acl, singletonList("joel"), singletonList("phil"), null);

    indexAclChangeSet(aclChangeSet, singletonList(acl), singletonList(aclReaders));

    //Check for the ACL state stamp.
    BooleanQuery.Builder builder =
            new BooleanQuery.Builder()
                    .add(new BooleanClause(new TermQuery(new Term(QueryConstants.FIELD_SOLR4_ID, "TRACKER!STATE!ACLTX")), BooleanClause.Occur.MUST))
                    .add(new BooleanClause(LegacyNumericRangeQuery.newLongRange(
                            QueryConstants.FIELD_S_ACLTXID, aclChangeSet.getId(), aclChangeSet.getId() + 1, true, false), BooleanClause.Occur.MUST));

    Query waitForQuery = builder.build();
    waitForDocCount(waitForQuery, 1, MAX_WAIT_TIME);
    return acl;
}
 
Example 8
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_AUTHORITYSET).append(':');
    stringBuilder.append(authorities);
    return stringBuilder.toString();
}
 
Example 9
private BitsFilter getOwnerFilter(String[] auths, SolrIndexSearcher searcher) throws IOException
{
    Builder builder = new BooleanQuery.Builder();
    for(String current : auths)
    {
        if (AuthorityType.getAuthorityType(current) == AuthorityType.USER)
        {
        	builder.add(new TermQuery(new Term(QueryConstants.FIELD_OWNER, current)), BooleanClause.Occur.SHOULD);
        }
    }

    BitsFilterCollector collector = new BitsFilterCollector(searcher.getTopReaderContext().leaves().size());
    searcher.search(builder.build(), collector);
    return collector.getBitsFilter();
}
 
Example 10
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 11
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_READERSET).append(':');
    stringBuilder.append(authorities);
    return stringBuilder.toString();
}
 
Example 12
@Override
public Query getIdentifierQuery(String field, String stringValue, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException
{
    String[] split = stringValue.split(";");
    if(split.length == 1)
    {
        return lqp.getFieldQuery(field, stringValue, AnalysisMode.IDENTIFIER, luceneFunction);
    }
    else
    {
        if(split[1].equalsIgnoreCase("PWC"))
        {
            return getMatchNoneQuery();
        }
        
        BooleanQuery.Builder query = new BooleanQuery.Builder();
        BooleanQuery.Builder part1 = new BooleanQuery.Builder();
        part1.add(lqp.getFieldQuery(field, split[0], AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST);
        part1.add(lqp.getFieldQuery("@"+ContentModel.PROP_VERSION_LABEL.toString(), split[1], AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST);
        query.add(part1.build(), Occur.SHOULD);
        
        if(split[1].equals("1.0"))
        {
            BooleanQuery.Builder part2 = new BooleanQuery.Builder();
            part2.add(lqp.getFieldQuery(field, split[0], AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST);
            part2.add(lqp.getFieldQuery(QueryConstants.FIELD_ASPECT, ContentModel.ASPECT_VERSIONABLE.toString(), AnalysisMode.IDENTIFIER, luceneFunction), Occur.MUST_NOT);
            query.add(part2.build(), Occur.SHOULD);
        }
        return query.build();
    }
}
 
Example 13
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_AUTHORITY).append(':');
    stringBuilder.append(authority);
    return stringBuilder.toString();
}
 
Example 14
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_READER).append(':');
    stringBuilder.append(authority);
    return stringBuilder.toString();
}
 
Example 15
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_OWNERSET).append(':');
    stringBuilder.append(authorities);
    return stringBuilder.toString();
}
 
Example 16
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_DENIED).append(':');
    stringBuilder.append(authority);
    return stringBuilder.toString();
}
 
Example 17
@Override
public Weight createWeight(IndexSearcher searcher, boolean requiresScore) throws IOException
{
    if(!(searcher instanceof SolrIndexSearcher))
    {
        throw new IllegalStateException("Must have a SolrIndexSearcher");
    }

    String[] auths = authorities.substring(1).split(authorities.substring(0, 1));
    BitsFilter denyFilter  = getACLFilter(auths, QueryConstants.FIELD_DENIED, (SolrIndexSearcher) searcher);
    return new ConstantScoreQuery(denyFilter).createWeight(searcher, false);
}
 
Example 18
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_DENYSET).append(':');
    stringBuilder.append(authorities);
    return stringBuilder.toString();
}
 
Example 19
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_OWNER).append(':');
    stringBuilder.append(authority);
    return stringBuilder.toString();
}
 
Example 20
private BitsFilter getOwnerFilter(String owner, SolrIndexSearcher searcher) throws IOException
{
    Query query =  new TermQuery(new Term(QueryConstants.FIELD_OWNER, owner));
    BitsFilterCollector collector = new BitsFilterCollector(searcher.getTopReaderContext().leaves().size());
    searcher.search(query, collector);
    return collector.getBitsFilter();
}
 
Example 21
Source Project: SearchServices   Source File: Cloud.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the doc list resulting from running the query
 * @param requestHandler the handler that handles the request
 * @param request the request object to put the query on
 * @param query the string that specifies the docs
 * @return the docs that come back from the query
 */
DocList getDocList(SolrRequestHandler requestHandler, SolrQueryRequest request, String query)
{
    // Getting the doc list is shard-specific, and not really cloud-friendly
    
    ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
    // Sets MAX_VALUE to get all the rows
    params.set("q", query).set("fl", QueryConstants.FIELD_SOLR4_ID).set("rows", Integer.MAX_VALUE);
    ResultContext rc = this.getResultContext(requestHandler, request, params);
    return rc != null ? rc.getDocList() : null;
}
 
Example 22
private void makeSureTransactionHasBeenIndexed(long transactionId) throws Exception
{
    //Check for the TXN state stamp.
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term(QueryConstants.FIELD_SOLR4_ID, "TRACKER!STATE!TX")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(LegacyNumericRangeQuery.newLongRange(QueryConstants.FIELD_S_TXID, transactionId, transactionId + 1, true, false), BooleanClause.Occur.MUST));
    BooleanQuery waitForQuery = builder.build();
    waitForDocCount(waitForQuery, 1, MAX_WAIT_TIME);
}
 
Example 23
private static Acl createAndIndexSomeAclData()
{
    try {

        AclChangeSet aclChangeSet = getAclChangeSet(1);

        Acl acl = getAcl(aclChangeSet);
        Acl acl2 = getAcl(aclChangeSet);

        AclReaders aclReaders = getAclReaders(aclChangeSet, acl, singletonList("joel"), singletonList("phil"), null);
        AclReaders aclReaders2 = getAclReaders(aclChangeSet, acl2, singletonList("jim"), singletonList("phil"), null);

        indexAclChangeSet(aclChangeSet, asList(acl, acl2), asList(aclReaders, aclReaders2));

        BooleanQuery.Builder builder = new BooleanQuery.Builder();
        builder.add(new BooleanClause(new TermQuery(new Term(QueryConstants.FIELD_SOLR4_ID, "TRACKER!STATE!ACLTX")), BooleanClause.Occur.MUST));
        builder.add(new BooleanClause(LegacyNumericRangeQuery.newLongRange(QueryConstants.FIELD_S_ACLTXID, aclChangeSet.getId(), aclChangeSet.getId() + 1, true, false), BooleanClause.Occur.MUST));
        BooleanQuery waitForQuery = builder.build();
        waitForDocCountAllCores(waitForQuery, 1, MAX_WAIT_TIME);

        return acl;
    }
    catch (Exception exception)
    {
        throw new RuntimeException(exception);
    }
}
 
Example 24
private void makeSureTransactionHasBeenIndexed(long transactionId) throws Exception
{
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term(QueryConstants.FIELD_SOLR4_ID, "TRACKER!STATE!TX")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(LegacyNumericRangeQuery.newLongRange(QueryConstants.FIELD_S_TXID, transactionId, transactionId + 1, true, false), BooleanClause.Occur.MUST));
    BooleanQuery waitForQuery = builder.build();
    waitForDocCount(waitForQuery, 1, MAX_WAIT_TIME);
}
 
Example 25
private void makeSureNodesHaveBeenIndexed(int expectedCount, String searchText) throws Exception
{
    waitForDocCount(new TermQuery(new Term("[email protected][email protected]{http://www.alfresco.org/model/content/1.0}content", searchText)), expectedCount, MAX_WAIT_TIME);

    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term("[email protected][email protected]{http://www.alfresco.org/model/content/1.0}content", searchText)), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(new TermQuery(new Term(QueryConstants.FIELD_OWNER, "mike")), BooleanClause.Occur.MUST));
    waitForDocCount(builder.build(), expectedCount, MAX_WAIT_TIME);
}
 
Example 26
/**
 * After updating the test data hierarchy (folders and file), the test checks that the cascade tracker properly
 * reflects the changes in the index.
 */
@Test 
public void solrTracking_folderUpdate_shouldReIndexFolderAndChildren() throws Exception
{
    // Update the folder
    Transaction txn = getTransaction(0, 1);

    folderMetaData.getProperties().put(ContentModel.PROP_CASCADE_TX, new StringPropertyValue(Long.toString(txn.getId())));
    folderMetaData.getProperties().put(ContentModel.PROP_NAME, new StringPropertyValue("folder2"));
    folderNode.setTxnId(txn.getId());
    folderMetaData.setTxnId(txn.getId());

    // Change the ancestor on the file just to see if it's been updated
    NodeRef nodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
    childFolderMetaData.setAncestors(ancestors(nodeRef));
    fileMetaData.setAncestors(ancestors(nodeRef));

    upsertData(txn, singletonList(folderNode), singletonList(folderMetaData));

    // Check that the ancestor has been changed and indexed
    TermQuery query = new TermQuery(new Term(QueryConstants.FIELD_ANCESTOR, nodeRef.toString()));
    waitForDocCount(query, 2, MAX_WAIT_TIME);

    // Child folder and grandchild document must be updated
    // This is the same query as before but instead of using a Lucene query, it uses the /afts endpoint (request handler)
    ModifiableSolrParams params =
            new ModifiableSolrParams()
                    .add(CommonParams.Q, QueryConstants.FIELD_ANCESTOR + ":\"" + nodeRef.toString() + "\"")
                    .add(CommonParams.QT, "/afts")
                    .add(CommonParams.START, "0")
                    .add(CommonParams.ROWS, "6")
                    .add(CommonParams.SORT, "id asc")
                    .add(CommonParams.FQ, "{!afts}AUTHORITY_FILTER_FROM_JSON");

    SolrServletRequest req =
            areq(params,
        "{\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [ \"mike\"], \"tenants\": [ \"\" ]}");

    assertQ(req, "*[count(//doc)=2]", "//result/doc[1]/long[@name='DBID'][.='" + childFolderNode.getId() + "']", "//result/doc[2]/long[@name='DBID'][.='" + fileNode.getId() + "']");
}
 
Example 27
/**
 * Inserts or updates the given data (nodes and corresponding metadata) using the given transaction.
 *
 * @param txn the transaction.
 * @param nodes the nodes.
 * @param metadata the nodes metadata.
 * @throws Exception hopefully never, otherwise the test fails (i.e. data hasn't been properly indexed).
 */
private void upsertData(Transaction txn, List<Node> nodes, List<NodeMetaData> metadata) throws Exception
{
    indexTransaction(txn, nodes, metadata);

    BooleanQuery.Builder builder =
            new BooleanQuery.Builder()
                    .add(new BooleanClause(new TermQuery(new Term(QueryConstants.FIELD_SOLR4_ID, "TRACKER!STATE!TX")), BooleanClause.Occur.MUST))
                    .add(new BooleanClause(LegacyNumericRangeQuery.newLongRange(QueryConstants.FIELD_S_TXID, txn.getId(), txn.getId() + 1, true, false),BooleanClause.Occur.MUST));

    Query waitForQuery = builder.build();
    waitForDocCount(waitForQuery, 1, MAX_WAIT_TIME);
}
 
Example 28
public  <Q, S, E extends Throwable> String getLuceneSortField(LuceneQueryParserAdaptor<Q, S, E> lqpa, String propertyName) throws E
{
    // Score is special
    if (propertyName.equalsIgnoreCase("Score"))
    {
        return "Score";
    }
    String field = getLuceneFieldName(propertyName);
    // need to find the real field to use
    if (field.startsWith(QueryConstants.PROPERTY_FIELD_PREFIX))
    {
        PropertyDefinition propertyDef = dictionaryService.getProperty(QName.createQName(field.substring(1)));

        // Handle .size and .mimetype
        if(propertyDef == null)
        {   
            if(field.endsWith(QueryConstants.FIELD_SIZE_SUFFIX))
            {
                propertyDef = dictionaryService.getProperty(QName.createQName(field.substring(1, field.length()-QueryConstants.FIELD_SIZE_SUFFIX.length())));
                if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
                {
                    throw new FTSQueryException("Order for "+QueryConstants.FIELD_SIZE_SUFFIX+" only supported on content properties");
                }
                else
                {
                    return field;
                }
            }
            else if (field.endsWith(QueryConstants.FIELD_MIMETYPE_SUFFIX))
            {
                propertyDef = dictionaryService.getProperty(QName.createQName(field.substring(1, field.length()-QueryConstants.FIELD_MIMETYPE_SUFFIX.length())));
                if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
                {
                    throw new FTSQueryException("Order for .mimetype only supported on content properties");
                }
                else
                {
                    return field;
                }
            }
            else
            {
                return field;
            }
        }
        else
        {
            if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
            {
                throw new FTSQueryException("Order on content properties is not curently supported");
            }
            else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT))
            {
                if(propertyDef.getIndexTokenisationMode() == IndexTokenisationMode.FALSE)
                {
                    return field;
                }

                String noLocalField = field+".no_locale";
                if(lqpa.sortFieldExists(noLocalField))
                {
                    return noLocalField;
                }
                field = findSortField(lqpa, field);
            }
            else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT))
            {
                field = findSortField(lqpa, field);

            }
            else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME))
            {
                field = lqpa.getDatetimeSortField(field, propertyDef);
            }
        }
    }
    return field;
}
 
Example 29
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException
{
    if(!(searcher instanceof SolrIndexSearcher))
    {
        throw new IllegalStateException("Must have a SolrIndexSearcher");
    }

    String[] auths = authorities.substring(1).split(authorities.substring(0, 1));

    SolrIndexSearcher solrIndexSearcher = (SolrIndexSearcher)searcher;
    Properties p = solrIndexSearcher.getSchema().getResourceLoader().getCoreProperties();
    boolean doPermissionChecks = Boolean.parseBoolean(p.getProperty("alfresco.doPermissionChecks", "true"));

    boolean hasGlobalRead = false;

    final HashSet<String> globalReaders = GlobalReaders.getReaders();

    for(String auth : auths)
    {
        if(globalReaders.contains(auth))
        {
            hasGlobalRead = true;
            break;
        }
    }

    if (hasGlobalRead || (doPermissionChecks == false))
    {
        return new MatchAllDocsQuery().createWeight(searcher, needsScores);
    }

    BitsFilter readFilter  = getACLFilter(auths, QueryConstants.FIELD_READER, solrIndexSearcher);
    BitsFilter ownerFilter = getOwnerFilter(auths, solrIndexSearcher);

    if (globalReaders.contains(PermissionService.OWNER_AUTHORITY))
    {
        readFilter.or(ownerFilter);
        return new ConstantScoreQuery(readFilter).createWeight(searcher, needsScores);
    }
    else
    {
        String[] ownerAuth = {PermissionService.OWNER_AUTHORITY};
        BitsFilter ownerReadFilter  = getACLFilter(ownerAuth, QueryConstants.FIELD_READER, solrIndexSearcher);
        ownerReadFilter.and(ownerFilter);
        readFilter.or(ownerReadFilter);
        return new ConstantScoreQuery(readFilter).createWeight(searcher, needsScores);
    }
}
 
Example 30
public DelegatingCollector getFilterCollector(IndexSearcher searcher)
{

    String[] auths = authorities.substring(1).split(authorities.substring(0, 1));

    SolrIndexSearcher solrIndexSearcher = (SolrIndexSearcher)searcher;
    Properties p = solrIndexSearcher.getSchema().getResourceLoader().getCoreProperties();
    boolean doPermissionChecks = Boolean.parseBoolean(p.getProperty("alfresco.doPermissionChecks", "true"));
    boolean hasGlobalRead = false;

    final HashSet<String> globalReaders = GlobalReaders.getReaders();

    for(String auth : auths)
    {
        if(globalReaders.contains(auth))
        {
            hasGlobalRead = true;
            break;
        }
    }

    if (hasGlobalRead || (doPermissionChecks == false))
    {
        return new AllAccessCollector();
    }

    try
    {

        /*
        *  Collect the ACLID's that match the authorities.
        *  This is done by querying the ACL records in the index. See the method for more
        *  documentation on this query.
        */

        HybridBitSet aclSet = getACLSet(auths, QueryConstants.FIELD_READER, solrIndexSearcher);

        /*
        * Collect the documents that the user owns.
        */

        BitsFilter ownerFilter = getOwnerFilter(auths, solrIndexSearcher);

        if (globalReaders.contains(PermissionService.OWNER_AUTHORITY))
        {
            return new AccessControlCollector(aclSet, ownerFilter);
        }
        else
        {
            String[] ownerAuth = {PermissionService.OWNER_AUTHORITY};
            HybridBitSet ownerAclSet = getACLSet(ownerAuth, QueryConstants.FIELD_READER, solrIndexSearcher);
            return new AccessControlCollectorWithoutOwnerRead(aclSet, ownerAclSet, ownerFilter);
        }
    }
    catch(Exception e)
    {
        throw new RuntimeException(e);
    }
}