OK, well I don't think that will be very hard, if I understand what you're
saying. You won't be able to do it all in one search operation, but the join
should still be fast. You'll just need a FLWOR, like this:
declare function my-search ($query as xst:query, $first as xs:integer, $max as
xs:integer)
{
let $id-qname := xs:QName ("doc-id")
let $last := $first + $max - 1
for $doc in (cts:search (fn:collection ("my-content"), $query))[$first to
$last]
let $id :=
$doc/xpath-to-place-where-the-extern-ref-is/other-doc-id/fn:string()
return cts:search (fn:collection ("my-content"), cts:element-value-query
($id-qname, $id, "exact")
};
This function will return matching documents in the order returned by
cts:search. The rest of the FLWOR extracts the id of the other document from
each search result and returns documents with those primary IDs, also in the
order of the original result sequence. The documents matched by the search are
not returned from this function. The above assumes the query that gives you
the relevance order you want is constructed and passed into this function.
There are a few things to note. The "let $id := ..." line may be
automatically optimized if there is a range index on the "other-doc-id"
element. The search gives you a sequence of handles to documents that match,
not the documents themselves. The actual documents are only pulled in when a
reference is made that cannot be satisfied from indexed information about a
document. Since you only want the IDs from these documents, if that value can
be retrieved from an index without ever needing to read the document in, then
it will be fast. Note also that sometimes types matter. If your doc ID is a
number, and you have a numeric range index on it, you may need to use a cast to
insure that the appropriate typed indexes can be enlisted.
The return clause could also be written as:
fn:collection ("my-content")[some-metadata-path/doc-id = $id]
This will usually result in a similar search operation. But, these kinds of
"global XPaths" will run even without supporting indexes being available, which
can be very slow in some cases. By using cts:search for a single document,
I'll get an exception if what I'm asking for cannot be resolved entirely via
indexes. Note: both approaches assume no more than one document in the
collection has the same value for "doc-id"
It could also be possible, depending on your document naming scheme, to
intuit the URIs of the other documents just from the ID, without an XPath or
subordinate cts:search. Something like this:
return fn:doc (uri-from-doc-id ($id))
But this assumes such an unambiguous mapping exists. Often this is not so
easy, if there is a versioning scheme, or unrelated documents might have the
same IDs in different collections, etc.
I hope that's helpful.
---
Ron Hitchens {[email protected]} +44 7879 358212
On Sep 18, 2014, at 2:54 PM, Mrinmoy Khamrui
<[email protected]> wrote:
> Hello Ron,
>
> Thanks for the link. I visited this and this is my last option.
>
> The other problem I have is to control the order of cts:element-values by
> passing it a query and controlling score in that query. As per my requirement
> I need the query to be passed to cts:element-values anyway. So I was
> wondering if it is at all possible.
>
> Here is my requirement:
>
> I have two sets of document. They are linked by an id (contrary to ML best
> practice to have the whole graph in single place). I need to search one set
> in relevance order and take the referring ids in same order so that the other
> set is retrieved in that order. I was using cts:element-values to get list of
> referring ids.
>
> Thanks
> Mrinmoy
>
> On Thu, Sep 18, 2014 at 6:52 PM, Ron Hitchens <[email protected]> wrote:
>
> There was a discussion here last year about boosting the relevance of
> recent documents, which I think is pretty much what you're after. That was
> prior to the release of ML 7, so it may be useful for you. The discussion
> thread can be found on MarkMail:
>
> http://markmail.org/search/?q=marklogic+new+content+relevance#query:marklogic%20new%20content%20relevance+page:1+mid:23kpbgnxavlaidyn+state:results
>
> If that link doesn't work, go to http://markmail.org and search for
> "marklogic new content relevance".
>
> ---
> Ron Hitchens {[email protected]} +44 7879 358212
>
> On Sep 18, 2014, at 1:22 PM, Mrinmoy Khamrui
> <[email protected]> wrote:
>
>> Hi Danny,
>>
>> Unfortunately I am stuck with Marklogic 6 as of now. My requirement is quite
>> similar to the one listed in ML 7 search documentation (boosting based on
>> newness of documents). So I feel it is only range query that I can use so
>> that all documents are selected but score is calculated based on how far is
>> it from the pivot.
>>
>> I am also wondering if I can influence the ordering of cts:element-values
>> based on passed query. It seems that it is not possible and only influencing
>> factors are frequency-order and item-order.
>>
>> Thanks
>> Mrinmoy
>>
>> On Wed, Sep 17, 2014 at 11:33 PM, Danny Sokolsky
>> <[email protected]> wrote:
>> You can consider moving to MarkLogic 7. Also, you can add other non-range
>> queries to your cts:query, if that is possible. And quality is also an
>> option, either at load time or as an update later.
>>
>>
>>
>> -Danny
>>
>>
>>
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Mrinmoy Khamrui
>> Sent: Wednesday, September 17, 2014 10:53 AM
>>
>>
>> To: MarkLogic Developer Discussion
>> Subject: Re: [MarkLogic Dev General] using cts:boost-query with
>> search:resolve in Marklogic 7
>>
>>
>>
>> Then is it that only option left is to set document quality at the time of
>> loading?
>>
>>
>>
>> Thanks
>>
>> Mrinmoy
>>
>>
>>
>> On Wed, Sep 17, 2014 at 10:05 PM, Danny Sokolsky
>> <[email protected]> wrote:
>>
>> Range queries do not contribute to score in MarkLogic 6. They do in
>> MarkLogic 7. So if you are using MarkLogic 6 that explains the 0 scores.
>>
>>
>>
>> -Danny
>>
>>
>>
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Mrinmoy Khamrui
>> Sent: Wednesday, September 17, 2014 7:03 AM
>>
>>
>> To: MarkLogic Developer Discussion
>> Subject: Re: [MarkLogic Dev General] using cts:boost-query with
>> search:resolve in Marklogic 7
>>
>>
>>
>> Hi Erik,
>>
>>
>>
>> I got a chance to try out this. I am using below query as my boost query but
>> it seems we would still require feature similar to score-function. Otherwise
>> the score for all the matching elements are coming as 0.
>>
>>
>>
>> boost query
>>
>> ==========================================
>>
>> cts:element-range-query(
>>
>> xs:QName("pubdate"), "<=", current-dateTime())
>>
>>
>>
>> Am I missing anything?
>>
>>
>>
>> Thanks
>>
>> Mrinmoy
>>
>>
>>
>> On Thu, Sep 11, 2014 at 8:15 PM, Erik Hennum <[email protected]>
>> wrote:
>>
>> Hi, Mrinmoy:
>>
>> On MarkLogic 6, you should be able come close to a boost query with
>>
>> <search:query xmlns:search="http://marklogic.com/appservices/search">
>> <search:and-query>
>> YOUR_MATCHING_QUERY_HERE
>> <search:or-query>
>> YOUR_BOOSTING_QUERY_HERE
>> <search:and-query/>
>> </search:or-query>
>> </search:and-query>
>> </search:query>
>> or the cts:query equivalent
>>
>> cts:and-query((
>> YOUR_MATCHING_QUERY_HERE,
>> cts:or-query((
>> YOUR_BOOSTING_QUERY_HERE,
>> cts:and-query(())
>> ))
>> ))
>> Within the or query, the and query matches everything, so the boosting query
>> should only affect ranking and not matching.
>>
>>
>> Hoping that helps,
>>
>>
>>
>> Erik Hennum
>>
>> From: [email protected]
>> [[email protected]] on behalf of Mrinmoy Khamrui
>> [[email protected]]
>> Sent: Monday, September 08, 2014 11:17 PM
>>
>>
>> To: MarkLogic Developer Discussion
>> Subject: Re: [MarkLogic Dev General] using cts:boost-query with
>> search:resolve in Marklogic 7
>>
>>
>>
>> Hi Erik,
>>
>>
>>
>> Is there a way to implement cts:boost-query in marklogic 6 apart from using
>> document quality? We need to have similar feature on marklogic 6. Please
>> suggest.
>>
>>
>>
>> Thanks
>>
>> Mrinmoy
>>
>>
>>
>> On Fri, Sep 5, 2014 at 10:25 PM, Mrinmoy Khamrui
>> <[email protected]> wrote:
>>
>> Hi Erik,
>>
>>
>>
>> Thanks for pointing that. It worked.
>>
>>
>>
>> -- Mrinmoy
>>
>>
>>
>> On Fri, Sep 5, 2014 at 8:38 PM, Erik Hennum <[email protected]>
>> wrote:
>>
>> Hi, Mrinmoy:
>>
>> The search:resolve() function expects the serialized version of the
>> cts:query. Try:
>>
>>
>> let $results := search:resolve(<q>{$query}</q>/*, $options, $start,
>> $pageRecs)
>>
>>
>> See:
>>
>> http://docs.marklogic.com/search:resolve
>>
>>
>> Hoping that helps,
>>
>>
>> Erik Hennum
>>
>> From: [email protected]
>> [[email protected]] on behalf of Mrinmoy Khamrui
>> [[email protected]]
>> Sent: Friday, September 05, 2014 7:38 AM
>> To: MarkLogic Developer Discussion
>> Subject: Re: [MarkLogic Dev General] using cts:boost-query with
>> search:resolve in Marklogic 7
>>
>> Hi Erik,
>>
>>
>>
>> Many thanks. Please find below the error. I can execute the same query with
>> cts:search but search:resolve complains
>>
>>
>>
>>
>>
>>
>>
>> [1.0-ml] XDMP-AS: (err:XPTY0004) $ctsquery as element() -- Invalid coercion:
>> cts:boost-query(cts:path-range-query("/products/product/productcategoryassociations/catalog[@code
>> = &q...", "=", xs:int("10001"), (), 1),
>> cts:path-range-query("/products/product/edition", ">", 0,
>> ("score-function=linear","slope-factor=10"), 1)) as element()
>>
>> Stack Trace
>>
>> In /MarkLogic/appservices/search/search.xqy on line 64
>> In xdmp:eval("xquery version "1.0-ml"; import module
>> namesp...", (), <options
>> xmlns="xdmp:eval"><database>13679529190427072881</database><isolation>different-tr...</options>)
>>
>> In /MarkLogic/appservices/qconsole/qconsole-amped.xqy on line 202
>> In amped-qconsole:qconsole-eval("xquery version
>> "1.0-ml"; import module namesp...", (), <options
>> xmlns="xdmp:eval"><database>13679529190427072881</database><isolation>different-tr...</options>)
>>
>> $xquery := "xquery version "1.0-ml"; import module
>> namesp..."
>> $vars := ()
>> $options := <options
>> xmlns="xdmp:eval"><database>13679529190427072881</database><isolation>different-tr...</options>
>>
>>
>>
>> On Fri, Sep 5, 2014 at 7:53 PM, Erik Hennum <[email protected]>
>> wrote:
>>
>> Hi, Mrinmoy:
>>
>>
>>
>> Can you provide the invalid coercion error? Including the expression,
>> module,
>>
>> and line number identified by the error (and the specific MarkLogic version)?
>>
>>
>>
>>
>>
>> Thanks,
>>
>>
>>
>>
>>
>> Erik Hennum
>>
>> From: [email protected]
>> [[email protected]] on behalf of Mrinmoy Khamrui
>> [[email protected]]
>> Sent: Friday, September 05, 2014 6:59 AM
>> To: [email protected]
>> Subject: [MarkLogic Dev General] using cts:boost-query with search:resolve
>> in Marklogic 7
>>
>> Hi Folks,
>>
>>
>>
>> I am trying to use cts:boost-query with search:resolve and getting invalid
>> coercion. Below is my code snippet.
>>
>>
>>
>> let $query := search:parse($search-term,$options)
>>
>> let $query := cts:boost-query(cts:query($query),
>> cts:path-range-query("somepath with path index", ">", 0,
>>
>> ("score-function=linear","slope-factor=10")))
>>
>>
>>
>> let $results := search:resolve($query, $options, $start, $pageRecs)
>>
>>
>>
>> Any suggestion is highly appreciated.
>>
>>
>>
>> Thanks
>>
>> Mrinmoy
>>
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
>>
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
>>
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
>>
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general