xml


constrain search:search query to specific element


I'm having trouble trying to specify the search parameters to only search a specific xml element within my files. Here is the file that I am using to search on:
<file>
<title>red</title>
<info>
<section>blurbs</section>
<section>words</section>
</info>
<info>
<section>first</section>
<section>this</section>
</info>
<info>
<section>blue</section>
<section>green</section>
</info>
<info>
<section>red</section>
<section>yellow</section>
</info>
</file>
The search:search query I'm using is:
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
let $options :=
<options xmlns="http://marklogic.com/appservices/search">
<additional-query>
<cts:document-query depth="infinity" xmlns:cts="http://marklogic.com/cts">
<cts:uri>/test_data/test_search.xml</cts:uri>
</cts:document-query>
</additional-query>
<extract-document-data selected="include">
<extract-path>/file/info</extract-path>
</extract-document-data>
<constraint>
<word>
<element name="info"/>
</word>
</constraint>
<search-option>filtered</search-option>
</options>
let $results := search:search("red", $options)
the $results variable contains:
<search:response snippet-format="snippet" total="1" start="1" page-length="10" selected="include" xmlns:search="http://marklogic.com/appservices/search">
<search:result index="1" uri="/test_data/test_search.xml" path="fn:doc("/test_data/test_search.xml")" score="8448" confidence="0.4065818" fitness="0.8925228">
<search:snippet>
<search:match path="fn:doc("/test_data/test_search.xml")/file">
<search:highlight>red
</search:highlight>
</search:match>
<search:match path="fn:doc("/test_data/test_search.xml")/file/info[4]">
<search:highlight>red
</search:highlight>
</search:match>
</search:snippet>
<search:extracted kind="element">
<info>
<section>blurbs
</section>
<section>words
</section>
</info>
<info>
<section>first
</section>
<section>this
</section>
</info>
<info>
<section>blue
</section>
<section>green
</section>
</info>
<info>
<section>red
</section>
<section>yellow
</section>
</info>
</search:extracted>
</search:result>
<search:qtext>red
</search:qtext>
<search:metrics>
<search:query-resolution-time>PT0.00166S
</search:query-resolution-time>
<search:snippet-resolution-time>PT0.000992S
</search:snippet-resolution-time>
<search:extract-resolution-time>PT0.00049S
</search:extract-resolution-time>
<search:total-time>PT0.003748S
</search:total-time>
</search:metrics>
</search:response>
As you can see red is hit on title and info, but I only want to search on the xml info element. What am I doing wrong here?
EDIT: I have a small understanding of contraint searching IE search:search("title:red") but what happens when that contraint is multiple words?
When creating a constraint, you should assign a name to it, as in:
<constraint name="inf">
That's what makes it possible to tag terms in query text as in inf:red
For more detail see:
http://docs.marklogic.com/guide/search-dev/appendixa#id_58121
You can also specify a default treatment for untagged search terms using the search:term element:
http://docs.marklogic.com/guide/search-dev/appendixa#id_31590
To understand the query generated from query text, it can be helpful to set the debug or return-query options to true:
http://docs.marklogic.com/guide/search-dev/appendixa#id_60243 h
http://docs.marklogic.com/guide/search-dev/appendixa#id_68047
By the way, you can use fn:doc() to retrieve any document and use XPath or search:snippet() to extract nodes from a document. The search:search() function isn't designed for retrieving a document by URI.
Finally, if possible, you might want to modify the document model. MarkLogic can provide more useful indexing for documents where:
The documents are granular with a focus on a single entity instead of a list of entities
The element names reflect the semantics of the data (instead of using generic element names)
Hoping that helps,

Related Links

XSD specifies a target namespace but XML doesn't - can I avoid editing either?
Having trouble adding text after my XML Root from TSQL to XML
Swift write contents of XML that uses single quote: '
Search in xml using xpath in postgresql db
MSBuild: How to update xml by xpath
Improving XML to record
Getting a 400 Bad request in Postman with application/xml request
XQuery HTML array input
how to change nodename with XSLT
xml to string and string to xml
Generate XML and XSD documents using one XSLT
Impact of XSD Element defined with no type
xmlstarlet: select attribute if child exists
Liquid XML writes odd chars  on the front of the file my xml file
Process XSLT output with XSLT in the same document, flat data to tree nodeset
How to shows Records entry count one2many field view in odoov8

Categories

HOME
phantom-dsl
search
twitter-bootstrap-3
adal
jpa
eslint
webdriver
apache-spark-mllib
error-handling
seo
parameters
bookmarks
title
rcloud
owin
naivebayes
openbugs
stellar.js
3nf
mongodb-csharp
asp.net-mvc-viewmodel
nim
replication
simpleitk
asciidoctor-pdf
ag
string-concatenation
qliksense
object-storage
scriptella
google-cloud-print
genexus-sd
ceylon
paperjs
google-earth
finagle
corenlp-server
volatile
scatter3d
zend-debugger
mockjax
fstream
numpy-broadcasting
wurfl
diacritics
sharp-snmp
photos
robomongo
hammer.js
facebook-pixel
mongotemplate
payara-micro
appdomain
otp
janus
cpu-cache
cd-burning
rocks
parfor
jodd
avspeechsynthesizer
http-status-code-401
beanstalk
kendo-upload
design-principles
spring-retry
grgit
lazybones
zscript
snoop
node-serialport
android-broadcast
j-security-check
document-repository
infosphere-spl
ejb-2.x
webmatrix-3
teaspoon
xml-namespaces
windows-embedded-standard
kendo-dataviz
breakout
inputmismatchexception
cnf
node-blade
pclzip
wp7test
http-status-code-410
asplinkbutton
dopostback
qtconcurrent
uimanageddocument
faye
pyunit
jsr286
wiimote
virtualpathprovider
apache-commons-dbutils
user-tracking
promotion-code
mysql-error-1205
load-time
instantiationexception
maven-1
aspmenu
isapi-extension
application-verifier
echo3
linfu-dynamicproxy
xslcompiledtransform
cardspace
idatareader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App