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

XSLT - How to combine XSLT files
Validating userId with XML Schema
Using Oracle XMLElement in complex PL/SQL
Change Order Status Magento by Customer
XPath: Default to 'Node A', select 'Node B' instead if 'Node B' is not empty
vba:save the result xml file to certain path
Unmarshal Group with Nested XML-RPC in Go
Xcode: XML parser grouping
Get all ancestors of current node
If result document already exists, skip transformation
i want to develop xml to json and json to xml convertor in java
MERGE command with multiple rows to insert or update
using Substring in Xpath expression in apache camel: error
xslt summing the totals in an invoice [closed]
Depth First Reading of large XML Files
Always return element value from current node with XPath

Categories

HOME
shell
algorithm
grok
azure-stream-analytics
developer-tools
jmeter
github-for-windows
nunit
numbers
owl-carousel
nuget
emscripten
mapbox
jquery-ui
missing-data
odoo-8
syntaxnet
reactive-programming
emoji
renjin
cumulocity
coin3d
linear-algebra
symfony-2.8
fileserver
apache2.4
selinux
sar
squashfs
href
inno-download-plugin
angular-routing
ckfinder
jackson-modules
asymptotic-complexity
linked-data
gp
cart
erb
hibernate-search
servicestack-text
xajax
protege4
raft
hivemq
reason
watchman
recurrent-neural-network
gdata
metaprogramming
comparison-operators
xv6
trigonometry
skylink
android-checkbox
apache-directory
snapchat
jboss-4.2.x
ovf
openal
wcftestclient
twilio-click-to-call
mongotemplate
carrot2
pair-programming
tinkerpop
java-bytecode-asm
otp
offline.js
baidu
branch-prediction
swizzling
jtwig
http-status-code-401
aurora
fuzzywuzzy
fink
grass
false-sharing
rasterize
directdraw
sapi
pypiserver
phonertc
opserver
binomial-theorem
visual-sourcesafe-2005
liquid-layout
snackbar
kubuntu
packet-sniffers
android-cookiemanager
sonarqube-5.0
big-ip
contrast
imagefilter
template-deduction
cancellation
authlogic
vbe
decoupling
solace-mq
jammer
kendo-dataviz
breakout
jeromq
curb
frameworkelementfactory
qi4j
thttpd
oracle-enterprise-linux
cgimage
catransform3d
django-paypal
ruby-1.8
eclipse-marketplace
opml
skype4java
tui
wordprocessingml
contentpresenter
mathematical-typesetting

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