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 Allan Dewar <Al...@bipsolutions.com> on 2006/01/23 16:47:16 UTC

Selecting the maxium/highest numerical value from a lucene Index)

Hi

A database is used as our primary data store.  Our lucene index is then
created and updated from this database.

We store the value of the database primary key in the lucene index as we
need to be able to identify documents across the database and lucene
index.

New documents are inserted into the database on a daily basis and this
is not necessarily a batch process.

What is the easist way to identify the maximum or highest primary key
value in the lucene index?

(The database equivalent of SELECT MAX(id) FROM CONTRACTS)

I would then be able to add documents to the lucene index from the
database whose primary key is greater than the highest primary key value
already in the index.

SELECT * FROM contracts WHERE id > maximumIdInLuceneIndex

Is there a standard approach to achieve this?

Aldo


****************************************************************************
This e-mail (and any attachment) is intended only for the attention of the addressee(s). Its unauthorised use, disclosure, storage or copying is not permitted. If you are not the intended recipient, please destroy all copies and inform the sender by return e-mail.
This e-mail (whether you are the sender or the recipient) may be monitored, recorded and retained by BiP Solutions Ltd. 
E-mail monitoring/ blocking software may be used, and e-mail content may be read at any time.You have a responsibility to ensure laws are not broken when composing or forwarding e-mails and their contents.
****************************************************************************

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


Re: Selecting the maxium/highest numerical value from a lucene Index)

Posted by Yonik Seeley <ys...@gmail.com>.
On 1/23/06, Chris Hostetter <ho...@fucit.org> wrote:
> use a TermEnum to iterate over all the values of the field, remembering
> the "previous" value each time untill you run out of values

Bummer that you can't step backwards with a TermEnum... finding the
first term is cheap, but finding the last is expensive.

How feasible would it be to add a prev() to TermEnum?  Would it be
worth it?  It seems like it would be useful for numeric fields to be
able to quickly find the max as well as the min without filling the
fieldcache.

-Yonik

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


Re: Selecting the maxium/highest numerical value from a lucene Index)

Posted by Chris Hostetter <ho...@fucit.org>.
: What is the easist way to identify the maximum or highest primary key
: value in the lucene index?

The most straight forward way is to do a search for all documents, ordered
by the field you are interested in, and then get the value out of hte
first document.

Under the covers, sorting works using the FieldCache -- a more efficient
way to do what you want then searching would be to use the FieldCache
for your ID field directly, and get the largest value out of the array.

If you don't want to have a giant array of all the ids in memory, you can
use a TermEnum to iterate over all the values of the field, remembering
the "previous" value each time untill you run out of values -- and now
your "previous" value is the highest.



-Hoss


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


RE: Selecting the maxium/highest numerical value from a lucene Index)

Posted by Gwyn Carwardine <gw...@carwardine.net>.
I'm only a novice at these things but if I had to do that right now? I'd add
a document that represents that primary key with a value representing the
next available number and everytime I go to do some additions I'd get it,
use the value and then delete and re-add that document with the revised next
available number. As only one index writer can be open at a time it would
seem a reasonable solution.

-Gwyn 

-----Original Message-----
From: Allan Dewar [mailto:Allan.Dewar@bipsolutions.com] 
Sent: 23 January 2006 15:47
To: java-user@lucene.apache.org
Subject: Selecting the maxium/highest numerical value from a lucene Index)

Hi

A database is used as our primary data store.  Our lucene index is then
created and updated from this database.

We store the value of the database primary key in the lucene index as we
need to be able to identify documents across the database and lucene
index.

New documents are inserted into the database on a daily basis and this
is not necessarily a batch process.

What is the easist way to identify the maximum or highest primary key
value in the lucene index?

(The database equivalent of SELECT MAX(id) FROM CONTRACTS)

I would then be able to add documents to the lucene index from the
database whose primary key is greater than the highest primary key value
already in the index.

SELECT * FROM contracts WHERE id > maximumIdInLuceneIndex

Is there a standard approach to achieve this?

Aldo


****************************************************************************
This e-mail (and any attachment) is intended only for the attention of the
addressee(s). Its unauthorised use, disclosure, storage or copying is not
permitted. If you are not the intended recipient, please destroy all copies
and inform the sender by return e-mail.
This e-mail (whether you are the sender or the recipient) may be monitored,
recorded and retained by BiP Solutions Ltd. 
E-mail monitoring/ blocking software may be used, and e-mail content may be
read at any time.You have a responsibility to ensure laws are not broken
when composing or forwarding e-mails and their contents.
****************************************************************************

---------------------------------------------------------------------
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