Failing unittest when upgrading to RavenDB 3.5 from 3.0

25 views
Skip to first unread message

Jochen Jonckheere

unread,
Jul 19, 2017, 9:30:20 AM7/19/17
to RavenDB - 2nd generation document database, con...@infohos.be
Hello,

After upgrading from RavenDB 3.0 to RavenDB 3.5 I have an unit/integration test that is failing.

It's a very simple test that does a search on a text field using a StartsWith. The term I use to search contains a -, and that character is causing the problem. It looks like that the RavenDB.Client is escaping the - with a \ and that the server doesn't remove the \ again.

Here's the failing request:

Receive Request # 165: GET     - Andes - http://localhost:8080/databases/Andes/indexes/Institution/ByVariousFields?&query=Query:"CAB %5C-INFI%5C-LARDINOIS*"&pageSize=10&sort=Denomination&SortHint-Denomination=String&resultsTransformer=SimpleInstitutionModelTransformer
Request # 165: GET     -     2 ms - Andes      - 200 - http://localhost:8080/databases/Andes/indexes/Institution/ByVariousFields?&query=Query:"CAB %5C-INFI%5C-LARDINOIS*"&pageSize=10&sort=Denomination&SortHint-Denomination=String&resultsTransformer=SimpleInstitutionModelTransformer
        Query: Query:"CAB \-INFI\-LARDINOIS*"
        Time: 1 ms
        Index: Institution/ByVariousFields
        Results: 0 returned out of 0 total.
        Timing:

If I use the Studio, the \ are not added and the request returns the correct number of results:

Receive Request # 164: GET     - Andes - http://localhost:8080/databases/Andes/indexes/Institution/ByVariousFields?query=Query: "CAB -INFI-LARDINOIS*"&start=0&pageSize=20
Request # 164: GET     -     3 ms - Andes      - 304 - http://localhost:8080/databases/Andes/indexes/Institution/ByVariousFields?query=Query: "CAB -INFI-LARDINOIS*"&start=0&pageSize=20
        Query: Query: "CAB -INFI-LARDINOIS*"
        Time: 0 ms


Can this been taking care of?

Kind regards,

Jochen Jonckheere

Tal Weiss

unread,
Jul 19, 2017, 10:10:36 AM7/19/17
to RavenDB - 2nd generation document database, con...@infohos.be
Can you please share the client code that generated this query ?

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Tal Weiss l Core Team Developer Mobile:+972-54-802-4849

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811l Skype: talweiss1982

RavenDB paving the way to "Data Made Simplehttp://ravendb.net/ 

Jochen Jonckheere

unread,
Jul 19, 2017, 10:18:29 AM7/19/17
to RavenDB - 2nd generation document database, con...@infohos.be
This is the client code:

return Session.Query<Institution_ByVariousFields.MapResult, Institution_ByVariousFields>()
                .Where(s => s.Query.StartsWith(searchTerm));

An here's the index code:

public class Institution_ByVariousFields : AbstractIndexCreationTask<Institution>
    {
        public class MapResult
        {
            public string Query { get; set; }
        }

        public Institution_ByVariousFields()
        {
            Map = institutions => from institution in institutions
                                  select new
                                             {
                                                 Query = new[]
                                                             {
                                                                 institution.Id.Substring(@"Institutions".Length + 1, 8),
                                                                 institution.Organization.Denomination,
                                                                 institution.Number
                                                             }
                                             };
        }
    }





On Wednesday, July 19, 2017 at 4:10:36 PM UTC+2, Tal Weiss wrote:
Can you please share the client code that generated this query ?
On Wed, Jul 19, 2017 at 4:30 PM, Jochen Jonckheere <jochen.j...@jxk.be> wrote:
Hello,

After upgrading from RavenDB 3.0 to RavenDB 3.5 I have an unit/integration test that is failing.

It's a very simple test that does a search on a text field using a StartsWith. The term I use to search contains a -, and that character is causing the problem. It looks like that the RavenDB.Client is escaping the - with a \ and that the server doesn't remove the \ again.

Here's the failing request:

Receive Request # 165: GET     - Andes - http://localhost:8080/databases/Andes/indexes/Institution/ByVariousFields?&query=Query:"CAB %5C-INFI%5C-LARDINOIS*"&pageSize=10&sort=Denomination&SortHint-Denomination=String&resultsTransformer=SimpleInstitutionModelTransformer
Request # 165: GET     -     2 ms - Andes      - 200 - http://localhost:8080/databases/Andes/indexes/Institution/ByVariousFields?&query=Query:"CAB %5C-INFI%5C-LARDINOIS*"&pageSize=10&sort=Denomination&SortHint-Denomination=String&resultsTransformer=SimpleInstitutionModelTransformer
        Query: Query:"CAB \-INFI\-LARDINOIS*"
        Time: 1 ms
        Index: Institution/ByVariousFields
        Results: 0 returned out of 0 total.
        Timing:

If I use the Studio, the \ are not added and the request returns the correct number of results:

Receive Request # 164: GET     - Andes - http://localhost:8080/databases/Andes/indexes/Institution/ByVariousFields?query=Query: "CAB -INFI-LARDINOIS*"&start=0&pageSize=20
Request # 164: GET     -     3 ms - Andes      - 304 - http://localhost:8080/databases/Andes/indexes/Institution/ByVariousFields?query=Query: "CAB -INFI-LARDINOIS*"&start=0&pageSize=20
        Query: Query: "CAB -INFI-LARDINOIS*"
        Time: 0 ms


Can this been taking care of?

Kind regards,

Jochen Jonckheere

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Tal Weiss

unread,
Jul 19, 2017, 11:37:12 AM7/19/17
to RavenDB - 2nd generation document database, con...@infohos.be
I have generated a similar query and it seems to work.
What version of v3.5 are you using?
Can you provide an isolated test that reproduce this?
My test:
using System.Linq;
using Raven.Client.Indexes;
using Raven.Tests.Common;
using Xunit;

namespace Raven.Tests.Issues
{
    public class Placeholder: RavenTest
    {
        [Fact]
        public void QueryingTermsWithDashesShouldWork()
        {
            using (var store = NewDocumentStore())
            {
                store.ExecuteIndex(new PeopleByName());
                using (var session = store.OpenSession())
                {
                    session.Store(new Person{Name="-The--Dasher-Person", Age = 34});   
                    session.SaveChanges();
                    WaitForIndexing(store);
                    var res = session.Query<Person>().Where(m => m.Name.StartsWith("-The--Dasher")).ToList();
                    Assert.Equal(res.Count,1);
                }
            }
        }

        public class PeopleByName : AbstractIndexCreationTask<Person>
        {
            public PeopleByName()
            {
                Map = people => from person in people select new {person.Name};
            }
        }
    }

    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }
}
 

To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Tal Weiss

unread,
Jul 20, 2017, 9:58:00 AM7/20/17
to Jonas Vandamme, RavenDB - 2nd generation document database, Condor
than the issue is likely with escaping white spaces and not dashes.
I'll see if i can look at it later today, but i'm a bit busy so this may wait for Sunday.

On Thu, Jul 20, 2017 at 3:40 PM, Jonas Vandamme <jonas.v...@infohos.be> wrote:

Hello,

 

We have recreated the test below and it works.

 

However, if we place a space in the name the person can no longer be found.

 

This is the request:

 

Receive Request # 111: GET     - Northwind - http://localhost:8080/databases/Northwind/indexes/dynamic/People?&query=Name:"%5C-The%5C-%5C-asher %5C-Person*"&pageSize=128

Request # 111: GET     -     5 ms - Northwind  - 200 - http://localhost:8080/databases/Northwind/indexes/dynamic/People?&query=Name:"%5C-The%5C-%C-Dasher %5C-Person*"&pageSize=128

        Query: Name:"\-The\-\-Dasher \-Person*"

        Time: 4 ms

        Index: PeopleByName

        Results: 0 returned out of 0 total.

        Timing:

 

And the changed code:

 

using (var session = store.OpenSession())

                {

                    session.Store(new Person { Name = "-The--Dasher -Person", Age = 34 });

                    session.SaveChanges();

                    WaitForIndexing(store);

                    var res = session.Query<Person>().Where(m => m.Name.StartsWith("-The--Dasher -Person")).ToList();

                    Assert.AreEqual(res.Count, 1);

                }

 

Kind regards,

 

Jonas Vandamme

 

 

 

You're receiving this message because you're a member of the Condor group. If you don't want to receive any messages or events from this group, stop following it in your inbox.

 

View group conversations   |   View group files

 

 

Tal Weiss

unread,
Jul 25, 2017, 4:05:59 AM7/25/17
to Jonas Vandamme, RavenDB - 2nd generation document database, Condor
Hi Jochen,
I had to make sure i properly fix this without creating new regressions so it took longer than expected.
The underlining issue is , if you have white space in your query string and Lucene special characters than the query will get quoted but the Lucene characters will get escaped when they shouldn't.
Reply all
Reply to author
Forward
0 new messages