Search code examples
solrnet

Solrnet - Retrieve x number of recent items


I was wondering if there is a straightforward way to receive the top 10 most recent items (by date) using solrnet? I assume I can use rows to specify the number of records returned but am not sure if there is an efficient way to query the most recent items...

Thank you

JP


Solution

  • First, you need a timestamp field in your schema, for example:

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

    Then sort it by this field with SolrNet:

    var results = solr.Query(SolrQuery.All, new QueryOptions {
        Rows = 10,
        OrderBy = new[] {new SortOrder("timestamp", Order.DESC)},
    });