简体   繁体   English

SOLR-在架构中使用单个文本字段进行全文搜索

[英]SOLR - Use single text field in schema for full text search

I am getting familiar with SOLR. 我对SOLR很熟悉。

I would like to use SOLR for full text search for many kind of entities. 我想使用SOLR对多种类型的实体进行全文搜索。 I don't want to create a Document for every different type of entity. 我不想为每种不同类型的实体创建一个文档。 I don't want to be able to search for specific fields. 我不希望能够搜索特定字段。 I am only interested in that if a specified string is anywhere in any item. 我只对指定的字符串在任何项目中的任何地方感兴趣。

In database terms for example I have a table News and a table Employee and I want to search for the word 'apple', I don't mind in which field it is, I only want to get back the database ID from the records which contain it. 以数据库术语为例,我有一个表News和一个表Employee,我想搜索单词“ apple”,我不在乎它在哪个字段中,我只想从记录中检索数据库ID。包含它。

Could it be a solution, that I use a SOLR schema something like this: 我可以使用如下所示的SOLR模式作为解决方案:

<fields>
   <field name="id" type="string" indexed="true" stored="true"/> 
   <field name="content" type="text" indexed="true" stored="false"/>
</fields>

So, I only need an ID and the contents. 所以,我只需要一个ID和内容。 I put all the data, in which I want to be able search into one 'content' field. 我把所有的数据都放在一个“内容”字段中。 When I search for some words it looks for it in the 'id' and int the 'content'. 当我搜索某些单词时,它会在“ id”中查找并在“ content”中诠释。

Is this a good idea? 这是一个好主意吗? Any performance or design problem? 任何性能或设计问题?

Thanks, Tamas 谢谢,塔玛斯

See https://wiki.apache.org/solr/SchemaXml#Copy_Fields . 请参阅https://wiki.apache.org/solr/SchemaXml#Copy_Fields It says: 它说:

A common requirement is to copy or merge all input fields into a single solr field. 常见的要求是将所有输入字段复制或合并到单个solr字段中。 This can be done as follows:- 可以按照以下步骤进行:

<copyField source="*" dest="text"/>

That's typically what is done to search across multiple fields. 这通常是跨多个字段搜索的工作。

But if you don't even want your original fields, just concatenate all your fields into one big field content and index in Solr. 但是,如果您甚至不想使用原始字段,只需将所有字段连接到一个大字段content并在Solr中建立索引。 There should be no problems with that. 那个应该没有问题。

You can either copyField to text (see example in the distribution) and have that set as default field ("df" parameter in solrconfig.xml for the select handler). 您可以将Field复制到文本(请参见分发示例),然后将其设置为默认字段(对于SELECT处理程序,在solrconfig.xml中为“ df”参数)。

Or, if you anticipate more complex requirements down the line and/or non-text searches, I would recommend looking at eDismax with qf parameter and it will handle searching all those fields itself. 或者,如果您预期会进行更复杂的需求和/或非文本搜索,那么我建议您使用带有qf参数的eDismax,它会处理所有这些字段本身的搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM