appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.89k stars 470 forks source link

Seeking clarity on customQuery prop for base components #278

Closed timtutt closed 6 years ago

timtutt commented 6 years ago

Issue Type: Question

Description: I just had a clarifying question on how customQueries are handled. Through a bunch of playing around with customQueries on the MultiListDropdown it appears that the query passed there only updates the query context and not necessarily the aggregations?

Specifically - As I change that customQuery it seems to be added to the bool->must section of the query and the aggregation continues to be executed as intended with this component.

The documentation seems to indicate that one might be able to change the entire behavior or result sets of the query as is the case with custom reactive components, but that doesn't seem to be the case.

I actually think this behavior is fine - but I think the docs could be a little more clear on how it actually functions.

I'm also curious as to how the components decide whether that custom query gets added to abool->must rather and a bool->must_not or bool->should? Is that based on the react prop in the component?

Btw - this is an amazing project - I have so many uses for it. Kudos!

Screenshots: N/A

Minimal reproduction of the problem with instructions: N/A

Reactivesearch version: 2.2.1

Browser: all

Anything else: N/A

metagrover commented 6 years ago

Thanks for writing in. We are glad that you're using reactivesearch 😄

I'll try to answer both of your questions here:

Through a bunch of playing around with customQueries on the MultiListDropdown it appears that the query passed there only updates the query context and not necessarily the aggregations?

In components like MultiDropdownList, we run an aggregation query on the dataField which is an expected behavior for most generic use-cases. If you wish to update the aggregations query, you should try ReactiveComponent. It lets you customize the complete behavior and enables you to talk to other Reactivesearch components seamlessly, thereby allowing you to add any React component to Reactive family.

How do the components decide whether that custom query gets added to a bool->must rather and a bool->must_not or bool->should? Is that based on the react prop in the component?

You're spot on here. The bool query is decided by react prop, where we use the following conjunctions:

i.e. If we have 5 components say A, B, C, D and E, with A as:

<ReactiveComponent
    componentId="A"
    react={{
        and: "B",
        or: "C",
        not: ["D", "E"]
    }}
/>

This will generate the following query:

must: <B>,
should: <C>,
must_not: [<D>, <E>]

Hope that helps! We will update our docs to clarify this in more detail there.

timtutt commented 6 years ago

@metagrover - Thanks much this is exactly the type of clarity I was looking for. And it makes perfect sense.

Might I also suggest updating the documentation to display the defaultQuery and what the query is set to on onChange events for each of the base components? The reason I was actually digging into this is because I noticed that the MultiListDropdown was adding selected values to a terms query in the bool -> must section of the query when I had it listed to and with itself.

{
   "bool": {
      "must": [
         "terms": { "MessageTo":  ['firstSelectedVal', 'secondSelectedVal', 'thirdSelectedVal'] }
      ]
   }
]

In the above case I was looking for messages sent to all three of the recipients rather than any of them. Even though I had the value in the and it wasn't behaving properly because of the terms query.

This wasn't the behavior I wanted - terms queries select any filter on of the values and not all of the values. I was able to write a customQuery to correct the issue, but it took a lot of digging to figure out what the component was doing by default. Would be nice to know what the default queries are for the standard components.

(Perhaps I should post this as a separate issue)?

Thanks again!

metagrover commented 6 years ago

Makes sense. We should highlight the defaultQuery of the components in the docs.

And, as far as your use-case goes, you should check the queryFormat prop in MultiDropdownList. It accepts two values: or or and, where or (default) - considers any and, and considers all the selected values.

Check it out in action here - you can toggle the knob between and / or to see the difference 🎉

timtutt commented 6 years ago

Oh! I don’t think I realized the queryFormat property existed. Will dig into that.

Thanks!

On Feb 22, 2018, at 9:08 AM, Deepak Grover notifications@github.com wrote:

Makes sense. We should highlight the defaultQuery of the component in the docs.

And, as far as your use-case goes, you should check the queryFormat prop in MultiDropdownList. It accepts two values: or or and, where or (default) - considers any and, and considers all the selected values.

Check it out in action here - you can toggle the knob between and / or to see the difference 🎉

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

metagrover commented 6 years ago

Closing due to inactivity. Feel free to re-open if you're still facing this issue!