Date range query with lucene

会有一股神秘感。 提交于 2019-12-12 01:42:30

问题


I am trying to take data between specific date ranges from mssql db. But returns nothing. I found a solution here on stackoverflow but it is not working.

Here what I have done :

This is the date field from the entity class:

 @Basic(optional = false)
@Column(name = "tarih")
@Temporal(TemporalType.TIMESTAMP)
@DateBridge(resolution = Resolution.MILLISECOND)
private Date tarih;

This is how I am trying to take date between specific dates:

 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    Calendar cal = Calendar.getInstance();

    Calendar cal2 = new GregorianCalendar();
    cal2.setTime(new Date(114, 12, 15, 3, 4,4));


    System.out.println(dateFormat.format(cal.getTime()));
    System.out.println(dateFormat.format(cal2.getTime()));


    TermRangeQuery luceneRangeDateQuery = newStringRange("tarih", DateTools.dateToString(cal2.getTime(), DateTools.Resolution.MILLISECOND),
     DateTools.dateToString(cal.getTime(), DateTools.Resolution.MILLISECOND), true, true);
    org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneRangeDateQuery);


    List<Satislar> kayitliSatislar = fullTextQuery.list();

This is db record and it is type is datetime:

This is the output these 2 lines and query sent:

    System.out.println(dateFormat.format(cal.getTime()));
    System.out.println(dateFormat.format(cal2.getTime()));

来源:https://stackoverflow.com/questions/34474653/date-range-query-with-lucene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!