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

The following examples show how to use org.alfresco.repo.search.adaptor.lucene.QueryConstants. 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
Source File: SolrDenySetQuery.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #2
Source File: SolrOwnerScorer.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
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
Source File: AlfrescoSolrTrackerStateIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #4
Source File: AlfrescoSolrFingerprintIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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
Source File: DistributedAlfrescoSolrTrackerStateIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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
Source File: AbstractAuthoritySetQuery.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #7
Source File: CascadingIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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
Source File: SolrDeniedQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_DENIED).append(':');
    stringBuilder.append(authority);
    return stringBuilder.toString();
}
 
Example #9
Source File: DistributedAlfrescoSolrTrackerStateIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #10
Source File: SolrOwnerQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #11
Source File: SolrOwnerQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_OWNER).append(':');
    stringBuilder.append(authority);
    return stringBuilder.toString();
}
 
Example #12
Source File: SolrOwnerSetQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_OWNERSET).append(':');
    stringBuilder.append(authorities);
    return stringBuilder.toString();
}
 
Example #13
Source File: AlfrescoSolrFingerprintIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #14
Source File: AlfrescoSolrTrackerStateIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #15
Source File: SolrDenySetQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #16
Source File: SolrReaderQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_READER).append(':');
    stringBuilder.append(authority);
    return stringBuilder.toString();
}
 
Example #17
Source File: SolrDenySetQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_DENYSET).append(':');
    stringBuilder.append(authorities);
    return stringBuilder.toString();
}
 
Example #18
Source File: AlfrescoSolrTrackerStateIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void makeSureNodesHaveBeenIndexed(int expectedCount, String searchText) throws Exception
{
    waitForDocCount(new TermQuery(new Term("content@s___t@{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("content@s___t@{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 #19
Source File: SolrAuthorityQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_AUTHORITY).append(':');
    stringBuilder.append(authority);
    return stringBuilder.toString();
}
 
Example #20
Source File: Lucene4QueryParserAdaptor.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #21
Source File: Cloud.java    From SearchServices with 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
Source File: SolrReaderSetQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_READERSET).append(':');
    stringBuilder.append(authorities);
    return stringBuilder.toString();
}
 
Example #23
Source File: SolrOwnerSetScorer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #24
Source File: CascadingIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 #25
Source File: SolrAuthoritySetQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #26
Source File: SolrAuthoritySetQuery.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toString(String field)
{
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(QueryConstants.FIELD_AUTHORITYSET).append(':');
    stringBuilder.append(authorities);
    return stringBuilder.toString();
}
 
Example #27
Source File: CascadingIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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
Source File: AlfrescoFieldMapperTransformerIT.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void populateAlfrescoData() 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();
    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, 80000);

    int numNodes = 5;
    List<Node> nodes = new ArrayList<>();
    List<NodeMetaData> nodeMetaDatas = new ArrayList<>();

    Transaction bigTxn = getTransaction(0, numNodes);
    Date now = new Date();

    for (int i = 0; i < numNodes; i++)
    {
        Node node = getNode(bigTxn, acl, Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, acl, "mike", null, false);
        nodeMetaData.getProperties().put(ContentModel.PROP_TITLE, new MLTextPropertyValue(Map.of(Locale.getDefault(),"title"+(i+1))));
        nodeMetaData.getProperties().put(ContentModel.PROP_NAME, new StringPropertyValue("name"+(i+1)));
        nodeMetaData.getProperties().put(ContentModel.PROP_CREATED,
                new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, now)));
        nodeMetaDatas.add(nodeMetaData);
    }

    indexTransaction(bigTxn, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), numNodes, 100000);
}
 
Example #29
Source File: DistributedAlfrescoSolrFingerPrintIT.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
@BeforeClass
public static void initData() throws Throwable
{
    initSolrServers(2,DistributedAlfrescoSolrFingerPrintIT.getSimpleClassName(),null);

    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();
    waitForDocCountAllCores(waitForQuery, 1, 80000);

    Transaction txn = getTransaction(0, 4);

    //Next create two NODES to update for the transaction
    NODES[0] = getNode(txn, ACL, Node.SolrApiNodeStatus.UPDATED);
    NODES[1] = getNode(txn, ACL, Node.SolrApiNodeStatus.UPDATED);
    NODES[2] = getNode(txn, ACL, Node.SolrApiNodeStatus.UPDATED);
    NODES[3] = getNode(txn, ACL, Node.SolrApiNodeStatus.UPDATED);


    //Next create the NodeMetaData for each node. TODO: Add more metadata
    NODES_METADATA[0] = getNodeMetaData(NODES[0], txn, ACL, "mike", null, false);
    NODES_METADATA[1] = getNodeMetaData(NODES[1], txn, ACL, "mike", null, false);
    NODES_METADATA[2] = getNodeMetaData(NODES[2], txn, ACL, "mike", null, false);
    NODES_METADATA[3] = getNodeMetaData(NODES[3], txn, ACL, "mike", null, false);

    List<String> content = new ArrayList<>();
    int[] sizes = {2000, 1000, 1500, 750};

    Random r = new Random(1);
    String token1 = Integer.toString(Math.abs(r.nextInt()));

    for(int i=0; i<4; i++) {
        Random rand = new Random(1);
        StringBuilder buf = new StringBuilder();
        int size = sizes[i];
        for(int s=0; s<size; s++) {
            if(s>0) {
                buf.append(" ");
            }
            buf.append(Math.abs(rand.nextInt()));
        }
        content.add(buf.toString());
    }

    //Index the transaction, NODES, and nodeMetaDatas.
    //Note that the content is automatically created by the test framework.
    indexTransaction(txn,
        asList(NODES[0], NODES[1], NODES[2], NODES[3]),
        asList(NODES_METADATA[0], NODES_METADATA[1], NODES_METADATA[2], NODES_METADATA[3]),
        content);

    //Check for the TXN state stamp.
    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, txn.getId(), txn.getId() + 1, true, false), BooleanClause.Occur.MUST));
    waitForQuery = builder.build();

    waitForDocCountAllCores(waitForQuery, 1, 80000);

    /*
     * Query the index for the content
     */

    waitForDocCountAllCores(new TermQuery(new Term(QueryConstants.FIELD_READER, "jim")), 1, 80000);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", token1)), 4, 80000);
}
 
Example #30
Source File: AlfrescoHighlighterIT.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected static void loadData() throws Exception
{
    /*
     * Create and index an AclChangeSet.
     */
    String long_text = "this is some long text.  It has the word long in many places.  " +
            "In fact, it has long on some different fragments.  " +
            "Let us see what happens to long in this case.";

    List<Map<String, String>> data = asList(
            of("name", "some very long name",
                    "description", "mydesc",
                    "title", "title1 is very long"),
            of("name", long_text,
                    "title", "title2"),
            of("name", "MixedCabbageString and plurals and discussion",
                    "title", "title2"));

    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));


    //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();
    long MAX_WAIT_TIME = 80000;
    waitForDocCount(waitForQuery, 1, MAX_WAIT_TIME);


    String owner = "mike";

    //First create a transaction.
    Transaction foldertxn = getTransaction(0, 1);
    Transaction txn = getTransaction(0, 2);

    // Create folder
    Node folderNode = getNode(foldertxn, acl, Node.SolrApiNodeStatus.UPDATED);
    NodeMetaData folderMetaData = getNodeMetaData(folderNode, foldertxn, acl, owner, null, false);


    List<Node> nodeList = new ArrayList<>();
    List<NodeMetaData> metadataList = new ArrayList<>();

    data.forEach(entry ->
    {
        Node node = getNode(txn, acl, Node.SolrApiNodeStatus.UPDATED);
        nodeList.add(node);
        NodeMetaData fileMetaData  = getNodeMetaData(node,  txn, acl, owner, ancestors(folderMetaData.getNodeRef()), false);
        Map<QName, PropertyValue> properties = fileMetaData.getProperties();
        properties.put(ContentModel.PROP_NAME, new StringPropertyValue(entry.get("name")));

        HashMap<Locale, String> titleProp = new HashMap<>();
        titleProp.put(Locale.ENGLISH, entry.get("title"));

        properties.put(ContentModel.PROP_TITLE, new  MLTextPropertyValue(titleProp));

        String description = entry.get("description");
        if (description != null)
        {
            HashMap<Locale, String> descProp = new HashMap<>();
            descProp.put(Locale.ENGLISH, description);
            properties.put(ContentModel.PROP_DESCRIPTION, new  MLTextPropertyValue(descProp));
        }

        metadataList.add(fileMetaData);
    });

    indexTransaction(foldertxn, singletonList(folderNode), singletonList(folderMetaData));
    indexTransaction(txn, nodeList, metadataList);

    waitForDocCount(new TermQuery(new Term(QueryConstants.FIELD_READER, "jim")), 1, MAX_WAIT_TIME);
    waitForDocCount(new TermQuery(new Term(QueryConstants.FIELD_OWNER, owner)), 4, MAX_WAIT_TIME);
}