Skip to content

Instantly share code, notes, and snippets.

@myoung34
Created September 25, 2012 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myoung34/3785105 to your computer and use it in GitHub Desktop.
Save myoung34/3785105 to your computer and use it in GitHub Desktop.
Set up the bacon ipsum documents
declare function local:random-hex-set( $length as xs:integer ) {
fn:string-join(
for $i in 1 to $length return
xs:string(
xdmp:integer-to-hex(
xdmp:random(15)
)
)
,""
)
};
declare function local:generate-uuid-v4() {
fn:string-join(
(
local:random-hex-set(8),
local:random-hex-set(4),
fn:concat(
"4",
local:random-hex-set(3)
),
fn:concat(
xdmp:integer-to-hex( 8+xdmp:random(3) ),
local:random-hex-set(3)
),
local:random-hex-set(12)
),
"-"
)
};
declare function local:get-single-word(
) as xs:string {
let $bacon-ipsum :=
fn:tokenize(
'Bacon ipsum dolor sit amet jowl dolor quis, salami fatback voluptate andouille sint ball tip nulla pork chop. Adipisicing shank sed ad pancetta tri-tip. Cupidatat velit consectetur short ribs excepteur fugiat dolor aliqua corned beef strip steak duis capicola spare ribs fatback. Dolore ham hock pork loin ad drumstick fatback duis tail pork chop excepteur capicola. Turkey mollit pork, laboris fatback ham hock elit tenderloin ut sint brisket beef ribs aliqua. In voluptate dolore consectetur drumstick ad deserunt anim boudin.Eu flank shoulder chuck deserunt eiusmod labore pork chop in turducken consequat swine. Nulla sirloin meatloaf cupidatat t-bone adipisicing, fugiat kielbasa laboris. Ullamco anim andouille ball tip bresaola kielbasa do enim boudin frankfurter cow pork corned beef est tenderloin. Pancetta leberkas frankfurter cupidatat laborum, turkey deserunt pork strip steak salami jerky sint. Ground round flank pig ut tri-tip, ad t-bone ullamco biltong tenderloin sausage anim capicola et. Duis aute ullamco eu, nisi flank ball tip deserunt swine incididunt officia beef ribs. Non ullamco venison shankle officia cupidatat pariatur laborum.Pariatur eu reprehenderit anim. Ut drumstick pork chop aliquip, esse do tenderloin occaecat irure swine. Ut nisi pork loin beef ribs laboris voluptate pastrami ut ribeye id sunt laborum sint sed. Nostrud short loin sint, fatback filet mignon bacon eu cow sed veniam.Nisi irure turkey jowl do commodo corned beef. Frankfurter consectetur commodo, bresaola duis ullamco ad corned beef. Jerky chicken officia proident, excepteur dolore shoulder meatloaf ut aute brisket. Nostrud kielbasa in, short ribs pork loin pork venison adipisicing velit veniam esse rump. Eiusmod filet mignon sunt tempor, ullamco commodo pork loin frankfurter pastrami jowl aute aliquip in. In tail consequat, bacon drumstick fatback bresaola swine corned beef ad.Short loin laboris ea, nulla t-bone sunt beef bresaola capicola cow. Incididunt shankle officia irure t-bone excepteur. Flank quis nulla, sint andouille aute ut tri-tip. Exercitation ut pariatur ea deserunt laboris pancetta ribeye shankle beef chuck. Boudin turkey commodo, sunt sint turducken sausage ea consequat non swine. Frankfurter short ribs mollit ut tongue pariatur cillum jerky eu non in enim prosciutto sausage. Nisi dolore minim exercitation pork chop velit.',
' '
)
let $random-position := xdmp:random(fn:count($bacon-ipsum))
let $word :=
fn:replace(
$bacon-ipsum[$random-position],
"[^a-zA-Z]",
""
)
return
if($word) then ($word) else ("huh") (: this should never happen, but it does sometimes...? :)
};
declare function local:get-text (
$num-of-words as xs:int
) as xs:string {
fn:string-join(
for $iteration in 1 to $num-of-words
return local:get-single-word()
," "
)
};
declare function local:generate-node(
$level as xs:int
) as node() {
element
{ local:get-single-word() }
{
attribute
{ local:get-single-word() }
{ local:get-text(2) },
let $new-level := $level - 1
return if($new-level gt 0) then (
for $iteration in 1 to xdmp:random((2 * $level) + 1) return
local:generate-node($new-level)
) else (
local:get-text(50)
)
}
};
(: This will insert 1200 documents, 4 levels deep full of bacon ipsum text :)
for $i in 1 to 1200 return
xdmp:document-insert(
fn:concat('/doc/',local:generate-uuid-v4()),
local:generate-node(4)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment