I haven't used search:suggest but if the results are already quoted (seems
strange to me - how is the inner " escaped ?) maybe you could just
create the JSON array yourself with
concat("[" , string-join($results,","),"]" )
-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]
Phone: +1 650-287-2531
Cell: +1 812-630-7622
www.marklogic.com
This e-mail and any accompanying attachments are confidential. The information
is intended solely for the use of the individual to whom it is addressed. Any
review, disclosure, copying, distribution, or use of this e-mail communication
by others is strictly prohibited. If you are not the intended recipient, please
notify us immediately by returning this message to the sender and delete all
copies. Thank you for your cooperation.
> -----Original Message-----
> From: [email protected] [mailto:general-
> [email protected]] On Behalf Of Jakob Fix
> Sent: Thursday, April 05, 2012 7:48 AM
> To: General Mark Logic Developer Discussion
> Subject: [MarkLogic Dev General] search:suggest and xdmp:to-json and jquery
> autocomplete not a perfect match?
>
> Hi,
>
> a typical integration of search:suggest is to use it as the data
> provider for, for example, the jquery autocomplete.
>
> using search:suggest I might get a sequence of strings:
>
> "A "Credit Crunch"?"
> "A Avaliação dos Alunos"
> "A Balancing Act"
> "A Better World for All"
> "A Bigger Picture"
>
> wrapping the search:suggest in xdmp:to-json gives me this:
>
> ["\"A \"Credit Crunch\"?\"", "\"A Avalia\u00E7\u00E3o dos Alunos\"",
> "\"A Balancing Act\"", "\"A Better World for All\"", "\"A Bigger
> Picture\""]
>
> I would very much like to see an option in xdmp:to-json that would not
> wrap another set of quotes around each item; in a perfect world this
> is the result I'd like to see:
>
> ["A \"Credit Crunch\"?", "A Avalia\u00E7\u00E3o dos Alunos", "A
> Balancing Act", "A Better World for All", "A Bigger Picture"]
>
> So, is there an easier option than trimming via a nested
> replace(replace()) the left and right quote marks (if they exist,
> single results aren't apparently quoted) of each element in the
> sequence, and then concat-ing and string-join-ing like this (not even
> sure that would work):
>
> concat(
> '["',
> string-join(
> search:suggest($term, $options, 5), '","'
> ),
> '"]'):)
>
> Right now the integration of jquery autocomplete and search:suggest
> seems quite cumbersome (but I may overlook the obvious solution, for
> sure!).
>
> Thanks for your advice,
> Jakob.
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general