Пример #1
0
        public void ParsingOperatorsInQuotes_ShouldTreatAsText()
        {
            var result        = this.Parse("\"test & hello\"");
            var expectedQuery = new AdjacentWordsQueryOperator(
                new IWordQueryPart[]
            {
                new ExactWordQueryPart("test"),
                new ExactWordQueryPart("&"),
                new ExactWordQueryPart("hello")
            });

            VerifyResult(result, expectedQuery);
        }
Пример #2
0
        public void ParsingWordsInQuotes_ShouldResultInAdjacentWordsQueryOperator()
        {
            var result        = this.Parse("\"search words startswith* too\"");
            var expectedQuery = new AdjacentWordsQueryOperator(
                new IWordQueryPart[]
            {
                new ExactWordQueryPart("search"),
                new ExactWordQueryPart("words"),
                new StartsWithWordQueryPart("startswith"),
                new ExactWordQueryPart("too")
            });

            VerifyResult(result, expectedQuery);
        }
Пример #3
0
        public void ShouldOnlyReturnMatchesForAppropriateField()
        {
            var sut = new AdjacentWordsQueryOperator(
                new[] {
                new FakeQueryPart(
                    QueryWordMatch(7, FieldMatch(1, 8, 20, 100), FieldMatch(2, 9, 14)),
                    QueryWordMatch(8, FieldMatch(1, 11, 101), FieldMatch(2, 8, 104))),
                new FakeQueryPart(
                    QueryWordMatch(7, FieldMatch(1, 7, 9, 21)),
                    QueryWordMatch(8, FieldMatch(1, 5, 102), FieldMatch(2, 9))),
                new FakeQueryPart(
                    QueryWordMatch(7, FieldMatch(1, 8, 10)),
                    QueryWordMatch(8, FieldMatch(1, 103, 104), FieldMatch(2, 10)))
            });

            var results = sut.Evaluate(() => new FakeIndexNavigator());

            // Item 7 matches:
            // Field 1: ((8, 9), 10)
            // Field 2: None
            // Item 8 matches:
            // Field 1: ((101, 102), 103)
            // Field 2: ((8, 9), 10)
            results.Matches.Should().BeEquivalentTo(
                new[]
            {
                QueryWordMatch(
                    7,
                    new FieldMatch(1, CompositeMatch(8, 9, 10))),
                QueryWordMatch(
                    8,
                    new FieldMatch(1, CompositeMatch(101, 102, 103)),
                    new FieldMatch(2, CompositeMatch(8, 9, 10)))
            },
                config => config.AllowingInfiniteRecursion());
        }
        public void ShouldOnlyReturnMatchesForAppropriateField()
        {
            var sut = new AdjacentWordsQueryOperator(
                new[] {
                new FakeQueryPart(
                    ScoredToken(7, ScoredFieldMatch(1D, 1, 8, 20, 100), ScoredFieldMatch(100D, 2, 9, 14)),
                    ScoredToken(8, ScoredFieldMatch(2D, 1, 11, 101), ScoredFieldMatch(101D, 2, 8, 104))),
                new FakeQueryPart(
                    ScoredToken(7, ScoredFieldMatch(3D, 1, 7, 9, 21)),
                    ScoredToken(8, ScoredFieldMatch(4D, 1, 5, 102), ScoredFieldMatch(102D, 2, 9))),
                new FakeQueryPart(
                    ScoredToken(7, ScoredFieldMatch(5D, 1, 8, 10)),
                    ScoredToken(8, ScoredFieldMatch(6D, 1, 103, 104), ScoredFieldMatch(103D, 2, 10)))
            });

            var results = sut.Evaluate(() => new FakeIndexNavigator(), QueryContext.Empty);

            // Item 7 matches:
            // Field 1: ((8, 9), 10)
            // Field 2: None
            // Item 8 matches:
            // Field 1: ((101, 102), 103)
            // Field 2: ((8, 9), 10)
            results.Matches.Should().BeEquivalentTo(
                new[]
            {
                ScoredToken(
                    7,
                    ScoredFieldMatch(9D, 1, CompositeMatch(8, 9, 10))),
                ScoredToken(
                    8,
                    ScoredFieldMatch(12D, 1, CompositeMatch(101, 102, 103)),
                    ScoredFieldMatch(306D, 2, CompositeMatch(8, 9, 10)))
            },
                config => config.AllowingInfiniteRecursion());
        }