Hello,
i'm really need your help i'm using Mongodb and hibernate OGM and i need quering a composite key using hibernate search but i'm getting an empty list.please help me here my code
person.java @Entity @Indexed @Table(name = "souta") public class Person {
@EmbeddedId @DocumentId @Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO) @FieldBridge(impl=PersonPkBridge.class) private PersonPK idd; @Column(name = "SURNAME", unique = true) private String age;
public String getAge() { return age; }
public void setAge(String age) { this.age = age; }
public PersonPK getIdd() { return idd; }
public void setIdd(PersonPK idd) { this.idd = idd; }
personDAO.java
public List<Person> getMesureDate(Date datee) { FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em); QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Person.class).get(); org.apache.lucene.search.Query query = queryBuilder.keyword().onField("idd.dat").ignoreFieldBridge().ignoreFieldBridge().ignoreFieldBridge().matching(datee).createQuery(); FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(query, Person.class); fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID); List<Person> results = fullTextQuery.getResultList(); System.out.println("size of list"); System.out.println(results.size()); //System.out.println(results.get(0).getIdd().getDat()); return results; }
PersonPK.java
@Embeddable public class PersonPK implements Serializable{ @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private int firstName; @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) @DateBridge(resolution = Resolution.DAY) @Temporal(javax.persistence.TemporalType.DATE) private java.util.Date dat; public java.util.Date getDat() { return dat; } public void setDat(java.util.Date dat) { this.dat = dat; } public int getFirstName() { return firstName; } public void setFirstName(int firstName) { this.firstName = firstName; }
PersonPKBridge.java public Object get(String name, Document document) { SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH); TimeZone utc = TimeZone.getTimeZone("UTC"); TimeZone.setDefault(utc); PersonPK id = new PersonPK(); Field field = document.getField( name + ".firstName" ); id.setFirstName( Integer.parseInt(field.stringValue()) ); System.out.println( Integer.parseInt(field.stringValue())); Field field3 = document.getField( name + ".dat" ); String dateInString = "Thu Apr 17 05:10:56 UTC 2014"; try { id.setDat(sdf.parse(dateInString)); sdf.setTimeZone(utc); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return id; } public String objectToString(Object object) { PersonPK id = (PersonPK) object; StringBuilder sb = new StringBuilder(); sb.append( id.getFirstName() ) .append( " " ) .append( id.getDat() ); return sb.toString(); } public void set(String name, Object value, Document document, LuceneOptions luceneOptions) { PersonPK id = (PersonPK) value; Store store = luceneOptions.getStore(); Index index = luceneOptions.getIndex(); TermVector termVector = luceneOptions.getTermVector(); Float boost = luceneOptions.getBoost(); //store each property in a unique field Field field = new Field( name + ".firstName", String.valueOf(id.getFirstName()), store, index, termVector ); field.setBoost( boost ); document.add( field ); field = new Field( name + ".dat", String.valueOf(id.getDat()), store, index, termVector ); field.setBoost( boost ); document.add( field ); //store the unique string representation in the named field field = new Field( name, objectToString( id ), store, index, termVector ); field.setBoost( boost ); document.add( field ); }
|