You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@lucene.apache.org by johnbesel <jo...@web.de> on 2013/01/19 10:54:39 UTC

Indexer search with filter and sort

Hello together,

I work since 2 weeks with lucene and developed an application which put some
values into index and get it from it.

it works very good.

now I want to sort values, which I put into index.
I used a SortField to sort values:
new SortField(sortKey, SortField.STRING, SortDirection.DESC);

It didn't work. 
I found in internet that when I want to use a SortField with type String, I
should build Index with Index.NOT_ANALYZED.
(http://blog.richeton.com/2009/05/12/lucene-sort-tips/)

I tested it, so now I could sort my values correct, BUT I could not search
for them :(

How can I search and sort String values ????

thank you for your help.

P.S.
I use StandardAnalyzer and Lucene 3.6.
I put values into index
doc.add(new Field(KEY_CUSTOMER_NUMBER, customer.getKunnr() != null ?
customer.getKunnr() : "", Store.YES, Index.ANALYZED));




--
View this message in context: http://lucene.472066.n3.nabble.com/Indexer-search-with-filter-and-sort-tp4034733.html
Sent from the Lucene - General mailing list archive at Nabble.com.

RE: Indexer search with filter and sort

Posted by Uwe Schindler <uw...@thetaphi.de>.
You have to index the field 2 times with different names. One time for search (analyzed) and one time for sorting (not analyzed).

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: johnbesel [mailto:johnbesel@web.de]
> Sent: Saturday, January 19, 2013 10:55 AM
> To: general@lucene.apache.org
> Subject: Indexer search with filter and sort
> 
> Hello together,
> 
> I work since 2 weeks with lucene and developed an application which put
> some values into index and get it from it.
> 
> it works very good.
> 
> now I want to sort values, which I put into index.
> I used a SortField to sort values:
> new SortField(sortKey, SortField.STRING, SortDirection.DESC);
> 
> It didn't work.
> I found in internet that when I want to use a SortField with type String, I
> should build Index with Index.NOT_ANALYZED.
> (http://blog.richeton.com/2009/05/12/lucene-sort-tips/)
> 
> I tested it, so now I could sort my values correct, BUT I could not search for
> them :(
> 
> How can I search and sort String values ????
> 
> thank you for your help.
> 
> P.S.
> I use StandardAnalyzer and Lucene 3.6.
> I put values into index
> doc.add(new Field(KEY_CUSTOMER_NUMBER, customer.getKunnr() != null ?
> customer.getKunnr() : "", Store.YES, Index.ANALYZED));
> 
> 
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Indexer-
> search-with-filter-and-sort-tp4034733.html
> Sent from the Lucene - General mailing list archive at Nabble.com.


RE: Indexer search with filter and sort

Posted by Uwe Schindler <uw...@thetaphi.de>.
This is because you tokenized/analyzed the field. It is sorted against the lowest term in the field ("sundheimer" is the largest value of all terms, so sorted first). This is why you cannot tokenize/analyze fields to sort against.

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: johnbesel [mailto:johnbesel@web.de]
> Sent: Monday, January 21, 2013 2:29 PM
> To: general@lucene.apache.org
> Subject: Re: Indexer search with filter and sort
> 
> I made  a Junit Test with some values. I sort values DESC and get following:
> 
> im sundheimer fort 1-9
> krammwinkel/surkampstr.78
> sundweg
> bray-sur-seine-str. 1
> bray-sur-seine-str. 1
> berck-sur-mer-str. 1
> 
> 
> this is not DESC, but also not ASC. what is this????
> SortField field=new SortField(sortKey, SortField.STRING, true);
> List<SortField> luceneSortFields = new ArrayList<SortField>();
> luceneSortFields.add(field);
> 
> Sort sort = new Sort(luceneSortFields.toArray(new
> SortField[luceneSortFields.size()]));
> topDocs = indexSearcher.search(booleanQuery, Integer.MAX_VALUE, sort);
> 
> has anybody any Idea??
> what is wrong in my implementation?
> 
> 
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Indexer-
> search-with-filter-and-sort-tp4034733p4035047.html
> Sent from the Lucene - General mailing list archive at Nabble.com.


Re: Indexer search with filter and sort

Posted by johnbesel <jo...@web.de>.
I made  a Junit Test with some values. I sort values DESC and get following:

im sundheimer fort 1-9
krammwinkel/surkampstr.78
sundweg
bray-sur-seine-str. 1
bray-sur-seine-str. 1
berck-sur-mer-str. 1


this is not DESC, but also not ASC. what is this????
SortField field=new SortField(sortKey, SortField.STRING, true);
List<SortField> luceneSortFields = new ArrayList<SortField>();
luceneSortFields.add(field);

Sort sort = new Sort(luceneSortFields.toArray(new
SortField[luceneSortFields.size()]));
topDocs = indexSearcher.search(booleanQuery, Integer.MAX_VALUE, sort);

has anybody any Idea??
what is wrong in my implementation?




--
View this message in context: http://lucene.472066.n3.nabble.com/Indexer-search-with-filter-and-sort-tp4034733p4035047.html
Sent from the Lucene - General mailing list archive at Nabble.com.