검색 자의 작업 속도가 매우 빠릅니다. 그러나 검색자가 구식 결과를 반환하는 경향이 있습니다. 내 사이트는 NerdDinner와 매우 흡사하여 과거의 이벤트가 무의미 해졌습니다.Lucene.Net : 검색 결과에 날짜 필터를 추가하려면 어떻게해야합니까?
나는 현재이
메모와 같은 색인 해요 : 예는 C#으로
Public Function AddIndex(ByVal searchableEvent As [Event]) As Boolean Implements ILuceneService.AddIndex
Dim writer As New IndexWriter(luceneDirectory, New StandardAnalyzer(), False)
Dim doc As Document = New Document
doc.Add(New Field("id", searchableEvent.ID, Field.Store.YES, Field.Index.UN_TOKENIZED))
doc.Add(New Field("fullText", FullTextBuilder(searchableEvent), Field.Store.YES, Field.Index.TOKENIZED))
doc.Add(New Field("user", If(searchableEvent.User.UserName = Nothing,
"User" & searchableEvent.User.ID,
searchableEvent.User.UserName),
Field.Store.YES,
Field.Index.TOKENIZED))
doc.Add(New Field("title", searchableEvent.Title, Field.Store.YES, Field.Index.TOKENIZED))
doc.Add(New Field("location", searchableEvent.Location.Name, Field.Store.YES, Field.Index.TOKENIZED))
doc.Add(New Field("date", searchableEvent.EventDate, Field.Store.YES, Field.Index.UN_TOKENIZED))
writer.AddDocument(doc)
writer.Optimize()
writer.Close()
Return True
End Function
통지를하는 경우 내 예제 VB.NET에 있지만 난 상관 없어 내가 가진 방법 " 이벤트 날짜를 저장하는 "날짜"색인입니다.
내 검색 후 나는 다음을 시도했던이
''# code omitted
Dim reader As IndexReader = IndexReader.Open(luceneDirectory)
Dim searcher As IndexSearcher = New IndexSearcher(reader)
Dim parser As QueryParser = New QueryParser("fullText", New StandardAnalyzer())
Dim query As Query = parser.Parse(q.ToLower)
''# We're using 10,000 as the maximum number of results to return
''# because I have a feeling that we'll never reach that full amount
''# anyways. And if we do, who in their right mind is going to page
''# through all of the results?
Dim topDocs As TopDocs = searcher.Search(query, Nothing, 10000)
Dim doc As Document = Nothing
''# loop through the topDocs and grab the appropriate 10 results based
''# on the submitted page number
While i <= last AndAlso i < topDocs.totalHits
doc = searcher.Doc(topDocs.scoreDocs(i).doc)
IDList.Add(doc.[Get]("id"))
i += 1
End While
''# code omitted
처럼 보이지만 그것은 (NullReferenceException이 던진) 아무 소용했다.
While i <= last AndAlso i < topDocs.totalHits
If Date.Parse(doc.[Get]("date")) >= Date.Today Then
doc = searcher.Doc(topDocs.scoreDocs(i).doc)
IDList.Add(doc.[Get]("id"))
i += 1
End If
End While
은 또한 다음과 같은 문서를 발견,하지만 당신은
BooleanQuery
여러 쿼리를 결합 할 수 있습니다 그것은
http://lucene.apache.org/java/1_4_3/api/org/apache/lucene/search/DateFilter.html
좋아, 나는 당신이 mvc를 다시 추가했다고 생각했다. 그래서 IronPython 또는 IronRuby 예제로 확인해 주시겠습니까? ;) – jfar
:-) [prolly 그것을 추진하고있다] –