我无法让我的 RavenDB 查询按预期工作。
我正在尝试根据用户搜索查询进行精确匹配,以匹配字符串中的所有单词。
因此,当我输入“Volkswagen”时,我想获得所有类型的“Volkswagen”汽车。如果我输入“Volkswagen Golf”,我只想得到“Volkswagen Golf”,依此类推。
到目前为止我所拥有的
public IEnumerable<Cars> GetSearch(string query)
{
return _documentSession.Query<Car>("CarIndex").Search(x => x.SearchQuery, query);
}
//Also tried with this one
public IEnumerable<Cars> GetSearch(string query)
{
return _documentSession.Query<Car>("CarIndex")
.Search(x => x.Make, query)
.Search(x => x.Model, query);
}
public class CarIndex : AbstractIndexCreationTask<Car>
{
public CarIndex()
{
Map = cars => from car in cars select
new
{
car.SearchQuery,
car.Make,
car.Model,
car.Year
};
Index(x => x.Id, FieldIndexing.No);
Index(x => x.SearchQuery, FieldIndexing.Analyzed);
Index(x => x.Make, FieldIndexing.NotAnalyzed);
Index(x => x.Model, FieldIndexing.NotAnalyzed);
Index(x => x.Year, FieldIndexing.NotAnalyzed);
}
}
private void AddDummyData()
{
var cars = new List<Car>
{
new Car {Id = 1, Make = "Volkswagen", Model = "Touran", Year = 1998 },
new Car {Id = 2, Make = "Volkswagen", Model = "Polo", Year = 2000 },
new Car {Id = 3, Make = "Nissan", Model = "Micra", Year = 2005 },
new Car {Id = 4, Make = "Bugatti", Model = "Veyron", Year = 2010 },
new Car {Id = 5, Make = "Ferrari", Model = "Spider 458", Year = 2011 },
new Car {Id = 6, Make = "Aston Martin", Model = "Vanquish", Year = 2010 },
new Car {Id = 7, Make = "Ford", Model = "Focus", Year = 2001 },
new Car {Id = 8, Make = "Fiat", Model = "Punto", Year = 2013 },
new Car {Id = 9, Make = "Peugeot", Model = "206", Year = 2006 },
new Car {Id = 10, Make = "Opel", Model = "Ascona", Year = 2002 },
new Car {Id = 11, Make = "Volkswagen", Model = "Golf", Year = 1997 }
};
foreach (var car in cars)
{
car.SearchQuery = car.Make + " " + car.Model;
_documentSession.Store(car);
}
_documentSession.SaveChanges();
}
问题是当 make 包含两个词时:“Aston Martin”等。有人可以填写我所缺少的内容吗?