[英]Marklogic JSON document field index
I have a ML database with all json documents.. I am having an issue with field creation for this documents.. Say I have a document 我有一个包含所有json文档的ML数据库..我对这些文档的字段创建有问题。说我有一个文档
{
"id": "1452016",
"name": "ALEXA488",
"identifyingInfo": {
"preparation": {
"chemicalConjugations": [{
"name": "ALEXA 488"
}]
}
}
}
I created a field for top level json element name
.. 我为顶级json元素
name
创建了一个字段。
{
"field-name": "concept_name",
"field-path": [
{
"path": "/name",
"weight": 1
}
],
"word-lexicon" :["http://marklogic.com/collation/en/S1"]
}
I created a field range index as well on this field.. 我也在这个字段上创建了一个字段范围索引。
Now when I do the search like this 现在当我像这样进行搜索时
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
let $search := ' (concept_name:(*ALEXA*))'
let $options :=
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="collection">
<collection prefix=""/>
</constraint>
<constraint name="concept_name">
<word>
<field name="concept_name" collation="http://marklogic.com/collation/en/S1"/>
</word>
</constraint>
<term>
<term-option>case-insensitive</term-option>
<term-option>punctuation-insensitive</term-option>
<term-option>whitespace-insensitive</term-option>
<term-option>wildcarded</term-option>
</term>
<return-facets>false</return-facets>
<return-values>false</return-values>
<return-constraints>false</return-constraints>
<return-frequencies>false</return-frequencies>
<return-qtext>false</return-qtext>
<search-option>format-json</search-option>
<search-option>score-simple</search-option>
</options>
let $start := 1
let $page-length :=1
let $result := search:search($search, $options, $start, $page-length)
return $result
The search is matching the top level name
and also identifyingInfo/preparation/chemicalConjugations/name
.. 搜索匹配顶级
name
以及identifyingInfo/preparation/chemicalConjugations/name
..
What should be the field path, so that it only matches the top level json element, in this case name
? 什么应该是字段路径,以便它只匹配顶级json元素,在这种情况下
name
?
Your field path looks fine. 您的现场路径看起来很好。 You can check that with
你可以检查一下
cts:field-value-match("concept_name", "*")
But you're trying to use wildcards. 但是你正在尝试使用通配符。 Did you enable "trailing wildcard searches" on your field?
您是否在您的字段上启用了“尾随通配符搜索”? Do you also want "one/two/three character searches" enabled?
你还想要启用“一/二/三字符搜索”吗?
I got this to work. 我得到了这个工作。 Replace your constraint with:
用以下内容替换约束:
<constraint name="concept_name">
<value>
<field name="concept_name" />
</value>
</constraint>
In your field, turn on field value searches and trailing wildcard searches . 在您的字段中,启用字段值搜索和尾随通配符搜索 。
I created three docs in a database; 我在数据库中创建了三个文档; one just like your sample, one that had "ALEXA" only in /name, and one that had "ALEXA" only in the other name.
一个就像你的样本,一个只在/ name中有“ALEXA”,另一个在另一个名称中只有“ALEXA”。 My test correctly found the two documents.
我的测试正确找到了两个文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.