How to use customized Collector class with IndexSearcher.searchAfter() method

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use customized Collector class with IndexSearcher.searchAfter() method

Chellasamy G
Hi,



I have written a customized collector and usually search the index using this collector.



i.e using the below method,



IndexSearcher.search(Query query, Collector results)





But, I cant find any searchAfter() methods in IndexSearcher which accepts a Collector input.

Please let me know how to use a customized collector when using searchAfter() method.

 



Thanks,

Satyan




Reply | Threaded
Open this post in threaded view
|

RE: How to use customized Collector class with IndexSearcher.searchAfter() method

Uwe Schindler
Hi,

search after is implemented inside the collector, so it cannot be exposed by APIs like that. Lucene by default does not support anything like searching after or starting with, because this task is done by the collector (soring, paging,...). The TopDocsCollector subclasses are doing this.

Uwe

-----
Uwe Schindler
Achterdiek 19, D-28357 Bremen
http://www.thetaphi.de
eMail: [hidden email]

> -----Original Message-----
> From: Chellasamy G <[hidden email]>
> Sent: Friday, May 18, 2018 8:00 PM
> To: java-user <[hidden email]>
> Subject: How to use customized Collector class with
> IndexSearcher.searchAfter() method
>
> Hi,
>
>
>
> I have written a customized collector and usually search the index using this
> collector.
>
>
>
> i.e using the below method,
>
>
>
> IndexSearcher.search(Query query, Collector results)
>
>
>
>
>
> But, I cant find any searchAfter() methods in IndexSearcher which accepts a
> Collector input.
>
> Please let me know how to use a customized collector when using
> searchAfter() method.
>
>
>
>
>
> Thanks,
>
> Satyan
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: How to use customized Collector class with IndexSearcher.searchAfter() method

Chellasamy G
Hi Uwe,



Thanks for replying. I now understood how to do it.



Actually my requirement was to search records which fall between certain hours in a day i.e records between 9AM to 5PM(each record has a GMT timestamp field indexed). The problem here is the timezone, I have to adjust the hour value based on the timezone.

If it is going to be a single timezone, I could index the adjusted hour value in the index itself but in my case the timezone is dynamic and it could vary. So, I used a customized collector as shown in the below code, in which I have written my code logic to filter the records.



Please check the code and let me know if it is a correct way to do it or if there is any better way to accomplish the requirement.





MyCollector timeFilterCollector = new MyCollector("TIME_FIELD", 9, 17, "PST", sortBy, 25, null);

indexSearcher.search(query, timeFilterCollector);

TopDocs topDocs = timeFilterCollector.collector.topDocs();





class MyCollector implements Collector {





      private String filterField;

      private int startHour;

      private int endHour;

      private String timeZone;

      public TopFieldCollector collector;



      public MyCollector(String filterField, int startHour, int endHour, String timeZone, Sort sort, int numHits, FieldDoc after) {

            this.filterField = filterField;

            this.startHour = startHour;

            this.endHour = endHour;

            this.timeZone = timeZone;

            this.collector = TopFieldCollector.create(sort, numHits, after, true, false, false);

      }



      @Override

      public LeafCollector getLeafCollector(final LeafReaderContext context)

            throws IOException {



            SortedNumericDocValues values = DocValues.getSortedNumeric(context.reader(), filterField);

            final LeafCollector topLevelLeafCollector = collector.getLeafCollector(context);



            return new LeafCollector() {

           

                  @Override

                  public void collect(int doc) throws IOException {

                        if(values.advanceExact(doc)) {

                              long value = values.nextValue();

                              int evtHour = new DateTime(value * 1000L, DateTimeZone.forID(timeZone)).getHourOfDay();  // convert timestamp to hrs

                              if(startHour &lt;= evtHour &amp;&amp; evtHour &lt;= endHour) {

                                    topLevelLeafCollector.collect(doc);

                              }

                        }

                  }



                  @Override

                  public void setScorer(Scorer arg0) throws IOException {

                  }

            };

      }



      @Override

      public boolean needsScores() {

            return false;

      }

}





Thanks,

Satyan






---- On Fri, 18 May 2018 23:34:11 +0530 Uwe Schindler &lt;[hidden email]&gt; wrote ----




Hi,

 

search after is implemented inside the collector, so it cannot be exposed by APIs like that. Lucene by default does not support anything like searching after or starting with, because this task is done by the collector (soring, paging,...). The TopDocsCollector subclasses are doing this.

 

Uwe

 

-----

Uwe Schindler

Achterdiek 19, D-28357 Bremen

http://www.thetaphi.de 

eMail: [hidden email]

 

&gt; -----Original Message-----

&gt; From: Chellasamy G &lt;[hidden email]&gt;

&gt; Sent: Friday, May 18, 2018 8:00 PM

&gt; To: java-user &lt;[hidden email]&gt;

&gt; Subject: How to use customized Collector class with

&gt; IndexSearcher.searchAfter() method

&gt;

&gt; Hi,

&gt;

&gt;

&gt;

&gt; I have written a customized collector and usually search the index using this

&gt; collector.

&gt;

&gt;

&gt;

&gt; i.e using the below method,

&gt;

&gt;

&gt;

&gt; IndexSearcher.search(Query query, Collector results)

&gt;

&gt;

&gt;

&gt;

&gt;

&gt; But, I cant find any searchAfter() methods in IndexSearcher which accepts a

&gt; Collector input.

&gt;

&gt; Please let me know how to use a customized collector when using

&gt; searchAfter() method.

&gt;

&gt;

&gt;

&gt;

&gt;

&gt; Thanks,

&gt;

&gt; Satyan

&gt;

&gt;

&gt;

 

 

 

---------------------------------------------------------------------

To unsubscribe, e-mail: [hidden email]

For additional commands, e-mail: [hidden email]