lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Todd Nine <>
Subject Help with numeric ranges and querying with sorting and counts
Date Mon, 20 Sep 2010 02:51:20 GMT
Hi all,
  Now that the nasty bug in Cassandra has been fixed, I can use numeric
fields in my Lucandra for searching and sorting.  I'm having a bit of an
issue I could use a hand with.  We're creating an SoS index.  Each
Document corresponds to an SoS.  Every person contacted for the SoS will
be indexed by their email address, their phone numbers, and the time the
SoS was created.  I have an api with the following functionality.

public List<SoS> getAll(String input, long endTime int count) {

Where the string is either a phone number or an email address, the
endTime is the epoch end time to seek up to, and the count is the number
of records to return.  I basically want to perform the following search

(email: input OR phone: input) AND endtime[-LONG.MIN : endTime]

Then return the last "count" values that are closest to the end time.
Here is how I'm creating my document.

	Document doc = new Document();
		DocumentUtils.setRowKey(doc, sos.getId().toString());

		doc.add(new Field(FIELD_IMEI, sos.getImeiNumber(), Store.NO,

		doc.add(new Field(FIELD_TRACKIDX, getHex(sos.getTrackIndexTime()),
				Store.NO, Index.NOT_ANALYZED));

		doc.add(new Field(FIELD_TIER, getHex(sos.getTier().getStoredValue()),
				Store.NO, Index.NOT_ANALYZED));

		doc.add(new NumericField(FIELD_CREATETIME).setLongValue(sos

		doc.add(new Field(FIELD_RESOLVED, getHex(sos.isResolved()), Store.NO,

		if (sos.getNotes() != null) {
			doc.add(new Field(FIELD_NOTES, sos.getNotes(), Store.NO,

		if (sos.isResolved()) {
			doc.add(new NumericField(FIELD_RESOLVETIME).setLongValue(sos

		for (ContactedPerson person : sos.getContactedPeople()) {

			doc.add(new Field(FIELD_EMAIL, person.getEmail(), Store.NO,

			for (Phone phone : person.getPhones()) {
				doc.add(new Field(FIELD_PHONE, getNumericString(phone
						.getNumber()), Store.NO, Index.NOT_ANALYZED));


Here is how I'm creating my query.

		BooleanQuery query = new BooleanQuery();
		BooleanQuery inputTerms = new BooleanQuery();
		inputTerms.add(new TermQuery(new Term(FIELD_EMAIL, input)),
				new TermQuery(new Term(FIELD_PHONE, getNumericString(input))),
		query.add(inputTerms, Occur.MUST);
		NumericRangeQuery time = NumericRangeQuery.newLongRange(
				FIELD_CREATETIME, null, endTime, true, true);

		query.add(time, BooleanClause.Occur.MUST);

     And my sorter

	SortField sort = new SortField(FIELD_CREATETIME, SortField.LONG,true);

Finally here is some sample test data.

SOS 1: createdTime = 1284093337200L
SOS 2: createdTime = 1284093337200L + 10000;
SOS 3: createdTime = 1284093337200L + 20000;

My search criteria is the following

input = "" (each record has this email address on it)
time = SOS 3 created time.

I expect to get 3 records, but instead I'm only getting 1.  It's
something specific to this query, as I have similar queries that work
properly for the numeric range and sorting.  Any ideas what is wrong
with my query?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message