Lucene query with pagination

cancel
Showing results for 
Search instead for 
Did you mean: 
mdmustaf
Member II

Lucene query with pagination

I am trying to reduce the search resullt using lunene query with pagination option.(maxItems and skipCount). 

Can any one help me to write a lucene query with pagination option.  

Alfrescolucene.JPGAlfrescoLuceneResult.JPG

3 Replies
abhinavmishra14
Advanced

Re: Lucene query with pagination

You can also use Search V1 Rest API:

 

Query example: 
{ "query": { "query": "+TYPE:\"cm:content\"", "language": "afts" }, "paging": { "maxItems": "25", "skipCount": "10" }, "sort": [{"type":"FIELD", "field":"cm:name", "ascending":"false"}] }

 curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' --header 'Authorization: Basic VElDS0VUXzIxYzAzOWMxNjFjYzljMDNmNmNlMzAwYzAyMDY5YTQ2OTQwZmYzZmM=' --data-binary '@paging-sort-query.json' 'http://localhost:8080/alfresco/api/-default-/public/search/versions/1/search'

 

Alternatively, if you prefer to write your own webscript, Have a look at the WebScript in the post here

var contentType = "cm:content"
var aspectName = "demo:webable"

var query = 'PATH:"/app:company_home/st:sites//*" AND TYPE:"'+contentType+'" AND NOT ASPECT:"'+aspectName+'" AND NOT ASPECT:"cm:lockable"';

var page = { skipCount : 0, maxItems : 1000
}; var searchQuery = { query : query, language : "lucene", page : page }; logger.log("Query for search: "+query) var nodes = search.query(searchQuery);

https://hub.alfresco.com/t5/alfresco-content-services-forum/is-there-any-endpoint-in-alfresco-that-a...

It searches the repository with paginated options and adds a missing aspect. 
you can take reference from the script.

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
afaust
Master

Re: Lucene query with pagination

The original poster is clearly using Alfresco 4.2 or earlier, which still supported Alfresco Explorer, so they cannot use v1 ReST API at all, which were only added in Alfresco 5.2.

The suggestion with using JavaScript API in a web script is appropriate - alternative, Java API in a Java-backed web script or any other component where you need the query is also possible. Within the Node Browser, which the OP posted as a screenshot, there is no support for pagination. The query itself can also not be rewritten to use pagination - pagination absolutely requires the use of query-external search parameters.

With regards to using Lucene: This is quite an old and deprecated search query language. In Alfresco 4.x, you can already use Alfresco FTS (AFTS / fts-alfresco) which is the recommended query language for cross-version support, and which also receives performance improvements and new features, such as TMQ. Apart from Alfresco 3.x and earlier versions, Lucene should be avoided.

mdmustaf
Member II

Re: Lucene query with pagination

Thanks for the reply.
 
public static final String QUERY_LANGUAGE = "lucene";
String lucenequery= "+@cm\\:categories:\"*" + "0a2ac5ef-bf4b-41e9-9926-9f89269a20d7" + "*\"";
 
log.info("Starting search type=" + QUERY_LANGUAGE);
log.info("Query: " + QUERY);

 

org.alfresco.webservice.repository.RepositoryServiceSoapPort repo = ctx.getClient().create(Endpoint.REPO_SERVICE);
Query query = new Query();
query.setLanguage(QUERY_LANGUAGE);
query.setStatement(lucenequery.toString());
QueryResult result = repo.query(SPACES_STORE, query, false);
 
We are using RepositoryServiceSoapPort.java class to get related asset belong to particular category. How do we add condition like maxItems and skipCount to implement pagination here.
 
Take an example: If category 'A' contains 10000 assets  but we want get top 100 assets for first query and for next query we have to get next 100 and so on.