Mailing List Archive

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
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@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
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@r.email.ne.jp>´ÔÀÌ ÀÛ¼º:
>
> 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@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>


--
DEV¿ë½Ä
http://devyongsik.tistory.com
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@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Exception when field sort. [ In reply to ]
Thanks It's good for me.

ª¢ªêª¬ªÈª¦. :-)

- Jang

09. 1. 6, Koji Sekiguchi <koji@r.email.ne.jp>´ÔÀÌ ÀÛ¼º:
>
> 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@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>


--
DEV¿ë½Ä
http://devyongsik.tistory.com