如何让海王星搜索更宽松
How to make Neptune Search more lenient
我正在搜索的图表中有一些条目(例如 hello_world
、foo_bar_baz
),我希望能够搜索“hello”并返回 hello_world。
目前,如果我搜索整个字符串(即搜索 hello_world
或 foo_bar_baz
),我只会得到结果
这似乎是由于 elasticsearch 的标准分析器行为,但我不知道如何使用 Neptune 来处理这个问题。
with neptune_graph() as g:
my_query = " OR ".join(
f"predicates.{field}.value:({query})" for field in ['names', 'spaces']
)
search_results = (
g.withSideEffect(
"Neptune#fts.endpoint", f"https://{neptuneSearchURL}"
)
.withSideEffect("Neptune#fts.queryType", "query_string")
.withSideEffect("Neptune#fts.sortOrder", "DESC")
.V()
.hasLabel("doc")
.has(
"*",
f"Neptune#fts entity_type:table AND ({my_query})",
)
)
一种方法是使用通配符。
鉴于:
g.addV('search-test').property('name','Hello_World')
v[0ebedfda-a9bd-e320-041a-6e98da9b1379]
假设搜索集成都已到位,更新搜索索引后,将找到顶点:
g.withSideEffect("Neptune#fts.endpoint",
"https://vpc-neptune-xxx-abc123.us-east-1.es.amazonaws.com").
withSideEffect('Neptune#fts.queryType', 'query_string').
V().
has('name','Neptune#fts hello*').
elementMap().
unfold()
产生
{<T.id: 1>: '0ebedfda-a9bd-e320-041a-6e98da9b1379'}
{<T.label: 4>: 'search-test'}
{'name': 'Hello_World'}
我遇到的问题确实是分析器,只是直到现在我才明白如何解决它。
最初创建elasticsearch索引时,需要设置你想要的设置。
解决方案是使用
创建索引
with neptune_search() as es:
es.indices.create(index="my_index", body={/*set custom analyser here*/});
es.index(index="my_index", ... other stuff);
# example of changing the analyser (needs "" around keys and values)
#body={
# settings:{analysis:{analyzer:{default:{
# type: custom,
# tokenizer:"lowercase"
# }}}}
#}
我正在搜索的图表中有一些条目(例如 hello_world
、foo_bar_baz
),我希望能够搜索“hello”并返回 hello_world。
目前,如果我搜索整个字符串(即搜索 hello_world
或 foo_bar_baz
),我只会得到结果
这似乎是由于 elasticsearch 的标准分析器行为,但我不知道如何使用 Neptune 来处理这个问题。
with neptune_graph() as g:
my_query = " OR ".join(
f"predicates.{field}.value:({query})" for field in ['names', 'spaces']
)
search_results = (
g.withSideEffect(
"Neptune#fts.endpoint", f"https://{neptuneSearchURL}"
)
.withSideEffect("Neptune#fts.queryType", "query_string")
.withSideEffect("Neptune#fts.sortOrder", "DESC")
.V()
.hasLabel("doc")
.has(
"*",
f"Neptune#fts entity_type:table AND ({my_query})",
)
)
一种方法是使用通配符。
鉴于:
g.addV('search-test').property('name','Hello_World')
v[0ebedfda-a9bd-e320-041a-6e98da9b1379]
假设搜索集成都已到位,更新搜索索引后,将找到顶点:
g.withSideEffect("Neptune#fts.endpoint",
"https://vpc-neptune-xxx-abc123.us-east-1.es.amazonaws.com").
withSideEffect('Neptune#fts.queryType', 'query_string').
V().
has('name','Neptune#fts hello*').
elementMap().
unfold()
产生
{<T.id: 1>: '0ebedfda-a9bd-e320-041a-6e98da9b1379'}
{<T.label: 4>: 'search-test'}
{'name': 'Hello_World'}
我遇到的问题确实是分析器,只是直到现在我才明白如何解决它。
最初创建elasticsearch索引时,需要设置你想要的设置。
解决方案是使用
创建索引with neptune_search() as es:
es.indices.create(index="my_index", body={/*set custom analyser here*/});
es.index(index="my_index", ... other stuff);
# example of changing the analyser (needs "" around keys and values)
#body={
# settings:{analysis:{analyzer:{default:{
# type: custom,
# tokenizer:"lowercase"
# }}}}
#}