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 = evtHour evtHour
= 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 u...@thetaphi.de
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: u...@thetaphi.de
-Original Message-
From: Chellasamy G chellasam...@zohocorp.com
Sent: Friday, May 18, 2018 8:00 PM
To: java-user java-user@lucene.apache.org
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: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org