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

Functions and subselects in single FLWOR
ReadXml from a Variable SSIS
Read XML values using XmlDocument
splitting xml root into two branches - with option of removing unwanted attributes
how to provide xml input for junit test case
How do I add a timestamp in header manually to a soap XML (WS-Security)?
Convert XML namespaces to top level prefixes using XSLT
How to save xml data to database using mvc4
XSLT group-by throws an error
create one ul after last li
Sort XML to XML using XSLT
Combine value of similar tags to one tag
Node.JS Odd Behavior Receiving Post Data
Having trouble loading images from external XML with states in AS3
XML/ASP: How to get the attribute value for an empty element
How to get distinct values after adding values of few nodes in XQuery?

Categories

HOME
depth
obfuscation
oracle-apex-5
apiblueprint
owl-carousel
vscode-extensions
babeljs
tvos
boto3
discrete-mathematics
p2p
g++
enthought
watson-conversation
plist
openbugs
google-form
stellar.js
null-pointer
google-content-api
google-container-registry
selinux
href
resourcebundle
onload
syntax-highlighting
firebase-analytics
inversion-of-control
vex
realm-mobile-platform
jmockit
hibernate-validator
installshield-le
hibernate-search
imx6
sql-server-ce
ideascript
tex
jvmti
c9.io
portforwarding
apollostack
avcapturedevice
xmldocument
gitlist
dotnet-httpclient
reportservice2010
dbcontext
mongotemplate
trigger.io
offline.js
structuremap4
slackware
cubism.js
parfor
spring-cloud-feign
burrows-wheeler-transform
freepbx
kango-framework
php-socket
httpruntime.cache
phpgrid
rasterize
spring-retry
libvlc
dynamics-nav-2016
opl
tfs-workitem
xenomai
django-urls
xvim
zen-cart
finalbuilder
jquery-forms-plugin
umlgraph
java-security
webmatrix-3
xml-namespaces
ignite-ui
template-deduction
tinyxml
terminate
vbe
maven-scm
multitasking
hidapi
time.h
jquery-1.9
joomla-template
video-codecs
http-status-code-410
bjyauthorize
resource-management
tree-balancing
garbage
hibernateexception
u2netdk
pylucene
photolibrary
load-time
binomial-heap
folding
lxr
purepdf
cuda.net
windows-identity
escrow
online-storage
netbeans6.1

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