Hi Justin,

Yes of course.  And exactly in the same spirit, it would be nice to be able
to compose collections in some way like the following (e.g. when we have
different sets of collections to organize documents following separate,
overlapping category sets):

var customers = jsearch.collections('customers');
var employees = jsearch.collections('employees');
var products  = jsearch.collections('products');

customers
    .collections('department/foo')
    .documents()
    .where(...)
    .result();

products
    .collections('department/bar')
    .collections('adults/only')
    .documents()
    .where(...)
    .result();

So collections([A, B]) is the union of A and B, whilst
collections(A).collections(B) would be their intersection.

But just an idea... ;-)  Regards,

-- 
Florent Georges
H2O Consulting
http://h2o.consulting/


On 1 August 2017 at 18:23, Justin Makeig wrote:

> To extend on what Erik said, the collections() method is designed to
> provide a top-level filter for the set of documents you're interested in.
> It's generally a best practice to organize your documents into collections.
> For example, all documents representing customers might be in the
> `com.acme.customer` collection. For this purpose, collections are roughly
> equivalent to a table in a relational database: a means to segregate
> entities of the same type. In practice, collections are much more flexible
> than tables, though.
>
> In JavaScript you can then provide a shortcut such that all subsequent
> queries will be scoped to that particular collection, so you don't have to
> remember to add the cts.collectionQuery() each time:
>
> const cust = jsearch.collections('com.acme.customers');
> const prod = jsearch.collections('com.acme.products');
>
> cust.documents().where(…).result();
> prod.values(…).result();
>
> If you were writing a library that operated over customers, you might even
> export the cust variable such that the consumer didn't even have to worry
> about the collection name itself.
>
> If you're using collections for other purposes (and you should), you can
> combine a top-level collections() call with cts.colletionQuery() in the
> where() to get the intersection.
>
> Justin
>
> > On Aug 1, 2017, at 6:20 AM, Florent Georges <[email protected]> wrote:
> >
> > Thank you, Erik!  I hoped there was a ready-to-use function for that.
> Thank you for confirming there is none.
> >
> > I definitely owe you a drink of your choice after the past few days :-)
> >
> > Regards,
> >
> > --
> > Florent Georges
> > H2O Consulting
> > http://h2o.consulting/
> >
> >
> > On 1 August 2017 at 15:10, Erik Hennum wrote:
> > Hi, Florent:
> >
> > The collections() call is just a shortcut / convenience.
> >
> > A full query can have a cts.andQuery() over a cts.collectionQuery() list.
> >
> >
> > Hoping that helps,
> >
> >
> > Erik Hennum
> >
> >
> > From: [email protected] [
> [email protected]] on behalf of Florent Georges [
> [email protected]]
> > Sent: Tuesday, August 01, 2017 3:46 AM
> > To: MarkLogic Developer Discussion
> > Subject: [MarkLogic Dev General] JSearch - collections
> >
> > Hi,
> >
> > The jsearch.collections() function uses the union of the collections.
> Is there another function for the intersection instead?  That is, to select
> all documents tagged with ALL the given collections (instead of ANY of
> them).
> >
> > Regards,
> >
> > --
> > Florent Georges
> > H2O Consulting
> > http://h2o.consulting/
> >
> >
> >
> > _______________________________________________
> > General mailing list
> > [email protected]
> > Manage your subscription at:
> > http://developer.marklogic.com/mailman/listinfo/general
> >
> >
> >
> >
> >
> > _______________________________________________
> > General mailing list
> > [email protected]
> > Manage your subscription at:
> > http://developer.marklogic.com/mailman/listinfo/general
>
>
> _______________________________________________
> General mailing list
> [email protected]
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to