lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul.Illingwo...@saaconsultants.com
Subject Re: AW: cancel search
Date Fri, 09 Sep 2005 09:12:10 GMT





You could always create a subclass of RuntimeException and throw and catch
this instead.

"Kunemann Frank" <frank.kunemann@innosystec.de> wrote on 09/09/2005
10:01:56:

> Exceptions didn't work as you need to implement the HitCollector
> class. Its method "collect" doesn't throw any exceptions and I don't
> want to rewrite anything of Lucene, so I'm using "searcher.close()"
instead:
>
>
> public class TimedHitCollector extends HitCollector
> {
>     private Searcher searcher;
>     private ArrayList ids = new ArrayList();
>     private long startTime;
>     private long maxTime;
>     private long endTime;
>     private int maxDocs = 10;
>
>     public TimedHitCollector(Searcher searcher, ArrayList list, long
maxTime)
>     {
>         startTime = System.currentTimeMillis();
>         this.searcher = searcher;
>         this.ids = list;
>         this.maxTime = maxTime;
>     }
>
>     public void collect(int id, float score)
>     {
>         long diff = System.currentTimeMillis() - startTime;
>
>         if((diff > maxTime) || (ids.size() >= maxDocs)) {
>
>             endTime = System.currentTimeMillis();
>             System.out.println("canceling search...");
>
>             try {
>                 searcher.close();
>             }
>             catch(IOException e) {
>                 e.printStackTrace();
>             }
>         }
>         else {
>             ids.add(new Integer(id));
>             endTime = System.currentTimeMillis();
>         }
>     }
> }
>
> Be sure to catch IOException when calling searcher.search from your
> application, otherwise your program will exit sometimes. In this
> case no results will be returned.
> That's why I can't use it to cancel the search after a given time or
> amount of documents found. But it's good enough for a cancel-button.
>
> Hope this will help everyone having the same problem.
>
>
> Frank
>
> -----Urspr√ľngliche Nachricht-----
> Von: Yonik Seeley [mailto:yseeley@gmail.com]
> Gesendet: Donnerstag, 8. September 2005 15:09
> An: java-user@lucene.apache.org
> Betreff: Re: cancel search
>
> You could create your own HitCollector that checked a flag on each hit,
and
> throw an exception if it was set.
> In a separate thread, you could set the flag to cancel the search.
>
> -Yonik
> Now hiring -- http://tinyurl.com/7m67g
>
> On 9/8/05, Kunemann Frank <frank.kunemann@innosystec.de> wrote:
> >
> >
> > The problem is that when searching there is no real save point to stop
> > the thread. The only line that takes time is this one:
> >
> > Hits hits = searcher.search(query);
> >
> >
> > Frank
> >
> > >I've had such a long lasting search too. I sounds good to start the
> > >search in another thread. I've done this for the indexing procedure.
> > >This is started in another thread and the gui will be informed when
> > >indexing is performed. If the user will stop it he has to click on a
> > >button stop and then an event is send to the indexerthread. The
> > >indexerthread stops if he reaches a safe point. Surely this is for
> > >indexing but I think this would work for searching also.
> > >stefan
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>
> ---------------------------------------------------------------------
> 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