Hi Alan,

If you *really* want to run the query regardless of whether you have the
lexicon, I think the try/catch method is the best approach here.
Similar to what Mike suggested, here is a pattern that seems to work for
me:

let $urilookup := 
  try { cts:uris()[1] } 
  catch ($e) { if ( $e/err:code eq "XDMP-URILXCNNOTFOUND" ) 
               then ( xdmp:node-uri(doc()[1]) )
               else ( $e ) } 
return $urilookup

In 3.2, there is no supported way to get the config info.  This is a
common enhancement request, and there is some likelihood there will be a
way to get this info in the future....  

But getting the config info is not really sufficient anyway--the
try/catch is safer.  For example, you could have the uri lexicon enabled
in the configuration but the database might not have finished
reindexing, in which case just getting the config info would make you
run the lexicon call, but it would fail because the lexicon is not yet
available.

Another thing to consider here is that, in many case, you probably do
*not* want the query to ever run in slow mode, because slow mode might
be a hugely expensive query.  Lexicon lookups can often be many orders
of magnitude faster than doing the equivalent lookup in a brute-force
manner, and in some cases there may be no other way to get that answer.
So you might just be best off having your application throw an exception
when the lexicon is not there, so that you can avoid a query that will
be very slow or never return.  

-Danny

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Michael
Sokolov
Sent: Friday, February 22, 2008 10:32 AM
To: 'General Mark Logic Developer Discussion'
Subject: RE: [MarkLogic Dev General] determining which indexes exist
foradatabase

The best I have come up with for this is:

let $has-uri-lexicon := try { cts:uris()[1], true() } catch { false() }
return
... if ($has-uri-lexicon) ...

Mark Logic people ; is there better?  What can we do for other sorts of
indexes?

We would really love to be able to get a list of all indexes, plus
ideally
statistics on those indexes (how many keys, how many fragments mapped
to,
how many bytes storage on disk, etc.)  Another nice feature would be to
track how "useful" the index was in some way: how many searches
resolved?

-Mike

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Alan Darnell
> Sent: Friday, February 22, 2008 1:19 PM
> To: General Mark Logic Developer Discussion
> Subject: [MarkLogic Dev General] determining which indexes 
> exist for adatabase
> 
> Is there an API that can be used to scope out what indexes 
> and/or lexicons have been defined for any particular 
> database?  For instance, if you have a URI lexicon enabled, 
> then it might be faster to use cts:uri-match than some other 
> method to determine if a URI already exists in the database.  
> It would be nice to write portable code, however, that could 
> adjust to whatever was available for a database.
> 
> Alan
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
> 

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to