-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 
Author Message
 Post subject: Failed to search number range
PostPosted: Fri Jul 13, 2007 12:07 am 
Regular
Regular

Joined: Tue Nov 04, 2003 12:37 pm
Posts: 57
Hello,

It cannot get any result when using numbering range query. The following is my code. Please help. Anyway, I checked the Hibernate-Search API, the @Keyword was deprecated, which annotation should I use ?

Best regards,
Eric



Code:
@Entity
@Indexed
public class Article implements Serializable {
   public static final long serialVersionUID = 1L;
      
   private long id;
   private String worker;
   private String title;
   private String text;
   private int page;
   
   public Article() {
      ;
   }
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @DocumentId
   public long getId() {
      return this.id;
   }
   public void setId(long id) {
      this.id = id;
   }
   
   @Field(index=Index.TOKENIZED)
   public String getText() {
      return this.text;
   }
   public void setText(String text) {
      this.text = text;
   }
   @Field(index=Index.TOKENIZED)
   public String getTitle() {
      return this.title;
   }
   public void setTitle(String title) {
      this.title = title;
   }
         
   @Keyword
   public int getPage() {
      return this.page;
   }
   public void setPage(int page) {
      this.page = page;
   }
   public String getWorker() {
      return this.worker;
   }
   public void setWorker(String worker) {
      this.worker = worker;
   }
   @Transient
   public String toString() {
      return worker + ":" + title + ", " + text + ", page=" + page;
   }
}




Code:
try {
         EntityManager em = EMUtil.getEntityManager();
         
         em.getTransaction().begin();
         
         Article a = new Article();
         a.setWorker("Hello World");
         a.setTitle("Line " + 100);
         a.setText("Testing");
         a.setPage(100);
         
         
         Article a1 = new Article();
         a1.setWorker("Hello World");
         a1.setTitle("Line " + 50);
         a1.setText("Testing");
         a1.setPage(80);
                  
         em.persist(a1);
         em.persist(a);
         
         
                  
         FullTextSession ftSession = Search.createFullTextSession((Session)em.getDelegate());
         
         
         QueryParser parser = new QueryParser("id", new StandardAnalyzer() );
         
         Query qry = parser.parse("page:[70 TO 120]");         
         
          org.hibernate.Query fullTextQuery = ftSession.createFullTextQuery(qry, test.model.Article.class);
         
                     
         List<Article> result = fullTextQuery.list();
         em.getTransaction().commit();
         
         System.out.println(".........." + result.size());
                                    
         for(Article art : result) {
            System.out.println(art);
            
         }
      } catch(Exception ex) {
         ex.printStackTrace();
      }


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 8:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
@Keyword should be replaced by @Field(index.Index.Un_TOKENIZED)
To compare 2 numbers check the PaddedIntegerBridge in the unit test suite. Also look at padded in the Lucene literature.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 15, 2007 10:00 pm 
Regular
Regular

Joined: Tue Nov 04, 2003 12:37 pm
Posts: 57
I added the PaddedIntegerBridge into the field (depends on the test suite).
But it still search nothing if I search the range of integer. Can you show me a simple runnable example?


Best regards,
Eric


Code:
try {
         EntityManager em = EMUtil.getEntityManager();
         
         em.getTransaction().begin();
         
         Article a = new Article();
         a.setWorker("Wonderful");
         a.setTitle("Line " + 100);
         a.setText("Testing");
         a.setPage(100);
         
         
         Article a1 = new Article();
         a1.setWorker("Hello World");
         a1.setTitle("Line " + 50);
         a1.setText("Testing Super Lucene");
         a1.setPage(80);
                  
         em.persist(a1);
         em.persist(a);
         
         em.getTransaction().commit();
         
         
         FullTextSession ftSession = Search.createFullTextSession((Session)em.getDelegate());         
         
         QueryParser parser = new QueryParser("id", new StandardAnalyzer() );
         
         Query qry = parser.parse("page:[50 TO 100]");         
         
          org.hibernate.Query fullTextQuery = ftSession.createFullTextQuery(qry, test.model.Article.class);
         
                     
         List<Article> result = fullTextQuery.list();
         
         
         System.out.println(".........." + result.size());
                                    
         for(Article art : result) {
            System.out.println(art);
            
         }
         
         
         em.close();
      } catch(Exception ex) {
         ex.printStackTrace();
      }



Code:
@Entity
@Indexed
public class Article implements Serializable {
   public static final long serialVersionUID = 1L;
      
   private long id;
   private String worker;
   private String title;
   private String text;
   private int page;
   
   public Article() {
      ;
   }
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @DocumentId
   public long getId() {
      return this.id;
   }
   public void setId(long id) {
      this.id = id;
   }
   
   @Field(index=Index.TOKENIZED)
   public String getText() {
      return this.text;
   }
   public void setText(String text) {
      this.text = text;
   }
   @Field(index=Index.TOKENIZED)
   public String getTitle() {
      return this.title;
   }
   public void setTitle(String title) {
      this.title = title;
   }
   
   
   @Field(index=Index.UN_TOKENIZED)
   @FieldBridge(impl=PaddedIntegerBridge.class,  params = @Parameter( name="pasdding", value="5" ) )
   public int getPage() {
      return this.page;
   }
   public void setPage(int page) {
      this.page = page;
   }
   public String getWorker() {
      return this.worker;
   }
   public void setWorker(String worker) {
      this.worker = worker;
   }
   @Transient
   public String toString() {
      return worker + ":" + title + ", " + text + ", page=" + page;
   }
}



Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 15, 2007 10:01 pm 
Regular
Regular

Joined: Tue Nov 04, 2003 12:37 pm
Posts: 57
I added the PaddedIntegerBridge into the field (depends on the test suite).
But it still search nothing if I search the range of integer. Can you show me a simple runnable example?


Best regards,
Eric


Code:
try {
         EntityManager em = EMUtil.getEntityManager();
         
         em.getTransaction().begin();
         
         Article a = new Article();
         a.setWorker("Wonderful");
         a.setTitle("Line " + 100);
         a.setText("Testing");
         a.setPage(100);
         
         
         Article a1 = new Article();
         a1.setWorker("Hello World");
         a1.setTitle("Line " + 50);
         a1.setText("Testing Super Lucene");
         a1.setPage(80);
                  
         em.persist(a1);
         em.persist(a);
         
         em.getTransaction().commit();
         
         
         FullTextSession ftSession = Search.createFullTextSession((Session)em.getDelegate());         
         
         QueryParser parser = new QueryParser("id", new StandardAnalyzer() );
         
         Query qry = parser.parse("page:[50 TO 100]");         
         
          org.hibernate.Query fullTextQuery = ftSession.createFullTextQuery(qry, test.model.Article.class);
         
                     
         List<Article> result = fullTextQuery.list();
         
         
         System.out.println(".........." + result.size());
                                    
         for(Article art : result) {
            System.out.println(art);
            
         }
         
         
         em.close();
      } catch(Exception ex) {
         ex.printStackTrace();
      }



Code:
@Entity
@Indexed
public class Article implements Serializable {
   public static final long serialVersionUID = 1L;
      
   private long id;
   private String worker;
   private String title;
   private String text;
   private int page;
   
   public Article() {
      ;
   }
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @DocumentId
   public long getId() {
      return this.id;
   }
   public void setId(long id) {
      this.id = id;
   }
   
   @Field(index=Index.TOKENIZED)
   public String getText() {
      return this.text;
   }
   public void setText(String text) {
      this.text = text;
   }
   @Field(index=Index.TOKENIZED)
   public String getTitle() {
      return this.title;
   }
   public void setTitle(String title) {
      this.title = title;
   }
   
   
   @Field(index=Index.UN_TOKENIZED)
   @FieldBridge(impl=PaddedIntegerBridge.class,  params = @Parameter( name="pasdding", value="5" ) )
   public int getPage() {
      return this.page;
   }
   public void setPage(int page) {
      this.page = page;
   }
   public String getWorker() {
      return this.worker;
   }
   public void setWorker(String worker) {
      this.worker = worker;
   }
   @Transient
   public String toString() {
      return worker + ":" + title + ", " + text + ", page=" + page;
   }
}



Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 3:13 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It has to be something like
Code:
Query qry = parser.parse("page:[0050 TO 0100]");

depending on your padding value

If you have Lucene In Action somwhere, check the book on padding, it explains what you need to do

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 3:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
And there is a typo here
Code:
@Parameter( name="pasdding", value="5" ) )

_________________
Emmanuel


Top
 Profile  
 
 Post subject: search number range problem
PostPosted: Fri Jul 20, 2007 5:10 am 
Regular
Regular

Joined: Tue Nov 04, 2003 12:37 pm
Posts: 57
Hello,

It doesn't really work.
when I tried to search page:[00050 TO 000100], it works fine.

If one of the Article.setPage(1000);

It also will show the reacords in the above query.


I think it is a big issue in number range search.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 9:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You have an issue somewhere in your padding then, or you tokenize your field, or you query tokenize your field

Check
http://wiki.apache.org/lucene-java/SearchNumericalFields

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Failed to search number range
PostPosted: Tue Mar 23, 2010 10:11 am 
Newbie

Joined: Tue Mar 23, 2010 10:00 am
Posts: 6
Hello,

I've tried to use PaddedIntegerBridge and I've noticed that I get a null pointer exception when the field is null. From Hibernate Search Reference Guide 3.1.1 I understood that it shouldn't try to index null fields and apparently it does.

Did I get it wrong and what should I return in method objectToString of the PaddedIntegerBridge for a null field?

I should mention that i'm using Hibernate Search 3.0.1, but I can't find a reference guide for it.


Top
 Profile  
 
 Post subject: Managed to search number range but failed to match number
PostPosted: Tue Mar 23, 2010 12:41 pm 
Newbie

Joined: Tue Mar 23, 2010 10:00 am
Posts: 6
1. Although it's working now, i'm still curious if hibernate is actually indexing null fields.

2. I'm able to search number ranges (something like page:[00050 TO 00100]).
I can't search a number though. e.g. page:(00100) returns no results and i know for sure there are some. Anybody knows what i'm doing wrong?


Top
 Profile  
 
 Post subject: Re: Managed to search number range but failed to match number
PostPosted: Tue Mar 23, 2010 12:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
mihaela wrote:
1. Although it's working now, i'm still curious if hibernate is actually indexing null fields.

Nope it does not. unless you write a custom fieldbridge where you do what you want.

mihaela wrote:
2. I'm able to search number ranges (something like page:[00050 TO 00100]).
I can't search a number though. e.g. page:(00100) returns no results and i know for sure there are some. Anybody knows what i'm doing wrong?

the parenthesis are the problem maybe?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Failed to search number range
PostPosted: Tue Mar 23, 2010 1:24 pm 
Newbie

Joined: Tue Mar 23, 2010 10:00 am
Posts: 6
1. I tried without parenthesis. I only put them because I found some examples like this.

2. The same thing happens with date fields. I'm using the default DateBridge. I can search in ranges, but when i try to find the exact date it returns no results:
this is working: parser.parse("birthDate:[19710303 TO 19710303]")
this is not: parser.parse("birthDate:19710303") and neither are parser.parse("birthDate:'19710303'") or parser.parse("birthDate:(19710303)")

3. I've asked about indexing null fields because when hibernate search is doing the indexing it is calling the objectToString(Object object) method of the PaddedIntegerBridge with a null value (object is null). If it calls the objectToString method for a a null field of my entity, doesn't it mean that it is indexing it?


Top
 Profile  
 
 Post subject: Re: Failed to search number range
PostPosted: Tue Mar 23, 2010 2:08 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It's a bit weird. But it really depends how your parser interprets it. Is it possible to display the query.toString() or even the explain method results. to know what Lucene query is created by the parser.

About PaddedIntegerBridge, which one are you talking about? The only one I see is in the test suite so we ahve not spec much time on it. Anyway Hibernate Search does not index null String value (though a null object value could be converted to a non-null string alue by a bridge.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.