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

Parsing UTF-8-encoded XML in MSXML/ASP
is it possible to script a .XML file
Encrypt ccnet.config TFS login details
Getting location of XML document in XQuery
Escape quote character in xml
Tiny Flash Question
AS3: How to get all XML-Nodes with a special attribute? (With sourch)
How to avoid parameter with all within?
Wrong Mixed Character Encoding in XML
Exporting excel to xml spreadsheet with blank cells
XSLT: tricky transformation, suggestions?
How do I escape unicode character 0x1F in xml?
How to force visio to re-evalute formulas when an untrusted visio document is opened
How to design storing complex object settings in an xml
Storedprocedure returns xml but linq replaces ' " ' with '\'
How to realize derived response (XSD)?

Categories

HOME
grok
angular-formly
zend-framework
toolbox
package
spring-data-redis
shiro
appcelerator
rds
cq5
telegram-bot
spin
naivebayes
pybossa
flatpak
atlassian-stash
asp.net-mvc-viewmodel
imessage
oledb
asp.net-core-webapi
lilypond
googlebot
blade
springfox
libigl
mongoid6
qliksense
epsilon
interpreter
xunit
game-theory
data.stackexchange.com
maze
fractions
angular-translate
jaws
calculation
livelink
erb
android-maps-extensions
joomla2.5
reverse
arduino-ide
mongoose-schema
magento-1.9.3
skylink
attributeerror
preloader
ssrs-2014
nanoc
geotiff
context-switch
ampps
cronexpression
docpad
seek
windows-azure-queues
jquery-jscrollpane
delta
swizzling
blitline
toast
page.js
pax-exam
sony-lifelog-api
viola-jones
haskell-warp
android-broadcast
cakephp-2.7
broadband
big-ip
sql-scripts
webfinger
cbind
rmysql
jqmodal
unix-socket
decoupling
sbcl
printdialog
uimanageddocument
veracity
cakephp-1.2
floating-point-exceptions
stress
quotation-marks
non-clustered-index
web-garden
pagemethods
django-piston
cuda.net
software-lifecycle
int64

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