使用 Apache Solr 进行半自然语言搜索

Semi Natural language Search using Apache Solr

我对 Apache Solr 做了一些分析,它非常适合从各种来源搜索数据。 我面临的问题是如何标准化我的搜索语法并将搜索文本翻译成 Solr 查询。

我有三种类型的 file/database table 可供搜索 - 即客户、行业和单位。搜索框中的第一个关键字应该是三个中的任何一个。之后,用户可以定义一组固定的标准:

Metrics : 0 or many (ex, exposure, income, revenue, loan_amt etc)
Dimension : 0 or many (Geography, region, etc)

示例:

customer - Returns all customer data from customer core
customer income from Asia - Returns all customer income details who belongs to Asia 
customer income revenue from Asia - Returns all customer income and revenue details who belongs to Asia 

如何将上述自然语言搜索文本翻译成 solr 查询? 我可以在 Solr 中修复我的文本语法吗 第一个关键字应该是 customer/industry/unit, 第二个键值将是一个或多个 region/geography 然后是度量值。

我不是在寻找 google 之类的搜索,而是一种用户知道要搜索什么的有限搜索。

为了不陷入NLP的问答领域,这被认为是NLP最难的领域,也许可以尝试定义你的问题的语法,例如X in Y with Z,其中X可以不同像客户这样的实体,Y 可以是某个地理位置,Z 是一个过滤器。

严格来说,这似乎不是 Solr 问题。作为第一步,您可能希望根据输入的特定生产规则定义 context-free grammar(CFG,类型 2 语法)。这将为您提供一些可靠的语法规则。基于此,您可以为自然语言输入创建一个解析器,并将生成的解析树映射到 Solr 中的关键字搜索。