AnsweredAssumed Answered

Problems with Lucene and setLimit/setLimitBy

Question asked by alr on Oct 14, 2008
Latest reply on Oct 15, 2008 by rivarola
Hello,

I am currently investigating a problem, where I want to limit the amount of returned results, when performing (and sorting) a lucene search. This is what I do in the source:


SearchParameters sp = new SearchParameters();
sp.addStore(storeRef);
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setLimitBy(LimitBy.FINAL_SIZE);
sp.setLimit(limit);
sp.addSort(sortField, sortAscending);
sp.setQuery(searchString);

ResultSet resultSet = searchService.query(sp);
List<NodeRef> refs = resultSet.getNodeRefs();
       
if (logger.isDebugEnabled()) {
    ResultSetMetaData metaData = resultSet.getResultSetMetaData();
    logger.debug("Search has been limited by " + metaData.getLimitedBy() + ". # of results: " + refs.size());
    logger.debug("SP GetLimit: " + metaData.getSearchParameters().getLimit() + " and limitby " + metaData.getSearchParameters().getLimitBy());
}

Now this is the logger output:

16:48:07,330 User:admin DEBUG [alfresco.search.MySearchImpl] Search has been limited by UNLIMITED. # of results: 108
16:48:07,330 User:admin DEBUG [alfresco.search.MySearchImpl] SP GetLimit: 101 and limitby FINAL_SIZE

So, somehow, my limit settings are completely ignored. I get 108 results returned. In case you wonder, why I set the limit to 101, take a look at org.alfresco.service.cmr.search.ResultSetMetaData, where is written in the comments, that searches for an amount lower than 100, might return LimitBy.UNLIMITED. However in this case the search does it as well (sorting works btw).

So, is there anything I am overlooking right now, or didn't I parse the ResultSet correctly? Do I need to access filtered results in another way?

I am using Alfresco Labs 3b, btw.

Thanks for the help!


–Alexander

Outcomes