lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: Index locked exception while updating index
Date Mon, 25 Jul 2005 09:25:49 GMT

On Jul 24, 2005, at 12:17 PM, Harini Raghavan wrote:

> Hi All,
>
> I am trying to add paging functionality while using lucene search.  
> I have created a PageFilter what takes in the current page num and  
> the number of records as input and invoking the IndexSearcher  
> passing the a Boolean Query object and the PageFilter. The search  
> returns around 1000 records when invoked without the PageFilter,  
> but with the PageFilter, it returns only 6 records. I did some  
> debugging and realised that the in the  
> org.apache.lucene.search.IndexSearcher.search method, the bitset.get 
> (doc) is returning false for all the other documents and so they  
> are not added to the results.
> Has someone implemented Paging using filters or tell me if I am  
> missing something here?

A Filter really isn't the right place to add paging.  A Filter makes  
a subset of documents available to searching.  Your example is making  
the first 20 documents available for search, but only 6 of those  
matched the query (so it seems at first glance).

Paging can be done a couple of different ways - 1) keep Hits around  
(and the associated IndexSearcher) and reuse it for paging rather  
than searching again.  2) Simply re-search and pick the appropriate  
starting point in Hits.   I've always used option #2 as it has always  
been fast enough.

     Erik


>
> Here is the code :
>
> public List searchDocuments(DocumentSearchCriteria searchCriteria)  
> throws ApplicationException {
>      List results = new ArrayList();
>      String indexLoc = luceneConfig.getIndexDir();
>      Directory fsDir = getIndexDirectory(indexLoc, false);
>      IndexSearcher searcher = getIndexSearcher(fsDir);
>
>      Query query = indexSearchUtil.getSearchQuery(searchCriteria);
>      try {
>            Hits hits = searcher.search(query, new PageFilter(0,20));
>            logger.info("Found " + hits.length() + " document(s)  
> that matched query '" + query + "':");
>            results = indexSearchUtil.populateDocumentInfoView(hits,  
> results);
>      } catch(Exception e) {
>           logger.error("Exception occurred in searchDocuments()");
>      }
>      return results;
> }
>
> Here is the PageFilter :
>
> public class PageFilter extends Filter {
>    private int start;
>    private int end;
>
>    public PageFilter(int pageNum, int pageSize) {
>        start = pageNum * pageSize;
>        end = (pageNum+1) * pageSize;
>    }
>
>    public BitSet bits(IndexReader reader) throws IOException {
>        BitSet result = new BitSet(reader.maxDoc());
>        for(int i=start; (i<end) && (i<result.size()); i++) {
>            result.set(i);
>        }
>        return result;
>    }
> }
>
> Any suggestion would be greatly appreciated.
> Thanks,
> Harini
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message