-->
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.  [ 2 posts ] 
Author Message
 Post subject: [HibernateSearch] Query by publication Date
PostPosted: Fri Jul 22, 2011 7:19 am 
Beginner
Beginner

Joined: Wed Jul 20, 2011 5:07 am
Posts: 23
hello i use lucene-core 2.4 hibernate-search 3.0.1 Jboss 4.2GA

i create search for user :
Code:
@Override
   public List<Person> getAlbumByQuery(String userQuery, int min , int max)            
   {      
                FullTextEntityManager ftem =  org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);
            
      String[] personFields = {"German", "photos.German"};
   
           MultiFieldQueryParser queryParser = new MultiFieldQueryParser(personFields, foo.GermanAnalyzer());
      
      org.apache.lucene.search.Query luceneQuery;
      try{
         luceneQuery = queryParser.parse(query);
      } catch (Exception e)
      {       e.printStackTrace();
         return null;
      }
      System.out.println("LUCENE QUERY :" + luceneQuery);   
         
      Query jpaQuery = ftem.createFullTextQuery(luceneQuery, Person.class);
      
      if(min > 0)
      jpaQuery.setFirstResult(min);
      if(max > 0)
      jpaQuery.setMaxResults(max);
      
      return (List<Person>) jpaQuery.getResultList();      
      
   }


In class Person i have got:

Code:
@Indexed
public class Person implements Serializable, Cloneable
{
   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   @DocumentId
   private long id;
   
   @Field(name="German",index=Index.TOKENIZED, store = Store.NO)
   private String title;

   @Field(index=Index.UN_TOKENIZED)
   @DateBridge(resolution=Resolution.SECOND)
   private Timestamp publicationTimestamp;
        //other

       @IndexedEmbedded
       @OneToMany
   @JoinColumns({
      @JoinColumn(name="albumId", referencedColumnName="id")
   })
       private List<Photo> photos;

}



And my GermanAnalyzer:
Code:
public class GermanAnalyzer extends Analyzer {

   @Override
   public TokenStream tokenStream(String fieldName, Reader reader) {
      TokenStream result = new StandardTokenizer(reader);
        result = new StandardFilter(result);
        result = new LowerCaseFilter(result);
        result = new SnowballFilter(result, fieldName);
      return result;
   }

}




1) Its correct to define German snowball ?? fieldName must have got name="German"
i read post: viewtopic.php?f=9&t=991924&start=0 so i think its correct because i cant use @AnalyzerDef
2)as yout see i define search the parametr is userQuery but i need filter results by publicationTimestamp. In mysql something like that:
SELET * FROM Person WHERE title LIKE "%something%" AND publicationTimestamp > CURRENT_TIMESTAMP
3) If i define @AnalyzerDef in class Person and another @AnalyzerDef in class Photo
so than i must set analyzer to null in constructor MultiFieldQueryParser: MultiFieldQueryParser queryParser = new MultiFieldQueryParser(personFields, null);
??

And its working fine when i delete @IndexedEmbedded from Photo and delete "photos.German" from personFields
because if i have got right for SnowballFilder name photos.German isnt correct

Its possible add this parametr into query ??


Top
 Profile  
 
 Post subject: Re: [HibernateSearch] Query by publication Date
PostPosted: Fri Jul 22, 2011 8:52 am 
Beginner
Beginner

Joined: Wed Jul 20, 2011 5:07 am
Posts: 23
With german snowball i set:
String snowballFieldName = "German";
result = new SnowballFilter(result, snowballFieldName);

And its working fine


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.