I have a document entity Student
public class Student
{
public string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
}
I have an index Student_ByName with a boost on the FirstName property defined as
public class Student_ByName : AbstractIndexCreationTask<Domain.Student>
{
public Student_ByName()
{
Map = students => from s in students
select new
{
FirstName = s.FirstName.Boost(6),
s.LastName,
s.DateOfBirth,
s.Gender
};
}
}
I have the following Student document instances
{ FirstName: 'David', LastName: 'Globe', DateOfBirth: '02/04/2000' }
{ FirstName: 'Tyson', LastName: 'David', DateOfBirth: '23/10/2000' }
{ FirstName: 'David', LastName: 'James', DateOfBirth: '19/05/1996' }
then the query below does not promote rows where David is the first name to the top of the list.
var students = _session.Query<Domain.Student, Student_ByName>()
.Where(s => s.FirstName.StartsWith('David') ||
s.LastName.StartsWith('David'))
.ToList();
If I change the Where clause to check for equality then the rows with David as the first name are promoted to the top of the list
.Where(s => s.FirstName == 'David' || s.LastName == 'David')
.ToList();
My question is how can I get the boost on the FirstName to work when doing a BeginsWith search.
This is expected, see the explanation here:
http://grokbase.com/t/lucene/java-user/022dzkexc6/prefixquery-scoring
You can do this with query time (vs index time) scoring, using: