Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support query by meta_query even if metadata is of Taxonomy type #236

Closed
leogermani opened this issue May 17, 2019 · 2 comments

Comments

@leogermani
Copy link
Contributor

commented May 17, 2019

Currently, when you query by items filtering by a metadata, you must know whether the metadata is of Taxonomy type or not. If it is a Taxonomy metadata, then you have to build a tax_query, otherwise, you can build a normal meta_query.

This is something that adds a bit of work, but it is a good way to build a query.

However, tax_query does not have support to query for items and, at the same time, perform a search in the terms. For example, I can only query for posts that have the term Rock or the term Progressive Rock, but I can not query for posts that have any term with the string Rock, resulting in posts with any of the two.

To solve this, and to make life easier for those querying for items, the propose is to add a bit of intelligence to the Items Repository which will check to see if there is a meta_query filtering items by a Taxonomy Metadata. In this case, it will replace this meta_query with a tax_query, after searching for terms if the compare clause is set to LIKE.

leogermani added a commit that referenced this issue May 17, 2019
leogermani added a commit that referenced this issue May 17, 2019

@leogermani leogermani added this to To Do in tainacan/tainacan May 21, 2019

@leogermani leogermani self-assigned this May 21, 2019

@leogermani leogermani added the 0.10 label May 21, 2019

leogermani added a commit that referenced this issue May 22, 2019
@leogermani

This comment has been minimized.

Copy link
Contributor Author

commented May 22, 2019

This turns out to be more complicated.

The transformation works, but in WP_Query, everytime you combine a meta_query and a tax_query, the logical operator between the two will always be AND.

So if you make a search with multiple meta_queries, with relation set to OR, the transformation would break you query, because tax_query would always have an AND operator...

This raises some issues and ideas

Relationship metadata

Currenty, when you set up a Relationship metadata, you can choose which fields in the target collection you want to use to perform a search when editing an item and filling in the relation (let's call it "search metadata"). If you choose a Taxonomy metadata, this search is currently not working. (I will open an issue for this), because the component is performing a search using only meta_query, and not the appropriate tax_query for chosen metadatum.

Even if we fix this, it would break the search because, if the user selects several metadata to search, the taxonomies would have an AND operator and the search would not bring the expected results.

To solve this we could:

  1. Do not allow the use of taxonomy metadata to be chosen as one of the "search" metadata in a relationship metadatum
  2. Let the user select only one metadata to use as the "search" metadata, and not several
  3. Add a modifier to WP_Query to allow to change the logical operator between meta_query and tax_query to OR. (see idea below)

Idea: modifier to WP_Query to change relation

We would have to investigate to find if this is doable, but we could add a modifier to the WP_Query arguments array to force the relation between meta_query and tax_query to OR.

We could test it BUT we would have to do the same tweak in the Elastic Search integration.

Idea: Add support for LIKE operator to Tax_Query

It sounds like a good idea to add support to do a LIKE search to the Tax_Query. It could be useful in many situations, giving more flexibility to filters and to an advanced search.

This could be done as it is in this proof of concept here:

public function transform_meta_query_to_tax_query($args) {

The advantage is that it would work fine with the elastic search integration. The disadvantage is this can create some problems for very large taxonomies...

This could also be done by filtering the SQL statement. The advantage is less use of memory (I'm not sure about how the query would perform). The disadvantage is that we would also have to tweak the elastic search integration in order to make it work.

mateuswetah added a commit that referenced this issue Jun 4, 2019
Removes Taxonomy metadata from metadata for search list on relationsh…
…ip metadatum edit form while something as the proposal on Ref. #236 is not feasible.
@leogermani

This comment has been minimized.

Copy link
Contributor Author

commented Jun 5, 2019

Our decision was to limit the configuration of the Relationship metadata to restrict "search" metadata to non-taxonomy ones.

Also, we think that the kind of "magic" this issue propose can lead to a lot of confusion and decided not to implement it.

But, we do think that add support to the LIKE operator to Tax_Query in the Tainacan API is a good idea and we will go for it. We are opening a new issue for this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.