简体   繁体   English

SOLR中的自定义字段类

[英]Custom field class in SOLR

SOLR allows use to define a field type using settings such as: SOLR允许使用以下设置来定义字段类型:

<fieldtype name= "text_th" class = "solr.TextField" />

Here the class is an in-built SOLR class. 在这里,该类是内置的SOLR类。 Are we allowed to define our own class and use it in a fieldType definition? 是否允许我们定义自己的类并在fieldType定义中使用它? I would like to have a class such as MyCompany.MyClass{ String name, int age, float salary } 我想要一个类似MyCompany.MyClass {的类,字符串名称,整数年龄,浮动工资}

This is so that the value that I store in the SOLR document is a composite value made up of 3 components. 这样一来,我存储在SOLR文档中的值就是一个由3个组成部分组成的复合值。 If this is allowed, are there any guidelines or defined practices for such classes such as how to develop a tokenizer for such a custom class, etc.? 如果允许的话,那么此类类是否有任何准则或定义的实践,例如如何为此类自定义类开发令牌生成器等?

Thanks, 谢谢,

Yash 亚什

Yes, you can create your own FieldType - there should however be very specific reasons to do so. 是的,您可以创建自己的FieldType-但是应该有非常特定的原因。 The Solr backend is Lucene, so it'll be your own responsibility to marshal content between the Solr representation and the backing Lucene implementation. Solr后端是Lucene,因此您有责任在Solr表示形式和支持的Lucene实现之间封送内容。

Possible starting points could be the implementation of StrField in Solr (which is just a simple field in Lucene as well), or far more advanced examples such as LatLonType and PointField . 可能的起点可以是Solr中StrField的实现 (在Lucene中也是一个简单的字段),或者更高级的示例,例如LatLonTypePointField

Be aware that the reason to create a new field type should be to express something that isn't possible with the currently available field types (or greatly simplify handling of such values). 请注意,创建新字段类型的原因应该是表达一些当前可用字段类型无法实现的内容(或大大简化此类值的处理)。 Remember that you might have to concern yourself with how sorting should work, how filtering should work, etc., and syntaxes for all these items. 请记住,您可能必须关心排序应如何工作,过滤应如何工作等,以及所有这些项目的语法。

Usually you're far better off (and an actually maintainable solution) by creating a separate collection, or by indexing your content in more than one way. 通常,通过创建一个单独的集合或以多种方式为内容建立索引,您的处境会更好(并且是一个实际上可维护的解决方案)。 Custom field types (on the Lucene / Solr level) is almost never the answer. 自定义字段类型(在Lucene / Solr级别)几乎是无法解决的。

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

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