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 Michael McCandless <lu...@mikemccandless.com> on 2007/10/07 13:47:53 UTC
Re: norms(String field, byte[] bytes, int offset)
I think the intention of that method is to load all norms for that reader
into the byte array, so I think it's reasonable that an exception is
thrown if you provide a byte array that's too small.
Though maybe it would be friendlier to throw an IllegalArgumentException
that says "the byte array is not long enough"?
Mike
"Karl Wettin" <ka...@gmail.com> wrote:
> I'm confused by this method. Why is the length set to maxDoc() and
> not bytes.length? This means that the following snippet will throw an
> ArrayIndexOutOfBoundsException in most cases:
>
> byte[] b = new byte[1];
> ir.norms(field, b, doc);
>
>
> > /** Read norms into a pre-allocated array. */
> > public synchronized void norms(String field, byte[] bytes, int
> > offset)
> > throws IOException {
> >
> > ensureOpen();
> > Norm norm = (Norm) norms.get(field);
> > if (norm == null) {
> > System.arraycopy(fakeNorms(), 0, bytes, offset, maxDoc());
> > return;
> > }
> >
> > if (norm.bytes != null) { // can copy from
> > cache
> > System.arraycopy(norm.bytes, 0, bytes, offset, maxDoc());
> > return;
> > }
> >
> > // Read from disk. norm.in may be shared across multiple
> > norms and
> > // should only be used in a synchronized context.
> > norm.in.seek(norm.normSeek);
> > norm.in.readBytes(bytes, offset, maxDoc());
> > }
>
> --
> karl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: norms(String field, byte[] bytes, int offset)
Posted by Yonik Seeley <yo...@apache.org>.
On 10/7/07, Michael McCandless <lu...@mikemccandless.com> wrote:
> Actually, MultiReader & MultiSegmentReader make use of this method, to
> load all norms from each sub-reader into a single byte array.
Right. Karl, see MultiSegmentReader.norms(String field)
for how this method is used. You want to be able to read all of the
norms of a sub-reader into the middle of an existing byte[] that is
passed.
-Yonik
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: norms(String field, byte[] bytes, int offset)
Posted by Karl Wettin <ka...@gmail.com>.
7 okt 2007 kl. 19.26 skrev Michael McCandless:
> I guess we could change the code to only load up until the end of
> the byte array that's passed in, but, that weakens the error checking?
> Ie if the intent is to "load all norms", it's nice to catch the error
> (that you passed in a too-small byte array) earlier rather than later.
If it was me that wrote that code, I'd have MultiWhatNot to validate and
throw the exception, if possible. But that's just me.
> Or maybe we could add a new method whose purpose is to load a subset
> of the norms? Is there are particular use case behind this?
There is no use-case. I noticed this as a discrepancy between LUCENE-550
and the SegmentImplementation, and simply wondered why.
--
karl
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: norms(String field, byte[] bytes, int offset)
Posted by Michael McCandless <lu...@mikemccandless.com>.
Actually, MultiReader & MultiSegmentReader make use of this method, to
load all norms from each sub-reader into a single byte array.
I guess we could change the code to only load up until the end of
the byte array that's passed in, but, that weakens the error checking?
Ie if the intent is to "load all norms", it's nice to catch the error
(that you passed in a too-small byte array) earlier rather than later.
Or maybe we could add a new method whose purpose is to load a subset
of the norms? Is there are particular use case behind this?
Mike
"Karl Wettin" <karl.wettin@gmail.com wrote:
> 7 okt 2007 kl. 13.47 skrev Michael McCandless:
>
> >
> > I think the intention of that method is to load all norms for that
> > reader
> > into the byte array, so I think it's reasonable that an exception is
> > thrown if you provide a byte array that's too small.
>
> Hmm, OK.
>
> But I don't understand why there is such a limit, and what could go
> wrong if one would start allowing smaller arrays?
>
> Nor can I find any use of this method in the trunk, except for in a
> test case.
>
> --
> karl
>
>
>
>
> >
> > Though maybe it would be friendlier to throw an
> > IllegalArgumentException
> > that says "the byte array is not long enough"?
> >
> > Mike
> >
> > "Karl Wettin" <ka...@gmail.com> wrote:
> >> I'm confused by this method. Why is the length set to maxDoc() and
> >> not bytes.length? This means that the following snippet will throw an
> >> ArrayIndexOutOfBoundsException in most cases:
> >>
> >> byte[] b = new byte[1];
> >> ir.norms(field, b, doc);
> >>
> >>
> >>> /** Read norms into a pre-allocated array. */
> >>> public synchronized void norms(String field, byte[] bytes, int
> >>> offset)
> >>> throws IOException {
> >>>
> >>> ensureOpen();
> >>> Norm norm = (Norm) norms.get(field);
> >>> if (norm == null) {
> >>> System.arraycopy(fakeNorms(), 0, bytes, offset, maxDoc());
> >>> return;
> >>> }
> >>>
> >>> if (norm.bytes != null) { // can copy from
> >>> cache
> >>> System.arraycopy(norm.bytes, 0, bytes, offset, maxDoc());
> >>> return;
> >>> }
> >>>
> >>> // Read from disk. norm.in may be shared across multiple
> >>> norms and
> >>> // should only be used in a synchronized context.
> >>> norm.in.seek(norm.normSeek);
> >>> norm.in.readBytes(bytes, offset, maxDoc());
> >>> }
> >>
> >> --
> >> karl
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> >> For additional commands, e-mail: java-user-help@lucene.apache.org
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: norms(String field, byte[] bytes, int offset)
Posted by Karl Wettin <ka...@gmail.com>.
7 okt 2007 kl. 13.47 skrev Michael McCandless:
>
> I think the intention of that method is to load all norms for that
> reader
> into the byte array, so I think it's reasonable that an exception is
> thrown if you provide a byte array that's too small.
Hmm, OK.
But I don't understand why there is such a limit, and what could go
wrong if one would start allowing smaller arrays?
Nor can I find any use of this method in the trunk, except for in a
test case.
--
karl
>
> Though maybe it would be friendlier to throw an
> IllegalArgumentException
> that says "the byte array is not long enough"?
>
> Mike
>
> "Karl Wettin" <ka...@gmail.com> wrote:
>> I'm confused by this method. Why is the length set to maxDoc() and
>> not bytes.length? This means that the following snippet will throw an
>> ArrayIndexOutOfBoundsException in most cases:
>>
>> byte[] b = new byte[1];
>> ir.norms(field, b, doc);
>>
>>
>>> /** Read norms into a pre-allocated array. */
>>> public synchronized void norms(String field, byte[] bytes, int
>>> offset)
>>> throws IOException {
>>>
>>> ensureOpen();
>>> Norm norm = (Norm) norms.get(field);
>>> if (norm == null) {
>>> System.arraycopy(fakeNorms(), 0, bytes, offset, maxDoc());
>>> return;
>>> }
>>>
>>> if (norm.bytes != null) { // can copy from
>>> cache
>>> System.arraycopy(norm.bytes, 0, bytes, offset, maxDoc());
>>> return;
>>> }
>>>
>>> // Read from disk. norm.in may be shared across multiple
>>> norms and
>>> // should only be used in a synchronized context.
>>> norm.in.seek(norm.normSeek);
>>> norm.in.readBytes(bytes, offset, maxDoc());
>>> }
>>
>> --
>> karl
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org