Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用lucene进行日期范围查询_Java_Lucene_Full Text Search_Hibernate Search_Date Range - Fatal编程技术网

Java 使用lucene进行日期范围查询

Java 使用lucene进行日期范围查询,java,lucene,full-text-search,hibernate-search,date-range,Java,Lucene,Full Text Search,Hibernate Search,Date Range,我试图从mssql数据库中获取特定日期范围之间的数据。但是什么也不返回。我在stackoverflow上找到了一个解决方案,但它不起作用 以下是我所做的: 这是实体类中的日期字段: @Basic(optional = false) @Column(name = "tarih") @Temporal(TemporalType.TIMESTAMP) @DateBridge(resolution = Resolution.MILLISECOND) private Date tarih; 这就是我如

我试图从mssql数据库中获取特定日期范围之间的数据。但是什么也不返回。我在stackoverflow上找到了一个解决方案,但它不起作用

以下是我所做的:

这是实体类中的日期字段:

 @Basic(optional = false)
@Column(name = "tarih")
@Temporal(TemporalType.TIMESTAMP)
@DateBridge(resolution = Resolution.MILLISECOND)
private Date tarih;
这就是我如何在特定日期之间选择日期:

 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();

这完全取决于您使用的搜索版本。在搜索4和搜索5之间行为已更改。你的说法是什么?另外,在您的示例中,“cal2”的处理方式是什么。我觉得它的构造很奇怪。这应该是起始范围吗?“newStringRange”来自哪里?它有什么作用?我已经设法让它工作了。我没有将@Field属性添加到日期字段。所以它没有被索引。但我没有看到带有该注释的示例。所以它应该是有效的。不知道。可能注释库已更改。在@DateBridge字段中,编码类型应定义为字符串。因为默认日期类型是整数,并且不强制转换。
    System.out.println(dateFormat.format(cal.getTime()));
    System.out.println(dateFormat.format(cal2.getTime()));