Java Code Examples for org.alfresco.service.cmr.search.SearchService#query()

The following examples show how to use org.alfresco.service.cmr.search.SearchService#query() . 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: SearcherComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ResultSet query(SearchParameters searchParameters)
{
    if(searchParameters.getStores().size() == 0)
    {
        throw new IllegalStateException("At least one store must be defined to search");
    }
    StoreRef storeRef = searchParameters.getStores().get(0);
    SearchService searcher = indexerAndSearcherFactory.getSearcher(storeRef, !searchParameters.excludeDataInTheCurrentTransaction());
    return searcher.query(searchParameters);
}
 
Example 2
Source File: ConcurrentNodeServiceSearchTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testConcurrent() throws Exception
{
    int count = 10;
    int repeats = 10;

    SearchService searcher = (SearchService) ctx.getBean(ServiceRegistry.SEARCH_SERVICE.getLocalName());

    Map<QName, ChildAssociationRef> assocRefs = commitNodeGraph();
    Thread runner = null;

    for (int i = 0; i < count; i++)
    {
        runner = new Nester("Concurrent-" + i, runner, repeats, searcher);
    }
    if (runner != null)
    {
        runner.start();

        try
        {
            runner.join();
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }
    }

    assertEquals(2, searcher.selectNodes(rootNodeRef, "/*", null,
            getNamespacePrefixReolsver(""), false).size());
    ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"");
    // n6 has root aspect - there are three things at the root level in the
    // index
    assertEquals(3, results.length());
    results.close();
}
 
Example 3
Source File: CronScheduledQueryBasedTemplateActionDefinitionTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Check the nodes to be indexed
 * 
 * @param nodes
 * @throws Exception
 */
private void checkNodes(List<FileInfo> nodes) throws Exception
{
    SearchService searchService = registry.getSearchService();
    
    boolean notFound = false;
    for (int i = 1; i <= 40; i++)
    {
        notFound = false;
        for (FileInfo fileInfo : nodes)
        {
            ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home//cm:" + TEST_FOLDER_NAME + "//cm:" + fileInfo.getName() + "\"");
            if (resultSet.length() == 0)
            {
                notFound = true;
                break;
            }
        }
        if (notFound)
        {
            Thread.sleep(500);
        }
        else
        {
            break;
        }
    }
    assertFalse("The content was not created or indexed correctly.", notFound);
}
 
Example 4
Source File: LuceneCategoryServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Collection<ChildAssociationRef> getChildren(NodeRef categoryRef, Mode mode, Depth depth, boolean sortByName, String filter, int fetchSize)
{
    if (categoryRef == null)
    {
        return Collections.<ChildAssociationRef> emptyList();
    }
    
    categoryRef = tenantService.getBaseName(categoryRef); // for solr
    
    ResultSet resultSet = null;
    try
    {
        StringBuilder luceneQuery = new StringBuilder(64);

        switch (mode)
        {
        case ALL:
            luceneQuery.append("PATH:\"");
            luceneQuery.append(buildXPath(nodeService.getPath(categoryRef))).append("/");
            if (depth.equals(Depth.ANY))
            {
                luceneQuery.append("/");
            }
            luceneQuery.append("*").append("\" ");
            break;
        case MEMBERS:
            luceneQuery.append("PATH:\"");
            luceneQuery.append(buildXPath(nodeService.getPath(categoryRef))).append("/");
            if (depth.equals(Depth.ANY))
            {
                luceneQuery.append("/");
            }
            luceneQuery.append("member").append("\" ");
            break;
        case SUB_CATEGORIES:
            luceneQuery.append("+PATH:\"");
            luceneQuery.append(buildXPath(nodeService.getPath(categoryRef))).append("/");
            if (depth.equals(Depth.ANY))
            {
                luceneQuery.append("/");
            }
            luceneQuery.append("*").append("\" ");
            luceneQuery.append("+TYPE:\"" + ContentModel.TYPE_CATEGORY.toString() + "\"");
            break;
        }
        if (filter != null)
        {
            luceneQuery.append(" " + "+@cm\\:name:\"*" + filter + "*\"");
        }

        // Get a searcher that will include Categories added in this transaction
        SearchService searcher = indexerAndSearcher.getSearcher(categoryRef.getStoreRef(), true);
        
        // Perform the search
        SearchParameters searchParameters = new SearchParameters();
        resultSet = searcher.query(categoryRef.getStoreRef(), "lucene", luceneQuery.toString(), null);
        searchParameters.setLanguage("lucene");
        if(sortByName)
        {
        	searchParameters.addSort("@" + ContentModel.PROP_NAME, true);
        }
        searchParameters.setQuery(luceneQuery.toString());
        searchParameters.setLimit(-1);
        searchParameters.setMaxItems(fetchSize);
        searchParameters.setLimitBy(LimitBy.FINAL_SIZE);
        searchParameters.addStore(categoryRef.getStoreRef());
        resultSet = searcher.query(searchParameters);

        // Convert from search results to the required Child Assocs
        return resultSetToChildAssocCollection(resultSet);
    }
    finally
    {
        if (resultSet != null)
        {
            resultSet.close();
        }
    }
}