RavenDB を使用していますが、読み取り時にデータベースが非常に遅いことに気付きました。データベースにクエリを実行する方法は次のとおりです。
IEnumerable<Reduced> items;
Filter filter = (Filter)Filter;
var watch = Stopwatch.StartNew();
using (var session = documentStore.OpenSession())
{
var query = session.Query<eBayItem,eBayItemIndexer>().Where(y => y.Price <= filter.MaxPrice && y.Price >= filter.MinPrice);
query = filter.Keywords.ToArray()
.Aggregate(query, (q, term) =>
q.Search(xx => xx.Title, term, options: SearchOptions.And));
if (filter.ExcludedKeywords.Count > 0)
{
query = filter.ExcludedKeywords.ToArray().Aggregate(query, (q, exterm) =>
q.Search(it => it.Title, exterm, options: SearchOptions.Not));
}
items = query.AsProjection<Reduced>().ToList();
Console.WriteLine("Query: " + query.ToString());
Console.WriteLine("Results: " + items.Count());
}
watch.Stop();
Console.WriteLine("Query time: " + watch.Elapsed.Milliseconds + " ms");
return items;
出力:
- クエリ: Price_Range:[* TO Dx600] AND Price_Range:[Dx400 TO NULL] AND Title:(Canon) AND Title:(MP) AND Title:(Black) -Title:(G1) -Title:(T3)
- 結果: 3
- クエリ時間: 365 ミリ秒
索引付け:
public class eBayItemIndexer : AbstractIndexCreationTask<eBayItem>
{
public eBayItemIndexer()
{
Map = contentItems =>
from contentItem in contentItems
select new { contentItem.Title, contentItem.Price };
Index(x => x.Title, FieldIndexing.Analyzed);
Index(x => x.Price, FieldIndexing.Analyzed);
TransformResults = (database, items) =>
from contentItem in items
select new { contentItem.Id };
}
}
初期化:
documentStore = new EmbeddableDocumentStore() { DataDirectory = "test.db" };
documentStore.Initialize();
IndexCreation.CreateIndexes(typeof(eBayItemIndexer).Assembly, documentStore);
documentStore.Configuration.TransactionMode = Raven.Abstractions.Data.TransactionMode.Lazy;
documentStore.Configuration.AllowLocalAccessWithoutAuthorization = true;
それを遅くするコードに何か問題がありますか?