You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Björn Ekengren <bj...@avanza.se> on 2006/09/18 11:34:12 UTC
Sorting on date in a frequently updated index
I'm experiencing problems getting sort to work correctly The result is not completely out of order, but it is certainly not correct. I have an index with the following fields:
id stored, un_tokenized
header stored, tokenized
body stored, tokenized
keywords stored, tokenized
date stored, un_tokenized
The index is updated a couple of times per minute like this (pseudocode):
update(String id){
indexreader.delete(id)
indexreader.close();
indexwriter.addDocument(getDocFromDB(id));
indexwriter.close();
indexreader = new IndexSearcher(myIndexDir);
}
String[] fields = new String[]{"header","body","keywords"}
QueryParser queryParser = new MultiFieldQueryParser(fields.toArray(new String[]{}), new SnowballAnalyzer("Swedish",MyIndexer.SWEDISH_STOP_WORDS)){
@Override
protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
return new ConstantScoreRangeQuery(field,part1, part2, inclusive, inclusive);
}
};
Query query = searcher.getQueryParser().parse(queryString);
IndexSearcher searcher = new IndexSearcher(directory);
Sort sorter = new Sort("date",true);
Hits hits = searcher.search(query,sorter);
The result, with date printed first(yyyyMMddhhmm):
200609151255 EUROPABÖRSER: GRUVOR FÖRLORARE I VÄNTAN PÅ KPI 338388
200609151255 EUROPABÖRSER: GRUVOR FÖRLORARE I VÄNTAN PÅ KPI 338389
200609151319 BÖRSEN: AVVAKTANDE INFÖR VAL OCH STATISTIK, OMXS30 -0,2% 338412
200609151319 BÖRSEN: AVVAKTANDE INFÖR VAL OCH STATISTIK, OMXS30 -0,2% 338413
200609151802 BÖRSEN: BLANDAD UTVECKLING, BANKERNA FÖRLORARE, OMXS30 -0,2% 338801
200609151802 BÖRSEN: BLANDAD UTVECKLING, BANKERNA FÖRLORARE, OMXS30 -0,2% 338802
200609131009 BÖRSEN: SCANIA, BOLIDEN OCH VOLVO I FOKUS, OMXS30 +0,7% 337857
200609131315 DJ MARKET TALK: Boliden Not A Perfect Takeover Target 337936
200609130652 SVENSKA BOLAGS KONKURRENTER I USA KLOCKAN 06:51 337777
200609130705 BOLIDEN: BHP ANTAGLIGEN EJ INTRESSERAD AV FÖRVÄRV - DAIWA 337780
200609131251 BÖRSEN: SCANIA UPP, BOLIDEN NED I BUDDJUNGELN, OMSX30 +0,7% 337930
200609130759 PM NYHETER I KORTHET ONSDAG 13 SEPTEMBER 337792
200609130837 BÖRSEN: STÖD FRÅN USA, AFFÄRER I FORTSATT FOKUS 337815
200609130959 ***BOLIDEN: HAR EJ KONTAKTATS AV BHP BILLITON 337846
200609131000 ***BOLIDEN: HAR EJ KONTAKTATS AV NÅGOT BOLAG 337849
200609131002 BOLIDEN: HAR EJ KONTAKTATS AV BHP EL NÅGOT ANNAT BOLAG ENL VD 337850
200609121645 BOLIDEN: BHP BILLITON VILL INTE KOMMENTERA RYKTEN 337729
200609122204 SVENSKA BOLAGS KONKURRENTER I USA KLOCKAN 22:03 337760
200609121800 BÖRSEN:BUDRYKTEN KRING SCANIA OCH BOLIDEN GAV LYFT,OMXS30 +1,9 337735
200609121843 SCANIA: NÄSTA INFORMATION KOMMER FRÅN EXTERN PART - OMX 337746
200609121555 RYKTE OM BUD DRIVER KURSEN <NY> Boliden 337723
200604071233 BÖRSEN: LUGN HANDEL I VÄNTAN PÅ JOBBSIFFROR, OMXS +1,0% 337224
200604071005 BÖRSEN: UPP I VÄNTAN PÅ AMERIKANSKA SIFFROR, OMXS +0,3% 337165
200604071256 Boliden: Kallelse till Bolidens årsstämma Boliden 337235
200604051359 BÖRSEN: HÖG AKTIVITET MED VISST FOKUS PÅ METALLER, OMXS +0,1% 335868
As seen above the year, month and day is sorted correctly, but hour and minute appears to be sorted at random. How come ??
/B
Re: Sorting on date in a frequently updated index
Posted by Chris Hostetter <ho...@fucit.org>.
i suspect this has everything to do with the specifics of how you are
adding the date field to the Documents before you index them ... are you
using DateTools? what Resolution are you specifying?
keep in mind that the "stored" date value you see isn't neccessarily the
exact same thing as the "indexed" date value that is being sorted on.
: Date: Mon, 18 Sep 2006 11:34:12 +0200
: From: Björn Ekengren <bj...@avanza.se>
: Reply-To: java-user@lucene.apache.org
: To: java-user@lucene.apache.org
: Subject: Sorting on date in a frequently updated index
:
: I'm experiencing problems getting sort to work correctly The result is not completely out of order, but it is certainly not correct. I have an index with the following fields:
: id stored, un_tokenized
: header stored, tokenized
: body stored, tokenized
: keywords stored, tokenized
: date stored, un_tokenized
:
: The index is updated a couple of times per minute like this (pseudocode):
: update(String id){
: indexreader.delete(id)
: indexreader.close();
: indexwriter.addDocument(getDocFromDB(id));
: indexwriter.close();
: indexreader = new IndexSearcher(myIndexDir);
: }
: String[] fields = new String[]{"header","body","keywords"}
: QueryParser queryParser = new MultiFieldQueryParser(fields.toArray(new String[]{}), new SnowballAnalyzer("Swedish",MyIndexer.SWEDISH_STOP_WORDS)){
: @Override
: protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
: return new ConstantScoreRangeQuery(field,part1, part2, inclusive, inclusive);
: }
: };
: Query query = searcher.getQueryParser().parse(queryString);
: IndexSearcher searcher = new IndexSearcher(directory);
: Sort sorter = new Sort("date",true);
: Hits hits = searcher.search(query,sorter);
:
: The result, with date printed first(yyyyMMddhhmm):
:
: 200609151255 EUROPABÖRSER: GRUVOR FÖRLORARE I VÄNTAN PÅ KPI 338388
: 200609151255 EUROPABÖRSER: GRUVOR FÖRLORARE I VÄNTAN PÅ KPI 338389
: 200609151319 BÖRSEN: AVVAKTANDE INFÖR VAL OCH STATISTIK, OMXS30 -0,2% 338412
: 200609151319 BÖRSEN: AVVAKTANDE INFÖR VAL OCH STATISTIK, OMXS30 -0,2% 338413
: 200609151802 BÖRSEN: BLANDAD UTVECKLING, BANKERNA FÖRLORARE, OMXS30 -0,2% 338801
: 200609151802 BÖRSEN: BLANDAD UTVECKLING, BANKERNA FÖRLORARE, OMXS30 -0,2% 338802
: 200609131009 BÖRSEN: SCANIA, BOLIDEN OCH VOLVO I FOKUS, OMXS30 +0,7% 337857
: 200609131315 DJ MARKET TALK: Boliden Not A Perfect Takeover Target 337936
: 200609130652 SVENSKA BOLAGS KONKURRENTER I USA KLOCKAN 06:51 337777
: 200609130705 BOLIDEN: BHP ANTAGLIGEN EJ INTRESSERAD AV FÖRVÄRV - DAIWA 337780
: 200609131251 BÖRSEN: SCANIA UPP, BOLIDEN NED I BUDDJUNGELN, OMSX30 +0,7% 337930
: 200609130759 PM NYHETER I KORTHET ONSDAG 13 SEPTEMBER 337792
: 200609130837 BÖRSEN: STÖD FRÅN USA, AFFÄRER I FORTSATT FOKUS 337815
: 200609130959 ***BOLIDEN: HAR EJ KONTAKTATS AV BHP BILLITON 337846
: 200609131000 ***BOLIDEN: HAR EJ KONTAKTATS AV NÅGOT BOLAG 337849
: 200609131002 BOLIDEN: HAR EJ KONTAKTATS AV BHP EL NÅGOT ANNAT BOLAG ENL VD 337850
: 200609121645 BOLIDEN: BHP BILLITON VILL INTE KOMMENTERA RYKTEN 337729
: 200609122204 SVENSKA BOLAGS KONKURRENTER I USA KLOCKAN 22:03 337760
: 200609121800 BÖRSEN:BUDRYKTEN KRING SCANIA OCH BOLIDEN GAV LYFT,OMXS30 +1,9 337735
: 200609121843 SCANIA: NÄSTA INFORMATION KOMMER FRÅN EXTERN PART - OMX 337746
: 200609121555 RYKTE OM BUD DRIVER KURSEN <NY> Boliden 337723
: 200604071233 BÖRSEN: LUGN HANDEL I VÄNTAN PÅ JOBBSIFFROR, OMXS +1,0% 337224
: 200604071005 BÖRSEN: UPP I VÄNTAN PÅ AMERIKANSKA SIFFROR, OMXS +0,3% 337165
: 200604071256 Boliden: Kallelse till Bolidens årsstämma Boliden 337235
: 200604051359 BÖRSEN: HÖG AKTIVITET MED VISST FOKUS PÅ METALLER, OMXS +0,1% 335868
:
:
: As seen above the year, month and day is sorted correctly, but hour and minute appears to be sorted at random. How come ??
:
: /B
:
:
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org