[MarkLogic Dev General] lib-search, Fields,
andcts:field-word-query
Shannon Scott Shiflett
sss4r at virginia.edu
Thu Jul 10 09:53:09 PDT 2008
Dear John,
I use lib-parser, not lib-search, but in case the concept is similar,
this is the conditional code block in one of our programs in which if
the user has selected "docs" as their search scope then a fielded
search becomes the default without requiring the user to know or
supply a field name:
else if ($scope = "docs") then (
(: use cts:field-word-querys and fields for document-only search :)
(: get a cts:query type from query string :)
let $cts-query := lp:get-cts-query($phrase)
(: get a cts:query element from cts:query constructor :)
let $cts-query-element := lp:serialize-cts-query($cts-query)
(: turn the cts:query element into a string :)
let $cts-query-element-string := xdmp:quote($cts-query-element)
(: replace every cts:word-query with a sequence of cts:field-word-
querys :)
let $cts-query-element-string-fields := replace(
$cts-query-element-string,
'<cts:word-query(.*?)>(.*?)</cts:word-query>',
'<cts:field-word-query $1 string-item="div_nonotes">$2</
cts:field-word-query>'
)
(: change the string back into a cts:query element :)
let $cts-query-element-fields := xdmp:unquote($cts-query-element-
string-fields)
(: convert the cts:query element into a cts:query constructor :)
let $cts-query-final := lp:deserialize-query($cts-query-element-
fields)
return $cts-query-final (: return the constructor :)
Basically, using regex the cts:word-query() is translated into a
cts:field-word-query().
This was pre-conference, and I do not know if this applies to your
case at all or is at all helpful, and I'd be interested in hearing
from others whether this method has any merit or if there is a more
direct approach.
Regards,
Shannon
On Jul 10, 2008, at 12:34 PM, John Craft wrote:
> I believe I'm looking for the same answer as Mike. Is there a way
> to specify a field to search without requiring the user to know the
> name of the field? Basically, the default search is a fielded search.
>
> John Craft
>
> ________________________________________
> From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com
> ] On Behalf Of Mike Sokolov
> Sent: Thursday, July 10, 2008 9:37 AM
> To: General Mark Logic Developer Discussion
> Subject: Re: [MarkLogic Dev General] lib-search, Fields,andcts:field-
> word-query
>
> Frank did you indicate there was a way to map a search
> "box" (element, field, parameter - these words are too overloaded)
> to a field in the lib-search criteria, rather than requiring the
> user to enter a formatted query (or munging the text of their
> query)? That would be useful
>
> -Mike
>
> Frank Rubino wrote:
> It's the indicator passed in the user's query string:
>
> myField:smith
>
> It allows you to provide the user with a more friendly syntax.
>
> On 7/10/08 9:59 AM, "John Craft" <jcraft at jonesmcclure.com> wrote:
>
>
> Frank-
>
> In your example below, what does the code attribute map to?
>
> John Craft
>
> -----Original Message-----
> From: general-bounces at developer.marklogic.com
> [mailto:general-bounces at developer.marklogic.com] On Behalf Of Frank
> Rubino
> Sent: Thursday, July 10, 2008 8:18 AM
> To: General Mark Logic Developer Discussion
> Subject: Re: [MarkLogic Dev General] lib-search, Fields,
> andcts:field-word-query
>
> John-
> The lib-parser example mapping element is configured to specify
> field-word
> queries on a field called "weighted".
>
> To use fields you sprecify, you create your own mapping element:
>
> declare namespace lp = "http://www.marklogic.com/ps/lib/lib-parser"
> (:don't
> forget namespace:)
>
> <lp:search-field-map>
> <lp:mapping code="myField" field="fieldName"/>
> </lp:search-field-map>
>
> The field attribute indicates the name of the field you created in the
> admin
> interface.
>
> You use this element with lib-search when you create your
> search-criteria
> element.
>
> Frank
>
>
>
> On 7/9/08 11:49 PM, "John Craft" <jcraft at jonesmcclure.com> wrote:
>
>
> I have created a field with appropriate includes and excludes, but I
>
> am
>
> having difficulty figuring out how to configure lib-search to search
>
> it.
>
> lib-search keeps wanting to build cts:word-query() constructors rather
> than a cts:field-word-query() constructor. I have looked through the
> code and found the $SEARCH-FIELD-MAP in lib-parser.xqy but I'm not
>
> sure
>
> exactly how to use it. The example in the documentation seems to
> indicate <lp:mapping /> is for searching specific elements.
>
> Any insight you could share with lib-search and fields would be
> appreciated.
>
> John Craft
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general
>
>
> Frank Rubino
> Mark Logic Corp.
>
> 862-596-3248
> Frank.Rubino at marklogic.com
>
>
>
> Frank Rubino
> Mark Logic Corp.
>
> 862-596-3248
> Frank.Rubino at marklogic.com
>
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general
__________________________________________________
Shannon Scott Shiflett, programmer/analyst with ROTUNDA,
The University of Virginia Press, Charlottesville, VA USA
http://rotunda.upress.virginia.edu
More information about the General
mailing list