Hi,
i'm creating a simple search-form for my exist-db
and therefor i need to interchange some details in my query dynamicly. At the
moment i've got only one input-field for my searchterm and while entering i will
provide the user possible terms out of the index files from the
exist-db.
Here is my exist-query:
instance('term-suggestion-query'
<exist:query
xmlns:exist="http://exist.sourceforge.net/NS/exist">
<exist:text>
xquery version "1.0";
declare namespace f=http://exist-db.org/xquery/test;
declare namespace mods=http://www.loc.gov/mods/v3;
import module namespace t=http://exist-db.org/xquery/text;
import module namespace util=http://exist-db.org/xquery/util;
import module namespace request=http://exist-db.org/xquery/request;
define function f:term-callback($term as xs:string,
$data as xs:int+)
as element()+ {
<li
class="LSRow">
<a
href="'{$term}">
<span class="term">{$term}</span>
({$data[2]} hits)
</a>
</li>,
if ($data[3] eq 15)
then
<li
class="LSRow">
<span style="margin-left:
1em;">...</span>
</li>
else ()
};
let $t := request:get-parameter("query",
('love')),
let $collection :=
request:get-parameter("collection", "/db")
return
<ul class="LSRes">
{
t:index-terms(collection($collection), $t, util:function("f:term-callback",
2), 15)
}
</ul>
</exist:text>
</exist:query>
My searchfield:
<xforms:select1
ref="instance('parameters-instance')/term" selection="open"
incremental="true"
appearance="xxforms:autocomplete"
class="search-field">
<xforms:itemset
nodeset="instance('search-query')//span">
<xforms:label ref="."/>
<xforms:value ref="."/>
</xforms:itemset>
<!-- Run the 'suggest'
submission as text being typed -->
<xforms:action
ev:event="xforms-value-changed">
<xforms:recalculate/>
<xforms:send submission="update-term-suggestion"/>
</xforms:action>
</xforms:select1>
My submission is the following:
<xforms:submission id="update-term-suggestion"
ref="instance('term-suggestion-query')"
method="post"
action="{{xxforms:instance('exist-instance')//main}}/" replace="instance"
xxforms:instance="search-instance" f:url-type="resource"/>
parameters.xml:
<parameters>
<term/>
</parameters>
An example return on my query is:
<exist:result exist:hits="1" exist:start="1" exist:count="1"
xmlns:exist=http://exist.sourceforge.net/NS/exist>
<terms>
<ul class="LSRes">
<li class="LSRow">
<a href="as">
<span class="term">as</span>(1
hits)
</a>
</li>
<li class="LSRow">
<a href="asd">
<span class="term">asd</span>(1
hits)
</a>
</li>
<li class="LSRow">
<a href="aspects">
<span class="term">aspects</span>(1
hits)
</a>
</li>
</ul>
</terms>
</exist:result> I'm importing the query from an external file, but
that shouldn't be the problem.
What i need to know are 2 things:
1) How can i exchange the term --> ('love')
<-- within the line:
let $t :=
request:get-parameter("query", ('love')),
dynamicaly with the one, entered in my search-field?
I tried something like:
<xforms:select1 ref="xxforms:instance('term-suggestion-query')//term" selection="open"
incremental="true"
appearance="xforms:autocomplete" class="search-field">
and in my query:
let $t := request:get-parameter("query", ('<term></term>')),
But than i always get empty results back, just like when i search for
nothing:
let $t := request:get-parameter("query", ('')),
So the entered data is inserted into the search-query-instance! I tested
that with the instance inspector, but it is not been sent during the submission
:-(
2) And how can i display the returnd values as options to my
input-search-field - just like in the example "google-suggests" I tried to
copy the google example and modified it, but it won't display my searched
suggestions :-( Even when I'm searching for a stable term and gettin back some
results, the aren't be displayed as options :-((
Could someone help me with that two problems?
Thanxs a lot,
Marcus
-- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Administrator
|
Hi Marcus,
On 4/19/07, Marcus <[hidden email]> wrote: > let $t := request:get-parameter("query", ('<term></term>')), > But than i always get empty results back, just like when i search for > nothing: > let $t := request:get-parameter("query", ('')), > > So the entered data is inserted into the search-query-instance! I tested > that with the instance inspector, but it is not been sent during the > submission :-( Yes, this is because when you send the query to eXist, inside the <exist:text> element, you are just supposed to have text. Not elements. And in this case you have this <term> element. What you can do is place the query in another instance: <xforms:instance id="initial-query"> <query> ... you XQuery <term/> .... </query> </xforms:instance> You bind the input to <term> in initial-query. You have then another instance with just: <xforms:instance id="exist-query"> <exist:query><exist:text/></exist:query> </xforms:instance> Before running the submission you do <xforms:setvalue ref="instance('exist-query')/exist:text" value="instance('initial-query')"/>. This will take the text value of your query, so you won't have the <term> element around the value anymore. > 2) And how can i display the returnd values as options to my > input-search-field - just like in the example "google-suggests" I tried to > copy the google example and modified it, but it won't display my searched > suggestions :-( Even when I'm searching for a stable term and gettin back > some results, the aren't be displayed as options :-(( Hard to say. Does the auto-complete field work for you if the values already there when the page is first loaded? Alex -- Orbeon Forms - Web 2.0 Forms for the Enterprise http://www.orbeon.com/ -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws |
Free forum by Nabble | Edit this page |