2012-09-10 46 views

回答

14

你可以一個「時間戳」字段添加到您的Solr模式是把當前的日期/時間到記錄添加時。

<field name="timestamp" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/> 

然後,按此字段的降序排序,第一條記錄將是最新的。像這樣的查詢應該這樣做: -

http://localhost:8080/solr/core-name/select/q=*%3A*&start=0&rows=1&sort=timestamp+desc

+0

有沒有別的辦法......?因爲我必須在Solr索引中添加字段,然後... 感謝您的回覆... –

+0

我相信這是做到這一點最可靠的方式,因爲時間戳字段將由Solr添加並保證準確。你可以用@ parvin的答案,但是這會假設你的docid字段是順序的並且可以被排序。 –

8

您可以通過下面的查詢索引順序的文件進行排序。

http://localhost:8983/solr/select?q=*:*&sort=_docid_ asc 

or 

http://localhost:8983/solr/select?q=*:*&sort=_docid_ desc 
+1

謝謝,這就是我需要的。 – Oyeme

+0

指望docid交叉合併安全嗎?請參閱http://osdir.com/ml/solr-user.lucene.apache.org/2011-12/msg01178.html –

+0

請勿使用_docid_,因爲它會更改以查看該響應以瞭解http://lucene.472066.n3。 nabble.com/Get-DocID-after-Document-insert-td556278.html – aName