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 장용석 <ne...@gmail.com> on 2009/01/06 02:10:55 UTC

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.

Posted by 장용석 <ne...@gmail.com>.
Thanks It's good for me.

ありがとう. :-)

- Jang

09. 1. 6, Koji Sekiguchi <ko...@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

Re: Exception when field sort.

Posted by Koji Sekiguchi <ko...@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


Re: Exception when field sort.

Posted by 장용석 <ne...@gmail.com>.
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 <ko...@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.

Posted by Koji Sekiguchi <ko...@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