Hello Gunnar,
i have 2 Entities in my project NoSQL(Mongodb).the first collection contains the consumption of clients and the second collections contains the clients.
this is the Entitie of client: @Entity @Indexed @Table(name = "GeneralEntityy") public class GeneralEntity implements Serializable{
@DocumentId @Id @GeneratedValue private int identifiant; @Column(name="customerIdent") @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private int customerIdent; @Column(name="terminalIdent") @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private int terminalIdent; @Column(name="submeterIdent") @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private int submeterIdent; @Column(name="machineIdent") @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private int machineIdent; @Column(name="gatewayIdent") @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private int gatewayIdent; @Column(name="siteIdent", nullable = false) @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private int siteIdent; }
[color=#FF00BF]and this is the entity of cunsumption
@Entity @Indexed @Table(name = "consumption")
public class consumption implements Serializable{ @DocumentId @Id @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid", strategy = "uuid2") private String id; @Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO) @DateBridge(resolution = Resolution.MILLISECOND) @Temporal(javax.persistence.TemporalType.TIMESTAMP) @Column(name = "mesure_datetime") private Date mesure_datetime; @Column(name="mesure_identifier") @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private int mesure_identifier; @Column(name="iph3") @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private double mesure_iph3; @Column(name="ip") @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private double mesure_ip; @Column(name="ipp") @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private double mesure_ipp; @Column(name="uph1") @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) private double mesure_uph1;
@DateBridge(resolution = Resolution.DAY) @Temporal(javax.persistence.TemporalType.DATE) @Column(name = "decision") private Date decision;
@IndexedEmbedded @ManyToOne() private GeneralEntity gen; }[/color]
So i have one join and this is my query hibernate search to get the list of consumption of client:
SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(HibernateUtilNoSQL.getEntityManager()); QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(consumption .class).get(); org.apache.lucene.search.Query query = queryBuilder.bool().must(queryBuilder.keyword().onField("general.customerIdent").matching(1123).createQuery()) .must(queryBuilder.keyword().onField("general.terminalIdent").matching(ter).createQuery()) .must( queryBuilder .range() .onField("mesure_datetime") .from(sdf.parse( "01-"+day+"-2014 00:00:00")) .to(sdf.parse( "01-"+(day+1)+"-2014 00:00:00")) .createQuery() ) .createQuery(); FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(query,MesureparamNo.class); fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID); List<MesureparamNo> results = fullTextQuery.getResultList(); System.out.println(results.size()); return results;
|