Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Lucene: Java-User

Exception when field sort.

 

 

Lucene java-user RSS feed   Index | Next | Previous | View Threaded


need4spd at gmail

Jan 5, 2009, 5:10 PM

Post #1 of 5 (4094 views)
Permalink
Exception when field sort.

Hi.

I want to test sorting when search so I was created simple index like this.

String[] samples = {"duck dog","first dog","grammar dog","come dog","basic
dog","intro dog","lipton dog","search dog","servlet dog","jan dog"};
Directory dir = FSDirectory.getDirectory(path);
IndexWriter writer = new IndexWriter(dir,new GSKoreanAnalyzer(true),true);
Document document = null;

for(int i = 0; i < samples.length; i++) {
document = new Document();
Field field = new
Field("name",samples[i],Field.Store.YES,Field.Index.ANALYZED,Field.TermVector.WITH_POSITIONS_OFFSETS);
document.add(field);

writer.addDocument(document);
}
writer.optimize();
writer.close();
and I did create sample code (use Sort and TopFieldDocs).

but It didn't work and throw Exception "there are more terms than documents
in field "name", but it's impossible to sort on tokenized fields"

What is this mean? I was searched about this issue in google and lucene
java-wiki but I can't find.

Is my code is wrong?

If I had mistake, point to me please.

Thanks.

- Jang.
--
DEV용식
http://devyongsik.tistory.com


koji at r

Jan 5, 2009, 5:54 PM

Post #2 of 5 (3997 views)
Permalink
Re: Exception when field sort. [In reply to]

See Sort class javadoc:
http://hudson.zones.apache.org/hudson/job/Lucene-trunk/javadoc/org/apache/lucene/search/Sort.html

It says:

The fields used to determine sort order must be carefully chosen.
Documents must contain a single term in such a field, and the value of
the term should indicate the document's relative position in a given
sort order. The field must be indexed, but should not be tokenized, and
does not need to be stored (unless you happen to want it back with the
rest of your document data). In other words:

document.add (new Field ("byNumber", Integer.toString(x),
Field.Store.NO, Field.Index.NOT_ANALYZED));

Koji

장용석 wrote:
> Hi.
>
> I want to test sorting when search so I was created simple index like this.
>
> String[] samples = {"duck dog","first dog","grammar dog","come dog","basic
> dog","intro dog","lipton dog","search dog","servlet dog","jan dog"};
> Directory dir = FSDirectory.getDirectory(path);
> IndexWriter writer = new IndexWriter(dir,new GSKoreanAnalyzer(true),true);
> Document document = null;
>
> for(int i = 0; i < samples.length; i++) {
> document = new Document();
> Field field = new
> Field("name",samples[i],Field.Store.YES,Field.Index.ANALYZED,Field.TermVector.WITH_POSITIONS_OFFSETS);
> document.add(field);
>
> writer.addDocument(document);
> }
> writer.optimize();
> writer.close();
> and I did create sample code (use Sort and TopFieldDocs).
>
> but It didn't work and throw Exception "there are more terms than documents
> in field "name", but it's impossible to sort on tokenized fields"
>
> What is this mean? I was searched about this issue in google and lucene
> java-wiki but I can't find.
>
> Is my code is wrong?
>
> If I had mistake, point to me please.
>
> Thanks.
>
> - Jang.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


need4spd at gmail

Jan 5, 2009, 6:09 PM

Post #3 of 5 (4010 views)
Permalink
Re: Exception when field sort. [In reply to]

Thanks for your advice.

If I want to sort some field (for example name is "TITLE") and It must be
Analyzed.

Then Do I have to make two field that one is ANALYZED and the other is
NOT_ANALYZED like this?

document.add(new Field("TITLE", value, Field.Store.NO. Field.Index.ANALYZED)
document.add(new Field("TITLE_FOR_SORT", value, Field.Store.NO,
Field.Index.NOT_ANALYZED)

- Jang.


09. 1. 6, Koji Sekiguchi <koji [at] r>님이 작성:
>
> See Sort class javadoc:
>
> http://hudson.zones.apache.org/hudson/job/Lucene-trunk/javadoc/org/apache/lucene/search/Sort.html
>
> It says:
>
> The fields used to determine sort order must be carefully chosen.
> Documents must contain a single term in such a field, and the value of
> the term should indicate the document's relative position in a given
> sort order. The field must be indexed, but should not be tokenized, and
> does not need to be stored (unless you happen to want it back with the
> rest of your document data). In other words:
>
> document.add (new Field ("byNumber", Integer.toString(x),
> Field.Store.NO, Field.Index.NOT_ANALYZED));
>
> Koji
>
> 장용석 wrote:
> > Hi.
> >
> > I want to test sorting when search so I was created simple index like
> this.
> >
> > String[] samples = {"duck dog","first dog","grammar dog","come
> dog","basic
> > dog","intro dog","lipton dog","search dog","servlet dog","jan dog"};
> > Directory dir = FSDirectory.getDirectory(path);
> > IndexWriter writer = new IndexWriter(dir,new
> GSKoreanAnalyzer(true),true);
> > Document document = null;
> >
> > for(int i = 0; i < samples.length; i++) {
> > document = new Document();
> > Field field = new
> >
> Field("name",samples[i],Field.Store.YES,Field.Index.ANALYZED,Field.TermVector.WITH_POSITIONS_OFFSETS);
> > document.add(field);
> >
> > writer.addDocument(document);
> > }
> > writer.optimize();
> > writer.close();
> > and I did create sample code (use Sort and TopFieldDocs).
> >
> > but It didn't work and throw Exception "there are more terms than
> documents
> > in field "name", but it's impossible to sort on tokenized fields"
> >
> > What is this mean? I was searched about this issue in google and lucene
> > java-wiki but I can't find.
> >
> > Is my code is wrong?
> >
> > If I had mistake, point to me please.
> >
> > Thanks.
> >
> > - Jang.
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
> For additional commands, e-mail: java-user-help [at] lucene
>
>


--
DEV용식
http://devyongsik.tistory.com


koji at r

Jan 5, 2009, 6:18 PM

Post #4 of 5 (4007 views)
Permalink
Re: Exception when field sort. [In reply to]

That's correct!

Koji


장용석 wrote:
> Thanks for your advice.
>
> If I want to sort some field (for example name is "TITLE") and It must be
> Analyzed.
>
> Then Do I have to make two field that one is ANALYZED and the other is
> NOT_ANALYZED like this?
>
> document.add(new Field("TITLE", value, Field.Store.NO. Field.Index.ANALYZED)
> document.add(new Field("TITLE_FOR_SORT", value, Field.Store.NO,
> Field.Index.NOT_ANALYZED)
>
> - Jang.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


need4spd at gmail

Jan 5, 2009, 6:32 PM

Post #5 of 5 (4002 views)
Permalink
Re: Exception when field sort. [In reply to]

Thanks It's good for me.

ありがとう. :-)

- Jang

09. 1. 6, Koji Sekiguchi <koji [at] r>님이 작성:
>
> That's correct!
>
> Koji
>
>
> 장용석 wrote:
> > Thanks for your advice.
> >
> > If I want to sort some field (for example name is "TITLE") and It must be
> > Analyzed.
> >
> > Then Do I have to make two field that one is ANALYZED and the other is
> > NOT_ANALYZED like this?
> >
> > document.add(new Field("TITLE", value, Field.Store.NO.
> Field.Index.ANALYZED)
> > document.add(new Field("TITLE_FOR_SORT", value, Field.Store.NO,
> > Field.Index.NOT_ANALYZED)
> >
> > - Jang.
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
> For additional commands, e-mail: java-user-help [at] lucene
>
>


--
DEV용식
http://devyongsik.tistory.com

Lucene java-user RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.