Hi Srini,
You can specify a phrase by double-quoting it. Note that in order to specify
double-quote marks, you have to either construct the string using single-quotes
or escape the double-quotes. There are a set of default options to the query
with the Search API, and some of those options change based on the terms you
search for. These mirror the defaults in the underlying cts:query APIs. These
are for such options as punctuation-sensitive, diacritic-sensitive, and so on.
To understand what search:search("foo OR bar test1") is doing, try the
following:
search:parse("foo OR bar test1")
=>
<cts:and-query strength="20" xmlns:cts="http://marklogic.com/cts">
<cts:or-query qtextjoin="OR" strength="10">
<cts:word-query qtextref="cts:text">
<cts:text>foo</cts:text>
</cts:word-query>
<cts:word-query qtextref="cts:text">
<cts:text>bar</cts:text>
</cts:word-query>
</cts:or-query>
<cts:word-query qtextref="cts:text">
<cts:text>test1</cts:text>
</cts:word-query>
</cts:and-query>
Notice this is an and-query of the ORed terms foo and bar and the term test1.
You can throw in a phrase to this string as follows:
search:parse('foo OR bar "hello world" test1')
=>
<cts:and-query strength="20" xmlns:cts="http://marklogic.com/cts">
<cts:or-query qtextjoin="OR" strength="10">
<cts:word-query qtextref="cts:text">
<cts:text>foo</cts:text>
</cts:word-query>
<cts:word-query qtextref="cts:text">
<cts:text>bar</cts:text>
</cts:word-query>
</cts:or-query>
<cts:and-query strength="20">
<cts:word-query qtextpre=""" qtextref="cts:text" qtextpost=""">
<cts:text>hello world</cts:text>
</cts:word-query>
<cts:word-query qtextref="cts:text">
<cts:text>test1</cts:text>
</cts:word-query>
</cts:and-query>
</cts:and-query>
Now it is an and-query of the ORed terms, the phrase "hello world", and the
term test1.
There are lots of options to the Search API. I recommend looking at Chapter 2
of the Search Developer's Guide
(http://developer.marklogic.com/pubs/4.1/books/search-dev-guide.pdf) and at the
apidoc for search:search
(http://developer.marklogic.com/pubs/4.1/apidocs/SearchAPI.html#search:search).
Hope that helps.
-Danny
From: [email protected]
[mailto:[email protected]] On Behalf Of Srinivas Mandadapu
Sent: Tuesday, November 17, 2009 12:35 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] search for multiple terms in ML
How do I restrict search results to be consistent like below:
search:search("foo") ==> returns 4 docs
search:search("bar") ==> returns 5 docs
search:search("foo OR bar") ==> returns 9 docs (assuming both terms don't
appear in any single document)
How do I search for terms which have space or "/" in between terms
search:search("foo OR bar test1") ==> returns 4 docs ( search query seems to be
looking for any of the terms as observed from search:parse )
search:search("foo OR bar test2") ==> returns 4 docs
Thanks,
Srini
Danny Sokolsky wrote:
How about:
search:search("foo OR bar")
To see what the cts:query would be, try:
xquery version "1.0-ml";
import module namespace search =
"http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
search:parse("foo OR bar")
-Danny
From: [email protected]
[mailto:[email protected]] On Behalf Of Srinivas Mandadapu
Sent: Tuesday, November 17, 2009 10:24 AM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] search for multiple terms in ML
I mean like foo OR bar.
Below is the grammar options used for search:
<grammar>
<starter strength="30" apply="grouping" delimiter=")">(</starter>
<starter strength="40" apply="prefix" element="cts:not-query">-</starter>
<joiner strength="10" apply="infix" element="cts:or-query"
tokenize="word">OR</joiner>
<joiner strength="20" apply="infix" element="cts:and-query"
tokenize="word">AND</joiner>
<quotation>"</quotation>
<joiner strength="50" apply="constraint">:</joiner>
</grammar>
Andrew Welch wrote:
2009/11/17 Srinivas Mandadapu <[email protected]>:
How do I search for multiple terms in ML using search lib? It seems to be
working for single term and constraints but not multiple terms though.Is
there something to be configured on ML side or additional option to be
provided for search:search API to enable the search for multiple terms?
Give an example of what you mean... do you mean something like "foo OR
bar", or "type:foo class:bar" etc..
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general