<?vsp 
--  
--  $Id: text.vsp,v 1.2 2006/08/15 19:30:35 source Exp $
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2006 OpenLink Software
--  
--  This project is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; only version 2 of the License, dated June 1991.
--  
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--  General Public License for more details.
--  
--  You should have received a copy of the GNU General Public License along
--  with this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--  
--  
?>
<html>
	<head><?vsp http(XQ..GET_SCRIPT()); ?> </head>
	<body>

	<h3>Text search using 'contains' predicate in "http://local.virt/DAV/feeds/" collection:</h3>
<?vsp
 declare _q , _sid, _realm, _sid_arg varchar;
 _sid := coalesce ({?'sid'}, '');
 _realm := coalesce ({?'realm'}, '');
 if ({?'sid'} is not null)
   _sid_arg := '?sid=' || _sid || '&realm=' || _realm;

 _q := coalesce ({?'q'}, '');
?>
 <form method="GET" action="text.vsp">
 	<input name="sid" type="hidden" value="<?=_sid?>"/>
	<input name="realm" type="hidden" value="<?=_realm?>"/>
	<input name="q" type="text" value="<?= _q ?>" />
	<input name="submit" type="submit" value="Search" />
 </form>
 <a href="search.vsp?sid=<?= _sid ?>&realm=<?= _realm ?>"> XPath Search </a>

<?vsp
if (_q <> '') {
	declare _res any;
	_res := xquery_eval ('
<ul> {
for \044d in collection ("http://local.virt/DAV/feeds/", ., 1, 2)
   for \044item in \044d//item[contains (descendant::*,"' || _q || '")]
   let \044link :=  \044item/link/string()
   let \044title := \044item/title/string()
 	return
  	 <li>
  	 {
  	 	 if (\044link and \044title) then
				 <a href="{\044link}" target="_blank">{\044title}</a>
		   else if (\044link) then
				 <a href="{\044link}" target="_blank">~empty title~</a>
		   else if (\044title) then
			 	 <div>{\044title}</div>
		   else
			 	 <div>~empty title~</div>
		}
  	 </li>
} </ul>', xtree_doc ('<stub/>'));
		http ('<br/>');
		declare _num int;
		_num := 0;
		if (isentity (_res))
		  _num := cast (xpath_eval ('count(/ul/li)', _res) as int);
		if (_num = 0)
		  http ('No results found');
	 	else
		  http (sprintf ('[%d] results found:<br/>', _num));
		http (serialize_to_UTF8_xml (_res));
 }
 ?>

</body>
</html>
