marklogic-community / Corona

Community REST API for MarkLogic
Other
37 stars 9 forks source link

Faceting on array fields #86

Open Jagdeep1 opened 12 years ago

Jagdeep1 commented 12 years ago

In the current corona implementation array is not a range supported data type https://github.com/marklogic/Corona/wiki/Supported-Range-Datatypes
I have a JSON document with structure like ... "aothor":"name", "published_date":"20-10-2011", "nouns":["n1","n2"], ....

Here I want to do faceting on "nouns" field which has array data type.

ryangrimm commented 12 years ago

You are correct, at this time there is no support for adding a range index on a JSON array. However, I anticipate that the next major version of MarkLogic server will make supporting this rather trivial. In the meantime there are a couple options:

1) I could change the datamodel that's backing the JSON documents to support this (pretty painful for me) 2) You could use the support for XML strings inside JSON documents as a stopgap solution. Here's how I'd do that if I were you:

I'd create another key, "nouns::xml". Inside this key I'ld put a quoted string of XML that contains a element for every item in the array. So it would look something like:

{"author":"name", "published_date":"20-10-2011", "nouns":["n1","n2"], "nouns::xml":{"<nouns><noun>n1</noun><noun>n2</noun></nouns>"}}

You'd then create an XML element range index on "noun" and query using that.

I know this isn't pretty and I'd like to have a better solution in place today but it is what it is.

Jagdeep1 commented 12 years ago

Thanks.. I will try using till you come up with native support for array objects.