RavenDB クエリを期待どおりに動作させる方法がわかりません。
文字列内のすべての単語と一致するように、ユーザーの検索クエリに基づいて完全一致を試みています。
したがって、「フォルクスワーゲン」と入力すると、すべてのタイプの「フォルクスワーゲン」の車が表示されます。また、「フォルクスワーゲン ゴルフ」と入力すると、「フォルクスワーゲン ゴルフ」のみが取得されます。
私がこれまでに持っているもの
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();
}
問題は、メーカーに「アストン マーティン」などの 2 つの単語が含まれている場合です。