Hi Chad Bishop,
*You can try using cts:element-values() as well to get distinct subject
values based on your input,*let $qtext := "whatever search"let $terms :=
fn:tokenize($qtext," ")let $q := cts:and-query((
cts:collection-query("content"),
cts:element-attribute-value-query(xs:QName("subj-group"),
xs:QName("subj-group-type"),"heading"),
cts:element-word-query(xs:QName("subject"), $terms) )) return
cts:element-values(xs:QName("subject"), (), (), $q)
If you want exact subject values, use cts:element-value-query and
case-insensitive option OR cts:element-range-query
Note - You would need to create range index for the subject to run above
code.
[image: Inline image 1]
Regards,
Indy
On Wed, May 6, 2015 at 9:17 AM, Asitmohan Nautiyal <[email protected]>
wrote:
> Hi Chad,
>
> For searching a specific element and returning the matching values of
> that element use cts:element-value-query() function. Please refer
> https://docs.marklogic.com/cts:element-value-query
>
> Avoid use fn:distinct-values() function as its again a expensive in
> terms of performance. Use cts:values() function to get distinct terms from
> a specified element. Refer https://docs.marklogic.com/cts:values
>
> sample code is here :
>
> cts:values(cts:path-reference("*:subject,"
> http://marklogic.com/collation//S2"),(),(),
> cts:and-query((
> cts:collection-query("content"),
> cts:element-attribute-value-query(xs:QName("subj-group"),
> xs:QName("subj-group-type"),xs:string(heading)))))
>
>
> Note : Create path range index for subject element in your database.
>
>
> Regards,
> Asit Nautiyal
> ------------------------------
> *From:* [email protected] [
> [email protected]] on behalf of Chad Bishop [
> [email protected]]
> *Sent:* Wednesday, May 06, 2015 3:04 AM
> *To:* [email protected]
> *Subject:* [MarkLogic Dev General] Searching elements
>
> Greetings,
>
>
>
> I’m wondering if someone can help with the best way to approach searching
> a specific element and returning the matching values of that element.
>
>
>
> I figured xpath would be best so set this up:
>
>
>
> let $term1 := "what"
>
> let $term2 := "ever"
>
>
>
> let $subjects :=
> fn:collection("content")/article/front/article-meta/article-categories/subj-group[@subj-group-type
> = "heading"]/subject[fn:contains(., $term1) and fn:contains(., $term2)]
>
>
>
> for $subject in fn:distinct-values($subjects)
>
> return $subject
>
>
>
> However, the number of terms will be variable, so I created this:
>
>
>
> let $qtext := "whatever search"
>
> let $terms := fn:tokenize($qtext," ")
>
> let $contains := for $term in $terms
>
> return
>
> if ($term != $terms[fn:last()])
>
> then fn:concat("fn:contains(., ", """", $term, """", ")
> and ")
>
> else fn:concat("fn:contains(., ", """", $term, """", ")")
>
>
>
> let $containsText := fn:string-join($contains)
>
>
>
> let $subjects :=
> fn:collection("content")/article/front/article-meta/article-categories/subj-group[@subj-group-type
> = "heading"]/subject[$containsText]
>
>
>
> for $subject in fn:distinct-values($subjects)
>
> return $subject
>
>
>
> The problem is the $containsText isn’t evaluated as a function(s).
>
>
>
> Is there a way to do that or should I be using something different?
>
>
>
> Any help or advice is much appreciated,
>
>
>
> -Chad
>
>
>
>
>
>
>
>
>
> ~~~~~~~~~~~
>
> Chad Bishop
>
> Lead Developer
>
> Science Societies
>
>
>
> Synergy in Science: Partnering for Solution*s*
>
> 2015 ASA, CSSA, and SSSA International Annual Meeting
>
> *with the Entomological Society of America*
>
> November 15-18 | Minneapolis, Minnesota
>
> www.acsmeetings.org
>
>
>
>
>
> ::DISCLAIMER::
>
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
> The contents of this e-mail and any attachment(s) are confidential and
> intended for the named recipient(s) only.
> E-mail transmission is not guaranteed to be secure or error-free as
> information could be intercepted, corrupted,
> lost, destroyed, arrive late or incomplete, or may contain viruses in
> transmission. The e mail and its contents
> (with or without referred errors) shall therefore not attach any liability
> on the originator or HCL or its affiliates.
> Views or opinions, if any, presented in this email are solely those of the
> author and may not necessarily reflect the
> views or opinions of HCL or its affiliates. Any form of reproduction,
> dissemination, copying, disclosure, modification,
> distribution and / or publication of this message without the prior
> written consent of authorized representative of
> HCL is strictly prohibited. If you have received this email in error
> please delete it and notify the sender immediately.
> Before opening any email and/or attachments, please check them for viruses
> and other defects.
>
>
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
> _______________________________________________
> General mailing list
> [email protected]
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general