我要解决的问题是,我有一堆有关数学表达式/公式的文档。我想按公式或表达式搜索文档。
到目前为止,根据我的研究,我正在考虑将数学表达式转换为乳胶格式,并作为字符串存储在数据库中(弹性搜索)。
通过这种方法,我可以搜索带有乳胶字符串的文档吗?
a2 + b2 = c2的示例乳胶转换为a ^ {2} + b ^ {2} = c ^ {2}。可以在弹性搜索中搜索此字符串吗?
我同意用户@Lue E,进行了更多修改,并尝试了一种简单的关键字方法,但给了我一些问题,因此我修改了在自己的keyword
中使用custom analyzer标记生成器的方法,该方法可以解决您的大多数问题用例。
{
"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"
}
}
]