RavenDB中带有空格键搜索的子字符串 [英] Substring with spacebar search in RavenDB

查看:96
本文介绍了RavenDB中带有空格键搜索的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这样的查询:

I'm using such a query:

var query = "*" + QueryParser.Escape(input) + "*";
session.Query<User, UsersByEmailAndName>().Where(x => x.Email.In(query) || x.DisplayName.In(query));

在简单索引的支持下:

public UsersByEmailAndName()
{
    Map = users => from user in users
                   select new
                          {
                              user.Email,
                              user.DisplayName,
                          };            
}

此处我已经读过:

默认情况下,RavenDB使用一个名为的自定义分析器 LowerCaseKeywordAnalyzer用于所有内容. (...)的默认值 每个字段分别为Stores中的FieldStorage.No和StoreIndex中的FieldIndexing.Default 索引."

"By default, RavenDB uses a custom analyzer called LowerCaseKeywordAnalyzer for all content. (...) The default values for each field are FieldStorage.No in Stores and FieldIndexing.Default in Indexes."

索引包含字段:

DisplayName -"jarek waliszko" Email -"my_email@domain.com"

最后是:

如果query*_email@**ali*之类的结果,则结果很好.但是当我在内部使用空格键时*ek wa*,不返回任何内容.为什么以及如何解决?

If the query is something like *_email@* or *ali* the result is fine. But while I use spacebar inside e.g. *ek wa*, nothing is returned. Why and how to fix it ?

顺便说一句:我正在使用RavenDB-Build#960

Btw: I'm using RavenDB - Build #960

推荐答案

因此,我想出了一个解决方法.我不知道这是否是正确的方式" ,但这对我有用.

So.., I've came up with an idea how to do it. I don't know if this is the "right way" but it works for me.

查询更改为:

var query = string.Format("*{0}*", Regex.Replace(QueryParser.Escape(input), @"\s+", "-"));

索引更改为:

public UsersByEmailAndName()
{
    Map = users => from user in users
                   select new
                          {
                              user.Email,
                              DisplayName = user.DisplayName.Replace(" ", "-"),
                          };
}

我刚刚将空格更改为用于用户输入文本的破折号,并将空格键更改为已建立索引的显示名称中的破折号.该查询现在给出预期的结果.一切都没有真正改变,我仍然像以前一样使用LowerCaseKeywordAnalyzer.

I've just changed whitespaces into dashes for the user input text and spacebars to dashes in the indexed display name. The query gives expected results right now. Nothing else really changed, I'm still using LowerCaseKeywordAnalyzer as before.

这篇关于RavenDB中带有空格键搜索的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆