cancel
Showing results for 
Search instead for 
Did you mean: 

Create custom java backed web script to filter content in sites

pragashonlink
Champ in-the-making
Champ in-the-making
I'm planning to create a custom java backed alfresco search. This search should be able to search items only in "All Sites". I'm struggling to write a Lucene search query to build the search. Please check the code below.


     StringBuilder query = new StringBuilder();
   
    query.append("TYPE:\"");
    query.append(ContentModel.TYPE_CONTENT);
    query.append("\" AND ALL:\"");
    query.append(searchTerms);
    query.append("\"");

    SearchParameters parameters = new SearchParameters();
    parameters.addStore(Repository.getStoreRef());
    parameters.setLanguage(SearchService.LANGUAGE_LUCENE);
    parameters.setQuery(query.toString());

    results = serviceRegistry.getSearchService().query(parameters);
    totalRecords = results.length();


The above code is returning the results from all the contents in the Alfresco system. Instead I want to be able to search only contents within sites (All Sites).
4 REPLIES 4

jpotts
World-Class Innovator
World-Class Innovator
The problem is that content that lives in a site isn't identified as such. It lives in a folder just like content in other parts of the repository.

One idea to work around this would be to create a rule on the Sites folder. The rule would add a custom aspect (maybe called "siteContent" or something like that) to all instances of cm:content. This rule would be applied recursively so that any content created in any site would get the aspect.

Once that is in place, you could use the presence of the aspect to filter your search results using the ASPECT keyword.

Jeff

pragashonlink
Champ in-the-making
Champ in-the-making
Thanks Jeff, that is a good idea. I'll try that out. In the meantime my colleague showed me the Alfresco community installation on his machine. In that once we do an advanced search it displays the option to filter the results by "All Sites" and "Repository". Do you know how does the Alfresco system handle this without having to create an aspect as you mentioned above ?

Try path query to search under sites folder only.

jpotts
World-Class Innovator
World-Class Innovator
Agreed, that is another way to go. At least in all versions thus far, all sites live in a folder that resides under /Sites so you could use:
PATH:"/app:company_home/st:sites//*"


As part of your query and that would restrict the content to content stored in a site.

Jeff