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 2013/10/07 17:23:34 UTC

Getting integer value from BytesRef

Dear,

I have indexing integer field like this

-----
Document doc = new Document();
FieldType fieldType = new FieldType();
fieldType.setIndexed(true);
fieldType.setStored(true);
fieldType.setTokenized(false);
fieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
fieldType.setStoreTermVectors(true);
fieldType.setNumericType(NumericType.INT);
doc.add(new IntField("contents", 1, fieldType));
-----

and I have tried to get integer value and doc frequency like this

-----
...

BytesRef term = null;
while ((term = termsEnum.next()) != null) {
System.out.println("doc Freq of ["+term.utf8ToString()+"] : " +
termsEnum.docFreq());
-----

But term.utf8toString is return some broken character like this [d@], [l ]
..etc.

How can I get right value from BytesRef?

Thanks and Regards.
-- 
DEV용식
http://devyongsik.tistory.com

Re: Getting integer value from BytesRef

Posted by 장용석 <ne...@gmail.com>.
Thanks very much! Uwe.
I have get right value using NumericUtils.
And as you talk, there were many terms more than I have indexing.

Thanks and Regards.


2013/10/8 Uwe Schindler <uw...@thetaphi.de>

> Hi,
>
> Use NumericUtils to convert the BytesRef back to a number:
> http://goo.gl/3KG9Pd
> But be careful, the terms index contains more terms with lower precisions
> (bits stripped off), unless you use infinite precisionStep!
>
> Uwe
>
> -----
> Uwe Schindler
> H.-H.-Meier-Allee 63, D-28213 Bremen
> http://www.thetaphi.de
> eMail: uwe@thetaphi.de
>
>
> > -----Original Message-----
> > From: 장용석 [mailto:need4spd@gmail.com]
> > Sent: Monday, October 07, 2013 5:24 PM
> > To: java-user@lucene.apache.org
> > Subject: Getting integer value from BytesRef
> >
> > Dear,
> >
> > I have indexing integer field like this
> >
> > -----
> > Document doc = new Document();
> > FieldType fieldType = new FieldType();
> > fieldType.setIndexed(true);
> > fieldType.setStored(true);
> > fieldType.setTokenized(false);
> > fieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIO
> > NS);
> > fieldType.setStoreTermVectors(true);
> > fieldType.setNumericType(NumericType.INT);
> > doc.add(new IntField("contents", 1, fieldType));
> > -----
> >
> > and I have tried to get integer value and doc frequency like this
> >
> > -----
> > ...
> >
> > BytesRef term = null;
> > while ((term = termsEnum.next()) != null) { System.out.println("doc Freq
> of
> > ["+term.utf8ToString()+"] : " + termsEnum.docFreq());
> > -----
> >
> > But term.utf8toString is return some broken character like this [d@],
> [l ] ..etc.
> >
> > How can I get right value from BytesRef?
> >
> > Thanks and Regards.
> > --
> > DEV용식
> > http://devyongsik.tistory.com
>
>
> ---------------------------------------------------------------------
> 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: Getting integer value from BytesRef

Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi,

Use NumericUtils to convert the BytesRef back to a number: http://goo.gl/3KG9Pd
But be careful, the terms index contains more terms with lower precisions (bits stripped off), unless you use infinite precisionStep!

Uwe

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


> -----Original Message-----
> From: 장용석 [mailto:need4spd@gmail.com]
> Sent: Monday, October 07, 2013 5:24 PM
> To: java-user@lucene.apache.org
> Subject: Getting integer value from BytesRef
> 
> Dear,
> 
> I have indexing integer field like this
> 
> -----
> Document doc = new Document();
> FieldType fieldType = new FieldType();
> fieldType.setIndexed(true);
> fieldType.setStored(true);
> fieldType.setTokenized(false);
> fieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIO
> NS);
> fieldType.setStoreTermVectors(true);
> fieldType.setNumericType(NumericType.INT);
> doc.add(new IntField("contents", 1, fieldType));
> -----
> 
> and I have tried to get integer value and doc frequency like this
> 
> -----
> ...
> 
> BytesRef term = null;
> while ((term = termsEnum.next()) != null) { System.out.println("doc Freq of
> ["+term.utf8ToString()+"] : " + termsEnum.docFreq());
> -----
> 
> But term.utf8toString is return some broken character like this [d@], [l ] ..etc.
> 
> How can I get right value from BytesRef?
> 
> Thanks and Regards.
> --
> DEV용식
> http://devyongsik.tistory.com


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Getting integer value from BytesRef

Posted by 장용석 <ne...@gmail.com>.
Peter. Thanks for reply.

This code is just sample for question.
Actually, I have index many documents.

And the reason for try this, I want to get statistics of index file.

Thanks and Regards.



2013/10/8 Peter Chang <pe...@gmail.com>

> Your doc freq is always 1. It's useless.
> I don't know why you try to index and search a binary field except for
> range searching.
>
> On Mon, Oct 7, 2013 at 11:23 PM, 장용석 <ne...@gmail.com> wrote:
>
> > Dear,
> >
> > I have indexing integer field like this
> >
> > -----
> > Document doc = new Document();
> > FieldType fieldType = new FieldType();
> > fieldType.setIndexed(true);
> > fieldType.setStored(true);
> > fieldType.setTokenized(false);
> > fieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
> > fieldType.setStoreTermVectors(true);
> > fieldType.setNumericType(NumericType.INT);
> > doc.add(new IntField("contents", 1, fieldType));
> > -----
> >
> > and I have tried to get integer value and doc frequency like this
> >
> > -----
> > ...
> >
> > BytesRef term = null;
> > while ((term = termsEnum.next()) != null) {
> > System.out.println("doc Freq of ["+term.utf8ToString()+"] : " +
> > termsEnum.docFreq());
> > -----
> >
> > But term.utf8toString is return some broken character like this [d@],
> [l ]
> > ..etc.
> >
> > How can I get right value from BytesRef?
> >
> > Thanks and Regards.
> > --
> > DEV용식
> > http://devyongsik.tistory.com
> >
>



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

Re: Getting integer value from BytesRef

Posted by Peter Chang <pe...@gmail.com>.
Your doc freq is always 1. It's useless.
I don't know why you try to index and search a binary field except for
range searching.

On Mon, Oct 7, 2013 at 11:23 PM, 장용석 <ne...@gmail.com> wrote:

> Dear,
>
> I have indexing integer field like this
>
> -----
> Document doc = new Document();
> FieldType fieldType = new FieldType();
> fieldType.setIndexed(true);
> fieldType.setStored(true);
> fieldType.setTokenized(false);
> fieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
> fieldType.setStoreTermVectors(true);
> fieldType.setNumericType(NumericType.INT);
> doc.add(new IntField("contents", 1, fieldType));
> -----
>
> and I have tried to get integer value and doc frequency like this
>
> -----
> ...
>
> BytesRef term = null;
> while ((term = termsEnum.next()) != null) {
> System.out.println("doc Freq of ["+term.utf8ToString()+"] : " +
> termsEnum.docFreq());
> -----
>
> But term.utf8toString is return some broken character like this [d@], [l ]
> ..etc.
>
> How can I get right value from BytesRef?
>
> Thanks and Regards.
> --
> DEV용식
> http://devyongsik.tistory.com
>