Thanks Rob

From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Rob Szkutak
Sent: Friday, March 04, 2016 4:19 PM
To: MarkLogic Developer Discussion <general@developer.marklogic.com>
Subject: Re: [MarkLogic Dev General] Need a suggestion for grouped search

Hi,

Here's a quick query you can run on an empty or test database to prove that a 
only a single search is performed (you can copy and paste the whole thing into 
qconsole even though at first glance it may look like it's two queries):

xquery version "1.0-ml";
xdmp:document-insert("/testcontent.xml", 
<test><name>Rob</name><name>John</name></test>);

xquery version "1.0-ml";
cts:search(/, cts:element-value-query(xs:QName("name"), ("Rob", "John")))


Best,
Rob

Rob Szkutak
Senior Consultant
MarkLogic Corporation
rob.szku...@marklogic.com<mailto:rob.szku...@marklogic.com>
www.marklogic.com<http://www.marklogic.com>

________________________________
From: 
general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>
 [general-boun...@developer.marklogic.com] on behalf of Kari Cowan 
[kco...@alm.com]
Sent: Friday, March 04, 2016 6:12 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Need a suggestion for grouped search
Hmmm, yes, not duplicate docs but rather, there are multiple values in the 
partner data, example:

<almmediapartners>
<almmediapartner>Benefits Pro</almmediapartner>
<almmediapartner>Life Health Pro</almmediapartner>
</almmediapartners>

But noting what you said, I think the way I did the search below, it's doing 2 
searches because I asked it to:

cts:element-value-query(xs:QName("almmediapartner"),$this_partner)
- so it's going to match twice in the above case and each of those partners 
would return the same result.

I'll give that a try, what you suggested below.  Thanks.


From: 
general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>
 [mailto:general-boun...@developer.marklogic.com] On Behalf Of David Lee
Sent: Friday, March 04, 2016 4:07 PM
To: MarkLogic Developer Discussion 
<general@developer.marklogic.com<mailto:general@developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] Need a suggestion for grouped search

fn:distinct-values doesn't do what you think,
It returns a sequence of distinct values,
Your if statement will be true for all result sequences that have 1 or more 
items.

As rob mentioned cts search won't return duplicate results ( documents in your 
query)     But the search for thispartner is a "or" search so it is satisfied 
by any doc with either.

To help debug try returning document-uri()

For a group by you may need to do multiple searches either from the db or in 
memory ( in a sub for express or function )
Using order by can arrange the list by the first key then group by
That and select using an xpath expression (look for axis like 
following-siblings. https://docs.marklogic.com/guide/xquery/xpath)

or roughly

for $s in distinct-values( $key1 )
   for $r in $results[ key = $key1 ]
        Return ...
Depending on how big the result set is and what logic you want,
Maps are also useful for this case to temporarily store all results by one key 
then iterate over them


Sent from my iPad
David A Lee
d...@marklogic.com<mailto:d...@marklogic.com>


On Mar 4, 2016, at 6:45 PM, Rob Szkutak 
<rob.szku...@marklogic.com<mailto:rob.szku...@marklogic.com>> wrote:
cts:search only performs a single search so you won't get duplicate records 
from it.

Check your data. My guess would be that you've uploaded duplicate documents at 
separate URIs. I believe this likely to be true because you're using timestamps 
in your URIs.

Best,
Rob

Rob Szkutak
Senior Consultant
MarkLogic Corporation
rob.szku...@marklogic.com<mailto:rob.szku...@marklogic.com>
www.marklogic.com<http://www.marklogic.com>

________________________________
From: 
general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>
 
[general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>]
 on behalf of Kari Cowan [kco...@alm.com<mailto:kco...@alm.com>]
Sent: Friday, March 04, 2016 5:36 PM
To: general@developer.marklogic.com<mailto:general@developer.marklogic.com>
Subject: [MarkLogic Dev General] Need a suggestion for grouped search
I am using ML 7, and trying to do a grouped search.  In my test below, 
this_partner is 2 partners, split by the / character.  In the search, it would 
then search one, then the other.  I was hoping in the return, using 
fn:distinct-values(), I would only return the record if it had not already 
returned it.  In fact, it seemed to work that way in Qconsole but when I 
applied it to my query on the server, it would return a duplicate result for 
each record.

I am assuming what I am doing below is inadequate to get the result I am 
looking for, but the failure doesn't produce an exception.

Any suggestion for what might be better?

I was going to try distinct-nodes instead but I don't think that's available in 
ML7, is that true?

xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";;

let $this_partner:="Benefits Pro/Life Health Pro"
let $this_partner:= fn:tokenize($this_partner,"/")

let $search-this-partner:=
cts:search(fn:doc(),cts:and-query((
  cts:element-value-query(xs:QName("almmediapartner"),$this_partner),
  cts:element-query(xs:QName("approval_status"),cts:word-query("true")),
cts:element-attribute-range-query(xs:QName("EventStartDate"), xs:QName("date"), 
">=", xs:date(fn:current-date()) )
)))


return if(fn:distinct-values($search-this-partner/event/doc-uri) ) then
   $search-this-partner/event/(EventTitle|doc-uri)
   else ()

Results in Qconsole >>

<EventTitle>Test Record Title</EventTitle>
<doc-uri>/data-sources/events/BenefitsandLifeHealthPartners:2016-03-04-05:00:58.xml</doc-uri>

Results from server online >>

Test Record Title
Test Record Title


________________________________
Learn more about ALM, visit http://www.alm.com . - ALM, an Integrated Media 
Company, is a leading provider of news and information for the legal and 
commercial real estate markets. ALM's market-leading brands include The 
American Lawyer, Corporate Counsel, GlobeSt.com<http://globest.com>, Insight 
Conferences, Law.com<http://law.com>, Law Journal Press, LegalTech, The 
National Law Journal and Real Estate Forum.
_______________________________________________
General mailing list
General@developer.marklogic.com<mailto:General@developer.marklogic.com>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general
________________________________
Learn more about ALM, visit http://www.alm.com . - ALM, an Integrated Media 
Company, is a leading provider of news and information for the legal and 
commercial real estate markets. ALM's market-leading brands include The 
American Lawyer, Corporate Counsel, GlobeSt.com, Insight Conferences, Law.com, 
Law Journal Press, LegalTech, The National Law Journal and Real Estate Forum.



_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to