Hello,

I'm working on a JSP app to do search function for term in the entire 
collection. I'm using the JSP Taglib.

I can search for term in specific element, however I want to search for all 
elements and return just that element with the term highlighted. The 
cts:search(collection()//(p|h1|h2), $query in the snippet below is not ideal 
where all element name have to be specified. I tried using 
cts:search(collection()//* but it return data including the parent elements.

Is there a recommended way to doing full-text search? I'm open to suggestion.

<% String term = request.getParameter("term"); %>
<h2>Result:</h2>
      <xq:execute>
            <xq:query>
                  declare namespace ns1="http://example/ns1";;
                  declare namespace ns2="http://example/ns2";;
                  declare variable $search_term external;

                  let $query := cts:or-query(tokenize($search_term, ' '))
                  for $p in 
cts:search(collection()//(p|h1|h2|b|i|ns1:para|ns2:paragraph), $query)[1 to 30]
                  return
                  <div>
                  { cts:highlight($p, $query, <font 
color="yellow"><b>{$cts:text}</b></font>) }
                  <span> (found in: <b>{fn:base-uri($p)}</b></span>
                  </div>
            </xq:query>
            <xq:variable localname="search_term" type="xs:string" 
value="${param.term}"/>
      </xq:execute>
</div>


Thank you!

Swee-Doon Goh

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

Reply via email to