Chris,

Depending on the type of query you want to perform on those structures, it 
sounds more like a <word>, <value> or <range> constraint.  One tutorial you 
might want to look at, in addition to those Mike lists below, is:

http://developer.marklogic.com/howto/tutorials/2009-07-search-api-walkthrough.xqy

That has some information on the different constraint types and how they relate 
to the searches you want to perform.

--Colleen
________________________________________
From: [email protected] 
[[email protected]] On Behalf Of Chris Morgan 
[[email protected]]
Sent: Thursday, March 04, 2010 5:14 AM
To: Michael Blakeley
Cc: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] Help with xQuery Syntax

Thanks, Michael.  After reading about the search API, it does seem like a 
simpler approach.  So in order to perform a google-like search within any Sect1 
or Sect2 in the structure below, I would use a collection constraint -- correct?

Thanks again for your help.

Chris

On Wed, Mar 3, 2010 at 11:42 AM, Michael Blakeley 
<[email protected]<mailto:[email protected]>> wrote:
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><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