Lucene query with pagination

Showing results for 
Search instead for 
Did you mean: 
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.  


3 Replies

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

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


(ACSCE, AWS SAA, Azure Admin)

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.

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" + "*\"";"Starting search type=" + QUERY_LANGUAGE);"Query: " + QUERY);


org.alfresco.webservice.repository.RepositoryServiceSoapPort repo = ctx.getClient().create(Endpoint.REPO_SERVICE);
Query query = new Query();
QueryResult result = repo.query(SPACES_STORE, query, false);
We are using 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.