-->
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.  [ 6 posts ] 
Author Message
 Post subject: Quering a composite key MongoDB looking field Date
PostPosted: Thu May 01, 2014 9:28 pm 
Newbie

Joined: Thu May 01, 2014 9:14 pm
Posts: 12
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=#000000]a date[/color].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 ); }


Top
 Profile  
 
 Post subject: Re: Quering a composite key MongoDB looking field Date
PostPosted: Fri May 02, 2014 6:08 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
have you tried to use Luke http://code.google.com/p/luke/ to check if the content of the indexes is correct?

It is a bit hard to check the code like this, do you think you can create a test or save the java files somewhere I can download them?


Top
 Profile  
 
 Post subject: Re: Quering a composite key MongoDB looking field Date
PostPosted: Fri May 02, 2014 9:22 pm 
Newbie

Joined: Thu May 01, 2014 9:14 pm
Posts: 12
Hi david thank you for your answer.
In this link you can find my simple project using composite key
http://www.mediafire.com/download/iuxsr8bf6xx8t78/UniqueTest.rar


Top
 Profile  
 
 Post subject: Re: Quering a composite key MongoDB looking field Date
PostPosted: Mon May 12, 2014 8:04 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
sorry I reply only now but I was on holiday this week with not much connectivity.

Thanks for the test, I've tried it and I've found something strange, it seems to me that you are saving the value "Sat Dec 17 05:10:56 UTC 1881" as date but you are looking for "Sat Dec 17 05:10:56 UTC 1880".

Also when you build the query you are looking for the keyword ignoring the field but not the analyzer, in the test case you are doing:

Code:
org.apache.lucene.search.Query query = queryBuilder.keyword().onField( "idd.dat" ).ignoreFieldBridge().matching( datee ).createQuery();


but I think it should be

Code:
org.apache.lucene.search.Query query = queryBuilder.keyword().onField( "idd.dat" )[b].ignoreAnalyzer()[/b].ignoreFieldBridge().matching( datee ).createQuery();


Top
 Profile  
 
 Post subject: Re: Quering a composite key MongoDB looking field Date
PostPosted: Mon May 12, 2014 3:19 pm 
Newbie

Joined: Thu May 01, 2014 9:14 pm
Posts: 12
Hi David
Thank u very much for your answer i try it and it's well doing.

But now i want to have all date that are above from a date given.
I added in the databse 6 date.

Thu Feb 12 06:12:57 UTC 2015
Thu Mar 12 06:12:57 UTC 2015
Sun Apr 12 06:12:57 UTC 2015
Tue May 12 06:12:57 UTC 2015
Fri Jun 12 06:12:57 UTC 2015
Sun Jul 12 06:12:57 UTC 2015

but when i try to get all date that are above Wed Apr 12 06:12:57 UTC 2000 i get an empty list. a don't know whow to fix this problem.
also when i want a time from intervall i get a list not correct.

here my function to get list date using above:

public List<Person> getMesureFromTO(Date debut) {


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.range().onField("idd.dat").ignoreAnalyzer().ignoreFieldBridge().above(debut).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 par intervalle de date");
System.out.println(results.size());


return results;



}

please help me david really i need ur help for my project


Top
 Profile  
 
 Post subject: Re: Quering a composite key MongoDB looking field Date
PostPosted: Tue May 13, 2014 12:30 pm 
Newbie

Joined: Thu May 01, 2014 9:14 pm
Posts: 12
David here u can find my project really i need ur help.
http://www.mediafire.com/download/pabsnjxn1kcnvao/doDateUnique.rar
the select from database usin from to or above or below does not give correct results.


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