简体   繁体   English

Arango 通配符查询

[英]Arango wildcard query

I am working on building a simple arango query where if the user enters: "foo bar" (starting to type Foo Barber), the query returns results.我正在构建一个简单的 arango 查询,如果用户输入:“foo bar”(开始输入 Foo Barber),查询将返回结果。 The issue I am running in to is going from a normal single space separated string (ie imagine LET str = "foo barber" at the top), to having multiple wildcard queries like shown below.我遇到的问题是从普通的单个空格分隔的字符串(即想象顶部的 LET str = "foo barber")到有多个通配符查询,如下所示。

Also, open to other queries that would work for this, ie LIKE, PHRASE or similar.此外,对适用于此的其他查询开放,例如 LIKE、PHRASE 或类似的查询。

The goal is when we have a single string like 'foo bar', search results are returned for Foo Barber and similar.目标是当我们有一个像 'foo bar' 这样的字符串时,返回 Foo Barber 和类似的搜索结果。

    FOR doc IN movies SEARCH PHRASE(doc.name,
[
   {WILDCARD: ["%foo%"]},
   {WILDCARD: ["%bar%"]}
], "text_en") RETURN doc

If you want to find Black Knight but not Knight Black if the search phrase is black kni , then you should probably avoid tokenizing Analyzers such as text_en .如果您想在搜索短语是black kni时找到Black Knight而不是Knight Black ,那么您可能应该避免对诸如text_en类的分析器进行标记。

Instead, create a norm Analyzer that removes diacritics and allows for case-insensitive searching.相反,创建一个norm分析器来删除变音符号并允许不区分大小写的搜索。 In arangosh:在阿兰戈什语中:

var analyzers = require("@arangodb/analyzers");
analyzers.save("norm_en", "norm", {"locale": "en_US.utf-8", "accent": false, "case": "lower"}, []);

Add the Analyzer in the View definition for the desired field (should be title and not name , shouldn't it?).在所需字段的视图定义中添加分析器(应该是title而不是name ,不是吗?)。 You should then be able to run queries like:然后,您应该能够运行以下查询:

  • FOR doc IN movies SEARCH ANALYZER(STARTS_WITH(doc.title, TOKENS("Black Kni", "norm_en")[0]), "norm_en") RETURN doc
  • FOR doc IN movies SEARCH ANALYZER(LIKE(doc.title, TOKENS("Black Kni%", "norm_en")[0]), "norm_en") RETURN doc
  • FOR doc IN movies SEARCH ANALYZER(LIKE(doc.title, CONCAT(TOKENS(SUBSTITUTE("Black Kni", ["%", "_"], ["\\%", "\\_"]), "norm_en")[0], "%")), "norm_en") RETURN doc

The search phrase Black Kni is normalized to black kni and then used for a prefix search, either using STARTS_WITH() or LIKE() with a trailing wildcard % .搜索短语Black Kni被规范化为black kni ,然后用于前缀搜索,使用STARTS_WITH()LIKE()与尾随通配符% The third example escapes user-entered wildcard characters.第三个示例转义用户输入的通配符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM