Hi, The first thing I would wonder, is whether you really need fn:contains (for substring), or whether you are searching on tokens/words.
If tokens/words, then as mentioned, the search facilities should be the first option. /ch On Tue, May 5, 2015 at 5:34 PM, Chad Bishop <[email protected]> wrote: > 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 > > www.acsmeetings.org > > > > > _______________________________________________ > 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
