SourceForge.net Logo
Main Overview Wiki Issues Forum Build Fisheye

Welcome, Guest
Guest Settings
Help

Compass Support Forums » Compass » Compass Users

Thread: How to search id ranges

This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 27 - Pages: 2 [ 1 2 | Next ] - Last Post: Dec 12, 2011 7:18 PM Last Post By: anitas
Thunderstorm

Posts: 11
Registered: 4/25/07
How to search id ranges
Posted: Apr 25, 2007 7:38 AM
 
  Click to reply to this thread Reply
I would like to try to search indexed id (Long value) ranges. This is what I have:

A Media class with a corresponding mapping which looks like this:
<compass-core-mapping package="my.package">
<class name="Media" alias="media" root="true">
<id name="id">
<meta-data>media-id</meta-data>
</id>
...

I use the following code to search for the ranges:

queryPartBuilder.addShould(cs.queryBuilder().between("media.id", new Long(10), new Long(20), true));

This gives me some strange results. Like it is comparing Strings rather than Long values. Is there any way I can fix this behavior?

Things I tried:
- Tried setting the type explicitly in the mapping but that doesn't help a lot.
  • Tried using .le() and .ge() operators. Also not working for me.

Your help is appreciated.
Shay Banon

Posts: 4,028
Registered: 9/6/05
Re: How to search id ranges
Posted: Apr 26, 2007 6:47 AM   in response to: Thunderstorm in response to: Thunderstorm
 
  Click to reply to this thread Reply
All queries in Lucene are executed with Strings, what you need to do is format the numbers in order for them to make sense in a "string manner".

Luckily, formatting in Compass is very simple, you simply add the format attribute to the meta-data tag, with the format using the regular Java number formatting syntax. In your case you would want to add leading zeros.
Thunderstorm

Posts: 11
Registered: 4/25/07
Re: How to search id ranges
Posted: Apr 27, 2007 5:18 AM   in response to: Shay Banon in response to: Shay Banon
 
  Click to reply to this thread Reply
I added the format string to zero out the strings to the meta-data field and tried it again but to no avail. I still get back results with id values:
2, 100, 101, 102, etc
when searching in range 10 to 20.

XML-Mapping I have:
<id name="id">
<meta-data converter="long" format="0000000000000000000">media-id</meta-data>
</id>
Thunderstorm

Posts: 11
Registered: 4/25/07
Re: How to search id ranges
Posted: Apr 27, 2007 5:30 AM   in response to: Thunderstorm in response to: Thunderstorm
 
  Click to reply to this thread Reply
My bad. I was still searching on media.id instead of media.id.media-id
I fixed it now. Thank you for your response.
jolinar13

Posts: 129
Registered: 12/21/06
Re: How to search id ranges
Posted: May 2, 2007 9:48 AM   in response to: Thunderstorm in response to: Thunderstorm
 
  Click to reply to this thread Reply
Hello,
It still does not work for me :

<property name="population">
    		<meta-data converter="int" format="00000000">population</meta-data>
</property>


Query string : population:[1 TO 50]
Returns no result.

Thanks
Florian

Message was edited by:
jolinar13
jolinar13

Posts: 129
Registered: 12/21/06
Re: How to search id ranges
Posted: May 14, 2007 8:32 AM   in response to: jolinar13 in response to: jolinar13
 
  Click to reply to this thread Reply
I guess I need to use "population:[00000001 TO 00000050]".

But is there a way to make user's life easier here? ;-)

Thanks,
Florian
Shay Banon

Posts: 4,028
Registered: 9/6/05
Re: How to search id ranges
Posted: May 14, 2007 12:53 PM   in response to: jolinar13 in response to: jolinar13
 
  Click to reply to this thread Reply
Of course there is. Not too simple to implement though. It is a possible feature request in Compass.
jolinar13

Posts: 129
Registered: 12/21/06
Re: How to search id ranges
Posted: May 15, 2007 2:07 AM   in response to: Shay Banon in response to: Shay Banon
 
  Click to reply to this thread Reply
What do you advise me to do?
Thanks,
Florian
Shay Banon

Posts: 4,028
Registered: 9/6/05
Re: How to search id ranges
Posted: May 16, 2007 10:56 AM   in response to: jolinar13 in response to: jolinar13
 
  Click to reply to this thread Reply
Open a Jira issue and I will see how it can be implemented. It won't be soon, though.
jolinar13

Posts: 129
Registered: 12/21/06
Re: How to search id ranges
Posted: May 17, 2007 3:54 AM   in response to: Shay Banon in response to: Shay Banon
 
  Click to reply to this thread Reply
Hello,

CMP-404 open at http://jira.compassframework.org/browse/ CMP-404?page=all

See you
Florian
jolinar13

Posts: 129
Registered: 12/21/06
Re: How to search id ranges
Posted: Jun 14, 2007 7:49 AM   in response to: jolinar13 in response to: jolinar13
 
  Click to reply to this thread Reply
Hello,

I read in CompassQueryParser.java :

Extends Lucene {@link org.apache.lucene.queryParser.QueryParser} and overrides {@link #getRangeQuery(String,String,String,boolean)}
 * since lucene performs data parsing which is a performance killer. Anyhow, handling dates in Compass
 * is different and simpler than Lucene.


Why do you say it is simpler?
Why not use lucene's query parser for my requirements (date ranges)?
jolinar13

Posts: 129
Registered: 12/21/06
Re: How to search id ranges
Posted: Jun 14, 2007 10:26 AM   in response to: jolinar13 in response to: jolinar13
 
  Click to reply to this thread Reply
Hello,

I wrote my custom QueryParser, using Lucene default parser.

For those interested, I had to add :
queryParser.setDateResolution(Resolution.DAY);

for Lucene not to use the deprecated DateField.

Then the yyyyMMdd format is transparent to the user :-)

For the number problem, still looking for a solution...

See you
Florian
Harini

Posts: 43
Registered: 5/10/07
Re: How to search id ranges
Posted: Jul 17, 2007 2:06 AM   in response to: jolinar13 in response to: jolinar13
 
  Click to reply to this thread Reply
Hi Florian,

I have a similar requirement to search on range of numbers(double/int). Were you able to resolve this issue?

Thanks,
Harini
jolinar13

Posts: 129
Registered: 12/21/06
Re: How to search id ranges
Posted: Jul 17, 2007 8:58 AM   in response to: Harini in response to: Harini
 
  Click to reply to this thread Reply
Hello, as you can see in the jira issue, the problem has not been fixed.
I have not found any other solution.
See you
Florian
javaguy44

Posts: 8
Registered: 9/3/08
Re: How to search id ranges
Posted: Jun 20, 2009 3:06 AM   in response to: Thunderstorm in response to: Thunderstorm
 
  Click to reply to this thread Reply
Hi all,

I got the range query working with numbers and thought I would contribute!.

I use annotations and my shorthand code is the following:

@Searchable
public class Record {

@SearchableId
@SearchableMetaData(name = "id", converter = "long", format = "0000000000000000000")
Long id;

And my search query is:
id:1 TO 5

I'm using the CompassSearchHelper + aliases. As a result,my toString representation of Compass class LuceneSearchEngineQuery instance is +alias:Record +id:0000000000000000001 TO 0000000000000000005

Hope that helps someone!

Legend
Guru: 2001 + pts
Expert: 501 - 2000 pts
Super-star: 101 - 500 pts
Assistant: 51 - 100 pts
Participant: 0 - 50 pts
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums