我正在尝试搜索我的记录,以查找大于给定日期的日期。对于等于,小于和之间,但大于总是的日期,我能够做到这一点。这是我的索引方式:
Dim doc = New Document()
If sampleData.Start_Date IsNot Nothing Then
Dim startDate As Integer = DateTools.DateToString(sampleData.Start_Date, DateTools.Resolution.DAY)
doc.Add(New Field("Start_Date", startDate, Field.Store.YES, Field.Index.ANALYZED))
End If
writer.AddDocument(doc)
然后我这样搜索:
Dim LuceneSearch As New LuceneSearchEngine
Dim LuceneData As List(Of LuceneSearchData)
Dim SearchString = "{(Start_Date : {20180606 TO *} ) AND (DataType:Mechanism)}"
LuceneData = LuceneSearch.search_query(SearchString)
Public Function search_query(ByVal search_query_string As String) As IEnumerable(Of LuceneSearchData)
Using searcher = New IndexSearcher(_directory, False)
Dim hits_limit = 1000
Dim analyzer = New StandardAnalyzer(Version.LUCENE_30)
Dim StandardAnalyzer As StandardAnalyzer = New StandardAnalyzer(Version.LUCENE_30)
Dim QueryParser As QueryParser = New QueryParser(Version.LUCENE_30, search_query_string, StandardAnalyzer)
Dim Query As Query = QueryParser.Parse(search_query_string)
Dim hits = searcher.Search(Query, Nothing, hits_limit, Sort.RELEVANCE).ScoreDocs
Dim results = _mapLuceneToDataList(hits, searcher)
analyzer.Close()
searcher.Dispose()
Return results
End Using
End Function
这将始终返回空。但是,使用这样的查询字符串有效:
Dim SearchString = "{(Start_Date : {* TO 20180606} ) AND (DataType:Mechanism)}"
Dim SearchString = "{(Start_Date : [20170606 TO 20180606] ) AND (DataType:Mechanism)}"
有人可以指出我在做什么错吗?