Skip to content

Support multi-field queries with combinations other than "and" #13

@pete-thompson

Description

@pete-thompson

There are situations where we need to query for multiple fields but combined in ways other than "and". For example, we may want to retrieve rows from a list for a set of different status values - so use an "or" query. Or a more complex example may require a specific value in one field but one of a set of values from another query - a combination of "and" and "or".

Veer has implemented one approach in his fork where he allows an option to say "use or instead of and" and another to say "use and for the first field, then or for the rest". I'm not sure I'd choose to implement the API this way, so looking to discuss before I put code in and create a pull request.

One option would be to allow the caller to pass the filter criteria directly rather than pass JSON and have sharepointer build it - that way they can pass anything they want but they need to understand SharePoint's format.

Another option would be to add something in the JSON to indicate if the field should be ANDed with previous criteria, or ORed. Not necessarily a totally intuitive method, but could work. E.g.

[
   { field: "owner", value: "pete" },
   { field: "status", value: "open", andor: "and" },
   { field: "status", value: "in-progress", andor: "or"}
]

would result in "owner='pete' and (status='open' or status='in-progress')"

This approach gives some flexibility and supports the and/or criteria, but doesn't support things like <>, > etc. It's also not entirely intuitive.

Another option would be to support an array of values and then OR them:

[
   {
   { field: "owner", value: "pete" },
   { field: "status", [ value: "open", "in-progress" ] },
   }
]

Probably better than my other idea, but still limited in what it can do and probably harder to implement.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions