1

ドキュメント内の複数のフィールドを検索できるように、作成してインデックスを作成しようとしています(これが私がやろうとしていることです)。このテストクラスは、私がやろうとしていることを説明するために作成しました。私の問題はこれです。インデックスでは、Noteフィールドを分割して、内の任意の単語をNote検索できるようにします。ただし、最初の単語または文字を使用して検索すると、「A」のテストではヒットが得られないことに気付きましたが、「B」を使用して検索すると、ヒットが得られません。なぜそうなのか。

public class Sandbox
{
    [Fact]
    public void Run_Forrest_Run()
    {
        var store = new EmbeddableDocumentStore
        {
            RunInMemory = true, 
            Conventions = { DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites }
        };

        store.Initialize();
        IndexCreation.CreateIndexes(typeof(SearchExpenseIndex).Assembly, store);

        using (store)
        {
            using (var session = store.OpenSession())
            {
                session.Store(new Expense
                {
                    Date = DateTime.Today,
                    Category = "Transport",
                    Amount = 1000,
                    Note = "A B C"
                });

                session.SaveChanges();
            }

            Thread.Sleep(1000);

            // var terms = new[] {"A"}; <-- THIS WILL FAIL
            var terms = new[] {"B"};

            using (var session = store.OpenSession())
            {
                var result = session.Query<SearchExpenseIndex.ReduceResult, SearchExpenseIndex>()
                                .Where(x => x.Query.In(terms))
                                .As<Expense>()
                                .Select(x => new 
                                {
                                    Id = x.Id,
                                    Category = x.Category,
                                    Date = x.Date,
                                    Amount = x.Amount,
                                    Note = x.Note
                                }).ToList();


                Assert.Equal(1, result.Count);

            }
        }
    }

    public class Expense
    {
        public string Id { get; set; }
        public DateTime Date { get; set; }
        public string Category { get; set; }
        public decimal Amount { get; set; }
        public string Note { get; set; }
    }

    public class SearchExpenseIndex : AbstractIndexCreationTask<Expense, SearchExpenseIndex.ReduceResult>
    {
        public class ReduceResult
    {
        public string Query { get; set; }
        public string UserId { get; set; }
    }

        public SearchExpenseIndex()
    {
        Map = documents => from d in documents
            select new
            {
                Query = new object[]
                {
                    d.Category,
                    d.Note,
                    d.Note.Split(' '),
                    d.Date.ToString("yyyy-MM-dd")
                }
            };
        }
    }
}

ここで何が欠けていますか?

4

1 に答える 1

0

ペレ、文字「A」は英語のストップ ワードです。そのため、ほとんどすべての検索用語がそこにあるため、実際に検索することはできません。

于 2012-06-10T11:14:46.587 に答える