1

I am working on an application which lists and searches document from alfresco. The issue is the alfresco can return upto 5000 records per query. but I don't want my application to list down all documents instead if I can some how implement pagination in alfresco, so that alfresco only return X result per page. I am using Alfresco 4 enterprise edition.

Any help or suggestion please.

UPDATE (Example) I have written a web script which executes the query and returns all the documents satisfies the condition. Lets say, there are 5000 entries found. I want to modify my web script in a way that the web script returns 100 documents for 1st page, next 100 for second page and so on...

It'll be something like usage of Limit BY and OFFSET keywords. something like this

SaQiB
  • 639
  • 8
  • 18

2 Answers2

3

There are two ways to query on the SearchService (excluding the selectNodes/selectProperties calls). One way is to specify all your arguments directly to the query method. This has the advantage of being concise, but the disadvantage is that you don't get all the options.

Alternately, you can query with a SearchParameters object. This lets you do everything the simple query does, and more. Included in that more are setLimit, setSkipCount and setMaxItems, which will allow you to do your paging.

If your query used to be something like:

searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "lucene", myQuery);

You'd instead do something like:

SearchParameters sp = new SearchParameters();
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
sp.setLanguage("lucene");
sp.setQuery(myQuery);
sp.setMaxItems(100);
sp.setSkipCount(900);
searchService.query(sp);
Dark Star1
  • 6,986
  • 16
  • 73
  • 121
Gagravarr
  • 47,320
  • 10
  • 111
  • 156
  • Nice, Thanks for now... One thing, if I am doing paging, the results can be retrieved and skipped by setting above parameters, but is there anyway I can figure out the total no of records for the search query.that will help in estimating total no pages.. (just the count would be enough & efficient, I think ) – SaQiB Jul 18 '12 at 11:52
1

Assuming you have written your webscript in Javascript you can use the search.query() function and add the page property to the search definition as shown below:

var sort1 =   {
     column: "@{http://www.alfresco.org/model/content/1.0}modified",
     ascending: false   
};   

var sort2 =   {
     column: "@{http://www.alfresco.org/model/content/1.0}created",
     ascending: false   
};   

var paging =   {
     maxItems: 100,
     skipCount: 0   
};   

var def = {
     query: "cm:name:test*",
     store: "workspace://SpacesStore",
     language: "fts-alfresco",
     sort: [sort1, sort2],
     page: paging   
};   

var results = search.query(def);

You can find more information here: http://wiki.alfresco.com/wiki/4.0_JavaScript_API#Search_API

Florian
  • 1,281
  • 7
  • 17