A friendly warning: If you care about hit counts then apparently you need to 
break your document up such that the desired hit level is a document itself. I 
used the approach outlined below and it works fine but I was always returned a 
total hit count of 1...even when I had many hits for a search. Some helpful 
people on this forum explained that this is because search:search and 
cts:search count the number of documents which contain a hit, not the number of 
hits themselves...apparently something to do with the way the indexes are 
built. My document initially was a large document containing many diary 
entries, but because in my application I need searches to return diary entries 
as hits, and because I do care about the hit count, I now have to split my 
original document up and make each diary entry its own document.

Perhaps this doesn't apply to you but I thought I'd give you a heads-up just in 
case.

Adam

From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Steiner, David J. 
(LNG-DAY)
Sent: March 26, 2010 11:26 AM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] RE: search:search options constraints

Yep...  searchable-expression gives me my XPath requirement for searching and I 
can restrict to a particular collection using additional-query...

Thanks!!!
David

From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Adam Patterson
Sent: Friday, March 26, 2010 10:12 AM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] RE: search:search options constraints

Hi, I'm a noob with XQuery and MarkLogic as well, but I've recently figured out 
how to do something along the lines of what you're after. I use the following 
options to search a TEI document and define the hits to be a particular node 
level inside the document:

<options xmlns="http://marklogic.com/appservices/search";>

                <!-This restricts the search to a particular URI, otherwise you 
will get hits from every document in your database. -->
                
<additional-query>{cts:document-query(/URI/to/the/document/I/want/to/search/document.xml)}</additional-query>

                <!-This searchable expression defines the level of my hits to 
the <div> tags in the body of my diary. -->
                <searchable-expression 
xmlns:tei="http://www.tei-c.org/ns/1.0";>{/tei:teiCorpus/tei:t...@xml:id=&quot;diary-ljb-1879-1881-1&quot;]/tei:te...@type=&quot;diary&quot;]/tei:body/tei:div}</searchable-expression>
</options>



You should try to set up your options with something like the following:

<options xmlns="http://marklogic.com/appservices/search";>

                
<additional-query>{cts:document-query(/URI/to/the/document/I/want/to/search/document.xml)}</additional-query>

                <searchable-expression 
xmlns:tei=http://www.my.namespace/ns/1.0>{//p[starts-with(ref:anchor/@id, 
"para_")]}</searchable-expression>

</options>

Good luck,

Adam


From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Steiner, David J. 
(LNG-DAY)
Sent: March 25, 2010 5:24 PM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] RE: search:search options constraints

Right, that's actually what I'm looking for - how to do what I want using the 
search API, not XPath.

From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Stewart Shelline
Sent: Thursday, March 25, 2010 4:33 PM
To: General Mark Logic Developer Discussion
Subject: [MarkLogic Dev General] RE: search:search options constraints

Another way to do this is in the <additional-query> element of search:search. 
You can use it to build complex queries using any of the cts:query 
functions-assuming you have the appropriate indexes set up.

From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Keith L. Breinholt
Sent: Thursday, March 25, 2010 1:34 PM
To: General Mark Logic Developer Discussion
Subject: [MarkLogic Dev General] RE: search:search options constraints

// p[starts-with(ref:anchor/@id, "para_")]/text[fn:contains( "sometext",  .)]

Keith L. Breinholt
breinhol...@ldschurch.org<mailto:breinhol...@ldschurch.org>

From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Steiner, David J. 
(LNG-DAY)
Sent: Thursday, March 25, 2010 1:21 PM
To: general@developer.marklogic.com
Subject: [MarkLogic Dev General] search:search options constraints

I have an XML structure like this:

...

                            <p xmlns="namespace1">

                                <ref:anchor id="para_2" xmlns:ref="namespace2"/>

                                <text>This is a bunch of text that I want to 
search.</text>

                            </p>

...

I want to search for words (multiple terms: word1 AND word2 AND word3) in the 
<text> element of the <p> elements where the <ref:anchor>@id starts with the 
string "para_".

<text> elements appear elsewhere and <p> elements do to...  and there are other 
types of id values, such as "subpara_..."

I'm trying to use search:search and I see how to constrain to a specific 
element or attribute (or collection, etc.), but how do you do more complex 
things - i.e., constrain to a specific element under a specific parent where a 
sibling's attribute starts with a particular string?

Hopefully I've been clear - the XPath of the element I want to search: // 
p[starts-with(ref:anchor/@id, "para_")]/text

Thanks,
David Steiner
Consulting Research Scientist
Global Architecture & Research iLabs
LexisNexis Group
david.j.stei...@lexisnexis.com<mailto:david.j.stei...@lexisnexis.com>
Toll Free:    800-227-9597 ext. 51894
Direct:        937-865-1894



NOTICE: This email message is for the sole use of the intended recipient(s) and 
may contain confidential and privileged information. Any unauthorized review, 
use, disclosure or distribution is prohibited. If you are not the intended 
recipient, please contact the sender by reply email and destroy all copies of 
the original message.

_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general

Reply via email to