You can also wrap the constraint in parenthesis, for example:

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"; at 
"/MarkLogic/appservices/search/search.xqy";

let $options := 
 <options xmlns="http://marklogic.com/appservices/search";>
  <constraint name="my constraint">
    <word>
     <element ns="" name="title"/>
    </word>
  </constraint>
  </options>

return search:parse("(my constraint):test", $options)

=>

<cts:element-word-query qtextpre="my constraint:" qtextref="cts:annotation" 
xmlns:cts="http://marklogic.com/cts";>
  <cts:element>title</cts:element>
  <cts:annotation qtextref="following-sibling::cts:text"/>
  <cts:text>test</cts:text>
</cts:element-word-query>


-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Colleen Whitney
Sent: Monday, August 24, 2009 9:51 AM
To: General Mark Logic Developer Discussion
Subject: [MarkLogic Dev General] RE: search:suggest questions

Hi Bob,

Re: question 1.  Your constraints will not work properly, even for searches, if 
there is a space in the name.  Here's an example of how a word constraint with 
a space parses:

import module namespace search = "http://marklogic.com/appservices/search"; at 
"/MarkLogic/appservices/search/search.xqy";

let $options := 
 <options xmlns="http://marklogic.com/appservices/search";>
  <constraint name="my constraint">
    <word>
     <element ns="" name="title"/>
    </word>
  </constraint>
  </options>

return search:parse("my constraint:Cayenne",$options)

 ==> 

<cts:and-query strength="20">
    <cts:word-query qtextref="cts:text">
        <cts:text>my</cts:text>
    </cts:word-query>
    <cts:word-query qtextref="cts:text">
        <cts:text>constraint:Cayenne</cts:text>
    </cts:word-query>
</cts:and-query>

It is two word queries anded together, neither restricted to the title element.

If you do the same query using an underscore rather than a space, it parses as 
an element-word query:

import module namespace search = "http://marklogic.com/appservices/search"; at 
"/MarkLogic/appservices/search/search.xqy";

let $options := 
 <options xmlns="http://marklogic.com/appservices/search";>
  <constraint name="my_constraint">
    <word>
     <element ns="" name="title"/>
    </word>
  </constraint>
  </options>

return search:parse("my_constraint:Cayenne",$options)
<cts:element-word-query qtextpre="my_constraint:" qtextref="cts:annotation">
    <cts:element>title</cts:element>
    <cts:annotation qtextref="following-sibling::cts:text"/>
    <cts:text>Cayenne</cts:text>
</cts:element-word-query>

So the bottom line is:  do not use a space in your constraint name.

Re: question no 2.  You'll need to think about your data structure carefully if 
you've got a very large database and you want to use the suggest feature.  As 
you've found, the range index will return the entire value of the element or 
attribute, not just individual words.  So you could do some data enrichment to 
build a range index of words to use for suggestions, if a database word lexicon 
is not fast enough given your dataset (keeping in mind the impact on database 
footprint).  You could also try using a field word lexicon on limited subsets 
of your data (e.g. if you had a database full of articles you could build a 
field word lexicon on titles and abstracts).  

Also keep in mind that performance will be faster if there are more input 
characters to limit matches quickly (e.g. it will be faster when query text is 
"abs" rather than "a", so you could also affect performance by designing the 
front end to start getting suggestions only when you reach some threshold for 
number of input characters.

In any case, I'd test against your data to get a real feel for performance of 
any given approach;  performance of this particular feature is tightly bound to 
the size and characteristics of your data.

Regards,

--Colleen Whitney


_______________________________________
From: [email protected] 
[[email protected]] On Behalf Of Runstein, Robert E. 
(Contr) (IS) [[email protected]]
Sent: Monday, August 24, 2009 7:59 AM
To: [email protected]
Subject: [MarkLogic Dev General] search:suggest questions

Hi,
I have two questions about search:suggest.

1. I've configured my options to include a constraint that has a space
in its name. When I pass the first character of the constraint name to
search:suggest it returns the constraint followed by the colon, but when
I submit the value returned again with the first character of a
constraint value, I get an empty sequence.
e.g., constraint name is "my constraint" and has values first, second
and third and has a range index on the values.
search:suggest("m", $options) => my constraint:
search:suggest("my constraint:f", $options) => ()
If I change the constraint name to "my_constraint" in my options
search:suggest("my_constraint:f", $options) => first
Is there a way to escape the space in the constraint name when passing
it to search:suggest or is my only option to rename the constraint to
eliminate the space?

2. The docs state that using a word lexicon for the default suggestion
source on a large database will not perform as well as using a range.
I've tried both and the word lexicon returns single words within
elements, but using a range index returns full sentences beginning with
words that match the characters passed. If I prepend a "*" I get full
sentences containing the characters passed. Is there a way to get back
just the matching words not the full sentence>

Thanks.

Bob

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

Reply via email to