我试图解决的问题是我有一堆与数学表达式/公式相关的文档。我想通过公式或表达式搜索文档。
到目前为止,根据我的研究,我正在考虑将数学表达式转换为乳胶格式并作为字符串存储在数据库中(弹性搜索)。
通过这种方法,我可以搜索带有乳胶字符串的文档吗?
a2 + b2 = c2 的乳胶转换示例为 a^{2} + b^{2} = c^{2} 。这个字符串可以在弹性搜索中搜索到吗?
我同意用户@Lue E 的一些修改,并尝试使用简单的关键字方法,但给了我一些问题,因此我修改了使用方法keyword
我自己的分词器定制分析仪 https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-custom-analyzer.html这应该可以解决您的大多数用例。
使用自定义分析器索引 def
{
"settings": {
"analysis": {
"analyzer": {
"my_custom_analyzer": {
"type": "custom",
"tokenizer": "keyword", --> to make it searchable
"filter": [
"lowercase", --> case insensitive search
"trim" --> remove extra spaces
]
}
}
}
},
"mappings": {
"properties": {
"mathformula": {
"type": "text",
"analyzer": "my_custom_analyzer"
}
}
}
}
索引示例文档
{
"mathformula" : "(a+b)^2 = a^2 + b^2 + 2ab"
}
{
"mathformula" : "a2+b2 = c2"
}
搜索查询(匹配查询,使用索引时间相同的分析器)
{
"query": {
"match" : {
"mathformula" : {
"query" : "a2+b2 = c2"
}
}
}
}
搜索结果仅包含第一个索引文档
"hits": [
{
"_index": "so_math",
"_type": "_doc",
"_id": "1",
"_score": 0.6931471,
"_source": {
"mathformula": "a2+b2 = c2"
}
}
]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)