From: Jens Ø. P. <oe...@gm...> - 2011-11-24 16:21:49
|
Hi Roy, Your ingenious XQuery makes me wonder …. When you wrote (to Gerrit) "I used eXist :-)" - what you meant was that you used _XQuery_, for eXist can easily process stylesheets: that's part of the toolbox. The five functx:ions that you call, some rather complicated, and your own function add up to something like 75 lines, all depending. The stylesheet, which does the work of these functions with one specific template, adds up to some 15 lines of indented XML. Good code is said to be code that is clear and concise - is XQuery to be preferred for all tasks? Cheers, Jens PS: If you have more rows than one, you should have something like "for $field in $rows/row[1]//field" (assuming that all rows have the same fields). On Nov 24, 2011, at 3:04 PM, Roy Walter wrote: > Ah, OK, the last part is easy and doesn't require update. Just something to add to the function: > > declare function local:flip($names, $row) > { > let $flipped := > for $name in $names > return > functx:change-element-names-deep($row/field[@name=$name], xs:QName('field'), xs:QName($name)) > > for $n in $flipped > return > functx:remove-attributes($n, "name") > }; > > -- Roy > > > ---- On Thu, 24 Nov 2011 13:15:11 +0000 Roy Walter <gar...@ya...> wrote ---- > > Sure, transformation is better (but another step). I used eXist :-) > > declare function local:flip($names, $row) > { > for $name in $names > return > functx:change-element-names-deep($row/field[@name=$name], xs:QName('field'), xs:QName($name)) > }; > > let $rows := (:some xml from mysqldump:) > > let $names := > for $field in $rows[1]//field > return xs:string($field/@name) > > let $result := > for $row in $rows/row > return > <row>{local:flip($names, $row)}</row> > > return $result > > > Now I just have to remove the redundant attributes using update, which can't be done in memory. > > -- Roy > > > > > ---- On Thu, 24 Nov 2011 11:45:16 +0000 Gerrit Boers<gb...@xs...> wrote ---- > > Why don't you transform the xml into something more useful? You're using exist as a glorified key-value storage, this will always be a suboptimal approach. > A simple XSLT could create xml like this: > > <row> > <fieldname1>Some data</fieldname1> > ... > </row> > Now you can create an index for a specific element and also create an index on row if you need to search across all elements. > > Regards, > > Gerrit > > On Nov 24, 2011, at 10:25 AM, Roy Walter wrote: > >> I have an XML file created using mysqldump. It has the format >> >> <row> >> <field name="fieldname1">Some data</field> >> <field name="fieldname2">Some data</field> >> ... >> </row> >> >> Is it yet possible to create a Lucene index for a field element with a specific name attribute? For example, I want to index the only the content of these field elements having the name attribute political interests: >> >> <field name="political_interests">Pension law, constitutional reform, European Union</field> >> >> If it's not possible, how do I optimise text searches within these elements? >> >> (I think I asked the same question a while ago and it was something that was being considered. Not sure where we got to.) >> >> Thanks as ever, >> Roy >> ------------------------------------------------------------------------------ >> All the data continuously generated in your IT infrastructure >> contains a definitive record of customers, application performance, >> security threats, fraudulent activity, and more. Splunk takes this >> data and makes sense of it. IT sense. And common sense. >> http://p.sf.net/sfu/splunk-novd2d_______________________________________________ >> Exist-open mailing list >> Exi...@li... >> https://lists.sourceforge.net/lists/listinfo/exist-open > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d_______________________________________________ > Exist-open mailing list > Exi...@li... > https://lists.sourceforge.net/lists/listinfo/exist-open > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d_______________________________________________ > Exist-open mailing list > Exi...@li... > https://lists.sourceforge.net/lists/listinfo/exist-open > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d_______________________________________________ > Exist-open mailing list > Exi...@li... > https://lists.sourceforge.net/lists/listinfo/exist-open |