Geert & Others,
Thanks for the input!
I thought maybe you had given me the solution but still having problems.

*The situation is like this:*
1. I'm new to these murky waters. :-)
2. I'm thinking this is generally a straight forward problem except for the following wrinkle that I was trying to solve without a serious code rewrite: 3. I have ~20,000 documents where almost all have unique element names that are great for faceting like e.g. "ResponsibleParty", "Date", etc... I set up my range indexes for them and things work great. However, one of the elements I'm interested in i.e. "Value" can appear up to ~1500+ times in a single document and have *_different _*content *_each time_*. Turns out I am only interested in about 5 possible content (character strings) that appear in the element "Value".

4. I use:
*{if { fn:contains(fn:string-join(($song-doc//ts:Value), ""   , "", "Cat"))

then /<div class="abc"> Value Cat: { /fn:string-join(($song-doc//ts:Value), "" , ""/</div>/**
else()}*


to determine if "cat" is present in any of the 1500 content values and if it is, display them. *This works great except it outputs _all_of them to the browser*. ??

I can also find the position in "Value" were "cat" is found using

{if {$song-doc//ts:Value[.= 'Cat'])
then let $x := fn:index-of ($song-doc//ts:Value, 'Cat')

But when I us the index (i.e. $x) and add this:

/return/

/{<div class="abc"> Content of "Value" at "cat" + 1 = {//$song-doc//ts:Value[position() =($x + 1)]}</div>/}


this does not work. It returns nothing.
I found out today when trying different things that if I put the integer "1" in place of ($x+1) it, again, returns ALL of the "Value" strings. However, anything other than "1" returns nothing. ???? Not sure why.


5. You can see I'm dancing around the solution but it still escapes me. :-)
6. Maybe you can't get there from here, but I seems close.
7. The suggestion to create an "document" just for the content of "Value" sounds good, but I do not know how to proceed to do that given my newness. 8. I also thought about filtering the "Value" element in the xml data as it comes in but we would like ALL of the data to be present for data mining.
9. I think I need council in the form of a teacher! :-)




Again, thanks for the help,
Randy


On 5/11/2011 12:18 AM, Geert Josten wrote:

Randy,

The short-hand for positional predicates don't always work when it contains a formula. You could write '/ts:Value[position() = ($x + 1)]/' instead of '/ts:Value[$x + 1]/'. But Damon is right; using following or following-sibling axes makes much more sense.

And yes, telling us the bigger picture helps us to give you more accurate advice. It also helps others facing similar problems to find an answer more easily in the mailing list archives. ;-)

Kind regards,

Geert

*Van:*[email protected] [mailto:[email protected]] *Namens *Damon Feldman
*Verzonden:* dinsdag 10 mei 2011 23:58
*Aan:* General MarkLogic Developer Discussion
*Onderwerp:* Re: [MarkLogic Dev General] How To Get The "Content" of An Index?

Randy,

I'm sure there's a way to accomplish what you're doing, but I'm not sure if indexes are the way to go. There are preceding-sibling and following-sibling axes available in XPath, so you could put all the "interesting" nodes in a document and use that to find prev/next. What's the bigger picture of what you're trying to accomplish?

Damon

*From:*[email protected] [mailto:[email protected]] *On Behalf Of *Randy Smith
*Sent:* Tuesday, May 10, 2011 2:33 PM
*To:* General MarkLogic Developer Discussion
*Subject:* Re: [MarkLogic Dev General] How To Get The "Content" of An Index?

Geert,
Thanks for the help. I believe you when you say that "index-of" may be slow. However, I am trying to get this to work (and satisfy my mind how it pull out the content at an index (like an array index):-). The code uses the search API plus I think I didn't explain the situation very well and I also left out some of the code. I tried the following based on you response but it still did not work. Any pointers?:
*
Up above in the code is this code :

**/declare variable $results := let $q := xdmp:get-request-field("q", "sort:newest")
let $q := local:add-sort($q)
return search:search($q, $options, xs:unsignedLong(xdmp:get-request-field("start","1")));/**
.
.
.


**declare function local:search-results()*
/let $items :=
    for $song in $results/search:result
    let $uri := fn:data($song/@uri)
    let $song-doc := fn:doc($uri)
    return

        {if {$song-doc//ts:Value[.='cat'])
            then let $x := fn:index-of($song-doc//ts:Value,'cat')
            for $gencontent at $index in $song-doc//ts:Value

            return
/note: I thought the following line would work but it didn't/

//<div class="abc"> Content of "Value" at "cat" + 1 = {//$song-doc//ts:Value[$x + 1]}</div>/
/

    else ()} .../
any help appreciated!!
randy

On 5/10/2011 7:05 AM, Geert Josten wrote:

Hi Randy,

Using index-of might not perform well. I would recommend using the for each at $pos construction instead:

for $song at $index in $searchresults

...

You can use $searchresults[$index + 1] to get access to the next searchresult (if there is any)

Kind regards,

Geert

*Van:*[email protected] <mailto:[email protected]> [mailto:[email protected]] *Namens *Randy Smith
*Verzonden:* maandag 9 mei 2011 22:47
*Aan:* [email protected] <mailto:[email protected]>
*Onderwerp:* [MarkLogic Dev General] How To Get The "Content" of An Index?

Anyone,
I think this is a simple question:
If I am using the MarkLogic search API like like with the Top-Songs app we developed in class e.g.:

/let $items :=
    for $song in $results/search:result
    let $song-doc := fn:doc($uri)
    return

        {if {$song-doc//ts:Value[.='cat'])
then <div class="abc"> Get the index of "Value" that has "cat" in it ==> {fn:index-of($song-doc//ts:Value/text(), 'cat')}</div>
    else ()} .../

The above works fine and gives me back the */index /**/for "cat" that is one of the many content values in element "Value"/*/(the element "Value" appears as many as 1500 times in some documents)./ But what I need is the content of the */index/*/+1/position. I already know "cat" is in the returned index position but I need to print out the content of the */index /*+ 1 position (or in some cases */index/*+2)

I'm sure there is a nice way to reference the /$song-doc//ts:Value[.='cat']/content by using something like (but I know this does not work) /$song-doc//ts:Value[index+1]/to get the content printed out. I know to look for "cat" but I do not know what is in the /"cat" position + 1/.

Any help appreciated! :'(

_______________________________________________
General mailing list
[email protected]  <mailto:[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

Reply via email to