Thanks. I guess, I cannot do everything directly within XQuery, e.g., extending marked elements to continuous marking, to make "<mark>Korb</mark> <mark>geben</mark>" to be "<mark>Korb geben</mark>" -- it will be more important for queries with ftand or ftor.
Currently, the ft:mark() and ft:extract() functions are mainly used to highlight hits in search results, but we are always interested in extending our XQuery modules with helpful functions/additional arguments, so feel free to suggest new features (..but I cannot give any guarantee when a particular request will be implemented). For example, the latest snapshot contains two new functions ft:tokens() and ft:tokenize() [1], which have recently been requested.
How do I create alternatives for the query? If a user types "A B C" and ticks "process as STRING", the query would be:
ft:mark(//*[text() contains text "A B C" using stemming using language "de"][self::*:p or self::*:l])
If the user ticks "process as AND", the query should be:
ft:mark(//*[text() contains text ("A" ftand "B" ftand "C") using stemming using language "de" distance at most 10 words][self::*:p or self::*:l])
A query could look as follows:
declare variable $mode := 'STRING'; declare variable $input := 'This is a c b text'; declare variable $terms := 'A B C';
if($mode = 'STRING') then $input contains text { $terms } phrase else if($mode = 'AND') then $input contains text { $terms } all words else error((), 'Unknown search mode')
I don't know how to process the input-string to create the correct string for 'terms' and how to toggle queries (I would nee the "distance at most 10 words) for discontinuous queries only). Can I handle this by binding other variables, say 'distance' to a value dependent on user input, like:
ft:mark(//*[text() contains text { $term } using stemming using language "de" { $distance }][self::*:p or self::*:l])
You can use variables to dynamically choose a distance; see e.g. here:
let $dist := 0 return 'a b c' contains text 'a' ftand 'c' distance at most $dist words
All the best, Christian