SOLR和重音字符
我有职业的索引(标识符+职业):SOLR和重音字符
<field name="occ_id" type="int" indexed="true" stored="true" required="true" />
<field name="occ_tx_name" type="text_es" indexed="true" stored="true" multiValued="false" />
<!-- Spanish -->
<fieldType name="text_es" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_es.txt" format="snowball" />
<filter class="solr.SpanishLightStemFilterFactory"/>
</analyzer>
</fieldType>
这是一个真正的查询,为三个标识符(1,195和129):
curl -X GET "http://192.168.1.11:8983/solr/cyp_occupations/select?indent=on&q=occ_id:1+occ_id:195+occ_id:129&wt=json"
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"q":"occ_id:1 occ_id:195 occ_id:129",
"indent":"on",
"wt":"json"}},
"response":{"numFound":3,"start":0,"docs":[
{
"occ_id":1,
"occ_tx_name":"Abogado",
"_version_":1565225103805906944},
{
"occ_id":129,
"occ_tx_name":"Informático",
"_version_":1565225103843655680},
{
"occ_id":195,
"occ_tx_name":"Osteópata",
"_version_":1565225103858335746}]
}}
其中两个有重音字符,一个没有。因此,让我们occ_tx_name搜索,而无需使用口音:
curl -X GET "http://192.168.1.11:8983/solr/cyp_occupations/select?indent=on&q=occ_tx_name:abogado&wt=json"
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"q":"occ_tx_name:abogado",
"indent":"on",
"wt":"json"}},
"response":{"numFound":1,"start":0,"docs":[
{
"occ_id":1,
"occ_tx_name":"Abogado",
"_version_":1565225103805906944}]
}}
curl -X GET "http://192.168.1.11:8983/solr/cyp_occupations/select?indent=on&q=occ_tx_name:informatico&wt=json"
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"occ_tx_name:informatico",
"indent":"on",
"wt":"json"}},
"response":{"numFound”:1,”start":0,"docs":[
{
"occ_id":129,
"occ_tx_name":"Informático",
"_version_":1565225103843655680}]
}}
curl -X GET "http://192.168.1.11:8983/solr/cyp_occupations/select?indent=on&q=occ_tx_name:osteopata&wt=json"
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"occ_tx_name:osteopata",
"indent":"on",
"wt":"json"}},
"response":{"numFound":0,"start":0,"docs":[]
}}
我对上一次搜索“osteopata”失败这一事实很烦人,而“informatico”成功。索引的源数据是一个简单的MySQL表:
-- -----------------------------------------------------
-- Table `mydb`.`occ_occupation`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`occ_occupation` (
`occ_id` INT UNSIGNED NOT NULL,
`occ_tx_name` VARCHAR(255) NOT NULL,
PRIMARY KEY (`occ_id`)
ENGINE = InnoDB
表的排序规则是“utf8mb4_general_ci”。该索引是使用DataImportHandler创建的。这是定义:
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.1.11:3306/mydb"
user=“mydb” password=“mydb” />
<document name="occupations">
<entity name="occupation" pk="occ_id"
query="SELECT occ.occ_id, occ.occ_tx_name FROM occ_occupation occ WHERE occ.sta_bo_deleted = false">
<field column="occ_id" name="occ_id" />
<field column="occ_tx_name" name="occ_tx_name" />
</entity>
</document>
</dataConfig>
我需要一些线索来检测问题。谁能帮我?提前致谢。
好的,我发现了源代码问题。我已经用十六进制打开了VI的SQL加载脚本。
这是INSERT语句中'Agrónomo'的十六进制内容:41 67 72 6f cc 81 6e 6f 6d 6f。
6f cc 81!!!! This is "o COMBINING ACUTE ACCENT" UTF code!!!!
所以这就是问题所在......它必须是“C3 B3” ......我得到的文本从网页上复制/粘贴,所以在原产地源字符是问题。
感谢你们两位,因为我对SOLR的灵魂有了更多的了解。
问候。
我不认为MySQL或您的jvm设置与此有任何关系。我怀疑一个工程,另一个不可能是由于SpanishLightStemFilterFactory。
正确的方式来实现,无论变音符号是使用以下的匹配:
<charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
将在这两个索引和查询分析器链的标记生成器,以及任何音调符号之前,应转换为ASCII版本。这将使它始终工作。
嗨。它没有工作。相同的结果:( –
转到分析选项卡在bot索引和查询端查看该词的详细输出 – Persimmonium
它是疯了@在Solr Admin中,我选择了我的索引,然后单击Schema部分。字段'occ_tx_name',然后是“加载期限信息”按钮,所以我可以看到列出的前10个术语。我已将10更改为278,以查看所有术语。列表中的每个术语都是HTML锚点,该链接我不能相信我看到... –
只需添加solr.ASCIIFoldingFilterFactory
到您的过滤器分析仪链,甚至更好地创造一个新的字段类型:
<!-- Spanish -->
<fieldType name="text_es_ascii_folding" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory" />
<filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_es.txt" format="snowball" />
<filter class="solr.SpanishLightStemFilterFactory"/>
</analyzer>
</fieldType>
此过滤器将字母,数字和符号的Unicode 字符,这是不是在基本拉丁语的Unicode块(第一个 127个ASCII字符)转换为它们的ASCII等价物(如果存在)。
即使重音字符丢失,也应该让您匹配搜索。 缺点是,像“cañon”和“canon”这样的词现在是相同的,并且都是相同的文件IIRC。
嗨。我已经添加了过滤器“solr.ASCIIFoldingFilterFactory”,但我得到了完全相同的结果... –
你必须重新索引整个集合 – freedev
我忘了提及我正在使用solr-6.3.0,并且使用以下命令启动服务器:solr start -a“-Duser.language = es -Duser.country = ES -Duser.timezone =欧洲/马德里“ –