You need to encode the numbers by padding to the left or another method, we do this we know what fields are numerics and extend QueryParser to encode the fields for searching. We also decode the number on display below is the functions we use, the tricky bit is getting negative numbers to work correctly and being able to mix decimals with integers.
Hope this helps Mike www.ardentia.com the home of NetSearch public static String encode(long num) { String hex = Long.toHexString(num < 0 ? Long.MAX_VALUE - (0xffffffffffffffffL ^ num) : num); hex = (num < 0 ? "N" : "P") + "0000000000000000".substring(0, 16 - hex.length()) + hex; return hex; } public static String encode(double num) { double temp = Math.floor(num); if (temp > Long.MAX_VALUE || temp < Long.MIN_VALUE) { return null; } if (temp == num) { return encode(new Double(temp).longValue()); } else if (temp < num) { return encode(new Double(temp).longValue()) + Double.toString(num - temp).substring(1); } return encode(new Double(temp - 1).longValue()) + Double.toString(temp - num).substring(1); } private static long decodeLong(String hex) { long num = Long.parseLong(hex.substring(1, 17), 16); return hex.charAt(0) == 'N' ? (Long.MAX_VALUE - num) ^ 0xffffffffffffffffL : num; } public static double decode(String strnum) { String[] parts = strnum.split("\\."); double left = new Long(decodeLong(parts[0])).doubleValue(); if (parts.length == 1) { return left; } double decimal = Double.parseDouble("0." + parts[1]); return strnum.charAt(0) == 'P' ? left + decimal : (left + 1) - (1 - decimal); } -----Original Message----- From: Shivani Sawhney [mailto:[EMAIL PROTECTED] Sent: 08 February 2006 15:20 To: java-user@lucene.apache.org Subject: Using Range Queries Hi, I am trying to search across some documents and have min and max experience, min and max ctc and email as some of the search fields. I have problem using the Range Query. The problem is as follows. If I am trying to search for documents with exp between 0 to 9, I get 15 hits, assuming that all 15 documents are with exp between 3 and 8, but if I change my range to 0 to 20, I do not get any results. Seems odd to me.anything between 0 to 9 is also between 0 to 20. Now, if I change my range to 0 to 90, I get all 15 records again. I guess is that somehow the code is not taking my range as numerals but is probably doing string compare. The code snipped is listed below. Any help will be much appreciated. Thanks in advance. BooleanQuery documentSearchQuery = new BooleanQuery(); . if (minExperience >= 0 && maxExperience >= 0) { queryExperience = new RangeQuery(new Term(IndexerColumns.experience, String.valueOf(minExperience)), new Term( IndexerColumns.experience, String.valueOf(maxExperience)), true); documentSearchQuery.add(queryExperience, true, false); } if (minCtc >= 0 && maxCtc >= 0) { queryCtc = new RangeQuery(new Term(IndexerColumns.ctc, String.valueOf(minCtc)), new Term(IndexerColumns.ctc, String.valueOf(maxCtc)), true); documentSearchQuery.add(queryCtc, true, false); } if (emailId != null && !emailId.trim().equals("")) { try { queryEmailId = QueryParser.parse(getQueryString(criteriaForTermFields, emailId), IndexerColumns.emailId, new StandardAnalyzer()); } catch (ParseException e2) { e2.printStackTrace(); } documentSearchQuery.add(queryEmailId, true, false); } Hits hits = null; try { hits = indexsearcher.search(documentSearchQuery); } catch (IOException e3) { e3.printStackTrace(); throw new Error("Exception in search().." + e3.getMessage()); } Regards, Shivani --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]