RavenDB全文搜索 [英] RavenDB full-text search
问题描述
您能否告诉我们如何在 RavenDb 中执行简单的全文搜索。该数据库存储文件:电影{名称=加勒比海盗} 。我希望这个文件可以在搜索短语Pirates Carribean或任何其他词汇组合中找到。
担心与全文无关 - 默认情况下,Lucene以OR为基础,你想要的是一个AND
如果我是你,我会做
String [] terms = searchTerm.Split(); //或者任何string.split方法是
和
$ b (Name :(+ String.Join(AND,terms)+)); $ b
.Where
您的索引应该类似于
<$ p $ b $
public class Movie_ByName:AbstractIndexCreationTask
{
public override IndexDefinition CreateIndexDefinition()
{
return new IndexDefinitionBuilder< Movie>
{
Map = movies => from movie in movies
select new {movie.Name,market.Id},
Indexes =
{
{x => x.Name,FieldIndexing.Analyzed}
}
}
.ToIndexDefinition(DocumentStore.Conventions);
}
你不需要存储,你不需要从lucene直接在任何时间。你可能甚至不需要索引(你可能真的想要FieldIndexing.Analyzed,并可能在这里只使用动态查询)
尽管如此。
Can you please tell how to perform simple full-text search in RavenDb. The database is stored document: Movie {Name = "Pirates of the Carribean"}. I wish that this document was found on the search phrase "Pirates Carribean" or any other combination of words.
What you are worrying about isn't anything to do with full text - by default Lucene works on an OR basis and what you want is an AND
If I were you I'd do
String[] terms = searchTerm.Split(" "); // Or whatever the string.split method is
and
.Where("Name:(" + String.Join(" AND ", terms) + ")");
Your index should look something like
public class Movie_ByName : AbstractIndexCreationTask
{
public override IndexDefinition CreateIndexDefinition()
{
return new IndexDefinitionBuilder<Movie>
{
Map = movies => from movie in movies
select new { movie.Name, market.Id },
Indexes =
{
{x => x.Name, FieldIndexing.Analyzed}
}
}
.ToIndexDefinition(DocumentStore.Conventions);
}
You don't need storage, you're not requesting the data from lucene directly at any time. You might not even want an index (You might actually want FieldIndexing.Analyzed, and might get away with just using dynamic queries here)
Up to you though.
这篇关于RavenDB全文搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!