Chris,

Why not use the higher-level search:search() API? The function reference page is http://developer.marklogic.com/pubs/4.1/apidocs/SearchAPI.html#search:search

The Search Developer's Guide (http://developer.marklogic.com/pubs/4.1/books/search-dev-guide.pdf) has more about the high-level search API.

If you need to use the lower-level cts:search() API for some reason, start with http://developer.marklogic.com/howto/tutorials/ and the "Paginated Search for Web Applications" tutorial.

-- Mike

On 2010-03-03 03:38, Chris Morgan wrote:
Hello,

I'm new to MarkLogic and am having trouble getting a search query to work 
properly.  Specifically, I'm attempting to build a simple query of a DocBook 
style document.  The structure of the document is as follows:

<article>
      <sect1>
      <title>The first title</sect1>
      <para>a paragraph of text</para>
<sect2>
<title>The first title</sect1>
   <para>a paragraph of text</para>
  </sect2>
     </sect1>
</article>

My goal is to build a simple search tool that will search through all<sect1>  
and<sect2>  elements and find any paragraph containing the search term.  I'd like to 
return:

<a href="somelink.xqy">Section Title</a>
<p>Paragraph text with<span class="highlight">highlighted search term</span>  in 
it.</p>

The problem is that when I loop through the paragraphs containing the search 
term, I return every sect1 or sect2 title, regardless of whether that title 
contains para elements with the search term.

Here's what I have so far:

=======================================
xquery version "1.0-ml";

xdmp:set-response-content-type("text/html"),
<html>
<body>
<head>
<link rel="stylesheet" type="text/css" href="affect.css" />
</head>
<div class="container">
<div class="topNav">
<form method="GET" action="searchtest3.xqy" id="searchForm">
  <input type="hidden" name="start" id="start" value="1"/>
<input type="text" name="search" size="43" maxlength="256" value=""/>
<input type="submit" name="button" value="search"/>
</form>
</div>
{let $searchTerm := xdmp:get-request-field("search")
let $query := cts:query(<cts:word-query 
xmlns:cts="http://marklogic.com/cts";><cts:text>{$searchTerm}</cts:text></cts:word-query>)

for $newresults in (//sect1|//sect2)
where cts:contains(($newresults//para), $query)
return
<div>
<a href="www.google.com<http://www.google.com>" 
class="searchResult">{$newresults/title/text()}</a>
{
for $para in $newresults/para
where cts:contains($para, $query)
return
<p>{cts:highlight($para[1],$query,<span 
class="highlight">{$cts:text}</span>)}</p>
}
</div>}
</div>
</body>
</html>
=======================================

Thanks for your help!

Chris


_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to