|
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 Solutions 2015 ASA, CSSA, and SSSA International Annual Meeting with the Entomological Society of America November 15-18 | Minneapolis, Minnesota
The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. ---------------------------------------------------------------------------------------------------------------------------------------------------- |
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
