Search with special characters?

637 views
Skip to first unread message

Simon

unread,
Feb 20, 2014, 4:22:33 AM2/20/14
to rav...@googlegroups.com
Hi

I have some issues with a search query. If I fx search for something containing a '+' I don't get any results. I've tried to escape the '+' with "\+" but that doesn't change anything. Can you help me, please?

Here's my code snippet:


//Adding index to the document store
documentStore.DatabaseCommands.PutIndex("UsersQueryIndex", new IndexDefinition
{
   Map = "from user in docs.UserSearchDtos select new { user.Name, user.Email, PhoneNumbers=user.PhoneNumbers.Select(p=>p.PhoneNumber) }",
   Indexes =
   {
      { "Name", FieldIndexing.Analyzed }, 
      { "Email", FieldIndexing.Analyzed }
      { "PhoneNumbers", FieldIndexing.Analyzed }
   }
}, true);


//My search method
public IEnumerable<UserSearchDto> Execute(string query)
{
   query = string.Format("*{0}*", query);
   using (var session = _documentStore.OpenSession())
   {
      var users = session.Query<UserSearchDto>("UsersQueryIndex")
                         .Search(x => x.Name, query, escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards)
                         .Search(x => x.Email, query, escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards)
                         .Search(x => x.PhoneNumbers, query, escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards).Take(50).ToList();
     return users;
   }
}


//My test (added a dcument with the email "my+...@email.com")

_searchUser.Execute("my+n")                 //Returns no user. Expected one.
_searchUser.Execute(@"my\+n")               //Returns no user. Expected one.
_searchUser.Execute("my+...@email.com")    //Returns no user. Expected one.
_searchUser.Execute("my")                   //Returns user as expected
_searchUser.Execute("my n")                 //Returns user as expected


How do I make the first search queries work?


Itamar Syn-Hershko

unread,
Feb 20, 2014, 4:30:09 AM2/20/14
to rav...@googlegroups.com
You need to figure out which analyzer to use, evidently the default analyzers don't work for you.

--

Itamar Syn-Hershko
http://code972.com | @synhershko
Freelance Developer & Consultant


--
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/groups/opt_out.

Oren Eini (Ayende Rahien)

unread,
Feb 20, 2014, 4:41:38 AM2/20/14
to ravendb
By default, the standard analyzer will strip all special characters from the text.
And there is no sense it marking the Email field as analyzed. Just use the Default, instead of Analyzed.

 RavenDB Conference

Oren Eini

CEO

Mobile: + 972-52-548-6969

Office:  + 972-4-674-7811

Fax:      + 972-153-4622-7811






On Thu, Feb 20, 2014 at 11:22 AM, Simon <simon....@gmail.com> wrote:

Itamar Syn-Hershko

unread,
Feb 20, 2014, 4:51:12 AM2/20/14
to rav...@googlegroups.com
StandardAnalyzer will not tokenize email addresses anyway.

--

Itamar Syn-Hershko
http://code972.com | @synhershko
Freelance Developer & Consultant


Simon

unread,
Feb 20, 2014, 5:00:29 AM2/20/14
to rav...@googlegroups.com
Thank you for your answers. I've changed to the DefaultAnalyzer


Den torsdag den 20. februar 2014 10.22.33 UTC+1 skrev Simon:
Hi

I have some issues with a search query. If I fx search for something containing a '+' I don't get any results. I've tried to escape the '+' with "\+" but that doesn't change anything. Can you help me, please?

Here's my code snippet:


//Adding index to the document store
documentStore.DatabaseCommands.PutIndex("UsersQueryIndex", new IndexDefinition
{
   Map = "from user in docs.UserSearchDtos select new { user.Name, user.Email, PhoneNumbers=user.PhoneNumbers.Select(p=>p.PhoneNumber) }",
   Indexes =
   {
      { "Name", FieldIndexing.Analyzed }, 
      { "Email", FieldIndexing.Analyzed }
      { "PhoneNumbers", FieldIndexing.Analyzed }
   }
}, true);


//My search method
public IEnumerable<UserSearchDto> Execute(string query)
{
   query = string.Format("*{0}*", query);
   using (var session = _documentStore.OpenSession())
   {
      var users = session.Query<UserSearchDto>("UsersQueryIndex")
                         .Search(x => x.Name, query, escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards)
                         .Search(x => x.Email, query, escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards)
                         .Search(x => x.PhoneNumbers, query, escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards).Take(50).ToList();
     return users;
   }
}


//My test (added a dcument with the email "my+...@email.com")

_searchUser.Execute("my+n")                 //Returns no user. Expected one.
_searchUser.Execute(@"my\+n")               //Returns no user. Expected one.
_searchUser.Execute("my+name@email.com")    //Returns no user. Expected one.
Reply all
Reply to author
Forward
0 new messages