You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Kevin Osborn <os...@yahoo.com> on 2008/07/02 23:39:07 UTC
Fetching float or int fields from index by Lucene document
As part of my results, I am building a lot of facet information. For example, an Attribute ID also needs to return the Attribute Text.
So, I have code like the following (really in a cache):
Term term = new Term ("AtrID", "A0001");
Document doc = searcher.doc(searcher.getFirstMatch(term));
return doc.get("AtrText");
This works great for string fields. But, if I am looking at a field that is non-string in Document.get(), I get strange characters. I also notice if I just print out doc.toString(). Most fields look fine, but int or float fields are all messed up. I assume this is because the Lucene index really is just text, so Solr must do some sort of encoding here.
Is there anyway to decode the string into something readable?
Re: Fetching float or int fields from index by Lucene document
Posted by Yonik Seeley <yo...@apache.org>.
On Wed, Jul 2, 2008 at 10:45 PM, Chris Hostetter
<ho...@fucit.org> wrote:
> It never really occured to me before, but it is kind of weird that there
> is a toInternal and a toExternal and an indexedToReadable -- but there is
> no readableToIndexed ... toInternal is used both for the "indexed" value
> and for the "stored" value, so things like SortableIntField wind up
> "storing" an encoded value even though there isn't much need for it.
Legacy stuff in a way. In the beginning there was only toInternal()
and toExternal(). I added indexedToReadable(), storedToReadable(),
storedToIndexed() later for more completeness. I think I didn't add a
readableToIndexed() since that was really what toInternal() was.
Really, the stored field could be a normal readable value - no reason
it has to match the indexed value.
I made them the same as an optimization to bypass the analyzer since
there was no way to just give the token directly to the IndexWriter
(worth it? I don't know...)
-Yonik
Re: Fetching float or int fields from index by Lucene document
Posted by Chris Hostetter <ho...@fucit.org>.
: See the methods on FieldType, esp toExternal()
It never really occured to me before, but it is kind of weird that there
is a toInternal and a toExternal and an indexedToReadable -- but there is
no readableToIndexed ... toInternal is used both for the "indexed" value
and for the "stored" value, so things like SortableIntField wind up
"storing" an encoded value even though there isn't much need for it.
In theory, indexing an "sint" field unstored and storing a corrisponding
"integer" field unindex might actaully be faster then a single field since
the toExternal method is a NOOP.
-Hoss
Re: Fetching float or int fields from index by Lucene document
Posted by Yonik Seeley <yo...@apache.org>.
See the methods on FieldType, esp toExternal()
-Yonik
On Wed, Jul 2, 2008 at 5:39 PM, Kevin Osborn <os...@yahoo.com> wrote:
> As part of my results, I am building a lot of facet information. For example, an Attribute ID also needs to return the Attribute Text.
>
> So, I have code like the following (really in a cache):
>
> Term term = new Term ("AtrID", "A0001");
> Document doc = searcher.doc(searcher.getFirstMatch(term));
>
> return doc.get("AtrText");
>
> This works great for string fields. But, if I am looking at a field that is non-string in Document.get(), I get strange characters. I also notice if I just print out doc.toString(). Most fields look fine, but int or float fields are all messed up. I assume this is because the Lucene index really is just text, so Solr must do some sort of encoding here.
>
> Is there anyway to decode the string into something readable?