Skip to main content
added 575 characters in body
Source Link
Michael West
  • 18.6k
  • 2
  • 42
  • 105

Consider researching Solr functions. My experience has used a hard-coded field name with solr field extension. Perhaps you can figure out how to make this more dynamic.

First you can start by adding a new field to your CustomSearchResultItem class.

[IndexField("_val_")]
public string _val_ { get; set; }

Second you can write a query using the new field.

var query = PredicateBuilder.True();
query = query.And(x => x._val_.Equals("recip(abs(ms(NOW/HOUR,startdate_tdt)),3.16e-11,4,.4)"));

What this query should do is rank the results higher when the date is close to today, and then rank lower the further away it is.

Here is a simple demonstration while using Sitecore PowerShell Extensions against Solr.

$criteria = @(
    @{Filter = "Equals"; Field = "_val_"; Value = "recip(abs(ms(NOW/HOUR,__smallcreateddate_tdt)),3.16e-11,4,.4)"}
)
$props = @{
    Index = "sitecore_master_index"
    Criteria = $criteria
}

Find-Item @props | Select-Object Name,CreatedDate

I used CreatedDate and so I don't expect any future dates.

Example results

Consider researching Solr functions. My experience has used a hard-coded field name with solr field extension. Perhaps you can figure out how to make this more dynamic.

First you can start by adding a new field to your CustomSearchResultItem class.

[IndexField("_val_")]
public string _val_ { get; set; }

Second you can write a query using the new field.

var query = PredicateBuilder.True();
query = query.And(x => x._val_.Equals("recip(abs(ms(NOW/HOUR,startdate_tdt)),3.16e-11,4,.4)"));

What this query should do is rank the results higher when the date is close to today, and then rank lower the further away it is.

Consider researching Solr functions. My experience has used a hard-coded field name with solr field extension. Perhaps you can figure out how to make this more dynamic.

First you can start by adding a new field to your CustomSearchResultItem class.

[IndexField("_val_")]
public string _val_ { get; set; }

Second you can write a query using the new field.

var query = PredicateBuilder.True();
query = query.And(x => x._val_.Equals("recip(abs(ms(NOW/HOUR,startdate_tdt)),3.16e-11,4,.4)"));

What this query should do is rank the results higher when the date is close to today, and then rank lower the further away it is.

Here is a simple demonstration while using Sitecore PowerShell Extensions against Solr.

$criteria = @(
    @{Filter = "Equals"; Field = "_val_"; Value = "recip(abs(ms(NOW/HOUR,__smallcreateddate_tdt)),3.16e-11,4,.4)"}
)
$props = @{
    Index = "sitecore_master_index"
    Criteria = $criteria
}

Find-Item @props | Select-Object Name,CreatedDate

I used CreatedDate and so I don't expect any future dates.

Example results

Source Link
Michael West
  • 18.6k
  • 2
  • 42
  • 105

Consider researching Solr functions. My experience has used a hard-coded field name with solr field extension. Perhaps you can figure out how to make this more dynamic.

First you can start by adding a new field to your CustomSearchResultItem class.

[IndexField("_val_")]
public string _val_ { get; set; }

Second you can write a query using the new field.

var query = PredicateBuilder.True();
query = query.And(x => x._val_.Equals("recip(abs(ms(NOW/HOUR,startdate_tdt)),3.16e-11,4,.4)"));

What this query should do is rank the results higher when the date is close to today, and then rank lower the further away it is.