我有职业索引(标识符+职业):
<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>
我需要一些线索来发现问题。谁能帮我?提前谢谢。
答案 0 :(得分:0)
我不认为mysql或你的jvm设置与此有任何关系。我怀疑一个是有效的,另一个可能不是由于SpanishLightStemFilterFactory。
无论变音符号如何,实现匹配的正确方法是使用以下内容:
<charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
将它放在您的标记器之前的索引和查询分析器链中,并且任何变音符号都应转换为ascii版本。这将使它始终有效。
答案 1 :(得分:0)
只需将solr.ASCIIFoldingFilterFactory
添加到过滤器分析器链中,甚至可以更好地创建新的fieldType:
<!-- 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 不在Basic Latin Unicode块中的字符(第一个 127个ASCII字符)到它们的ASCII等价物(如果存在)。
即使缺少重音字符,也可以让您匹配搜索。 不利的一面是,像“cañon”和“canon”这样的词语现在已经相同,并且都出现了相同的文件IIRC。
答案 2 :(得分:0)
好的,我发现了源问题。我用六进制模式打开了我的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的灵魂有了更多的了解。
问候。