Reputation: 1179
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
{
"id": "1452016",
"name": "ALEXA488",
"identifyingInfo": {
"preparation": {
"chemicalConjugations": [{
"name": "ALEXA 488"
}]
}
}
}
I created a field for top level json element 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
..
What should be the field path, so that it only matches the top level json element, in this case name
?
Upvotes: 1
Views: 105
Reputation: 8422
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. My test correctly found the two documents.
Upvotes: 0
Reputation: 2475
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?
Upvotes: 0