Using Taxonomy fields in Queries module

Topics: Core
Sep 19, 2014 at 2:08 AM
I am assisting non-programmers to get Orchard configured for a small hobby site. I'm trying to get as much done through the Admin UI as possible. I'm having difficulty working with Taxonomy type fields when creating queries in the Queries module.

Basic scenario - the site has four content types corresponding to research library entries. I created a Content Part via the Admin UI that holds three standard fields - a text field for contributors names, a taxonomy field connected to an alphabet taxonomy so that each entry is given an "Alpha Key" regardless on content type, and a taxonomy field connected to a common completion status taxonomy. Each of the four content types uses this part.

I would like to create a query where all library entries with Alpha Key "A" (or whatever character) are displayed in a list, grouped by content type, or even all entries from a single content type with an Alpha Key value of "A", ordered by most recently modified. In general, I can't figure out how to combine taxonomies with anything else in queries.

I've searched these forums, searched on line, watched YouTube videos, trying to find an answer, even if the answer is "It won't work that way," so I hope someone here can point me in the right direction. I'm looking for an approach that uses the Admin UI, not doing any custom code or module, though I'm happy to install someone else's module that would do this.

My thanks in advance for any assistance.
Sep 27, 2014 at 5:35 AM
OK, from the dead silence greeting this post, I will assume that Orchard is not capable of allowing me to use taxonomy terms in the Queries module, even if the term set has been made a part of a content type. Creating a query with that content type does not expose the taxonomy type field for any sorting, filtering or other action.

This is incredibly disappointing. I know lists have been deprecated, so what exactly should I be doing to be able to build a reasonably simple query - show me all records of type X where property Z is [value]? If a taxonomy field cannot be made part of this kind of query, and I shouldn't use a list to provide categorization information, what am I supposed to do if I need to query that content type using that category value?

And, FYI, I do custom coding and have developed/supported enterprise CMS applications for over 17 years. I presume it can be done with custom code. My point is I can't do it with the Queries module, which is what the admins of this hobby site need to be able to do.

My thanks in advance for any assistance, or even just a formal confirmation that Orchard cannot deliver this functionality at this time.
Sep 27, 2014 at 6:35 AM
Edited Sep 27, 2014 at 6:36 AM
I just checked, and I was able to do the following:
  • Define a new taxonomy called Category (just as an example) and some terms (Category 1 through 4);
  • Attach a taxonomy field to the Page content type;
  • Create a new query with the Has Terms filter, selecting all Page content items that has Category 2.
This query successfully returned all Page content items tagged with "Category 2".

Orchard.Lists is no longer deprecated - it has been revived and revamped. Some further late improvements have been made, including playing nice with projections, so you might want to download the 1.x branch to try this out.

Hope this helps.
Sep 27, 2014 at 11:21 PM
Yes, it certainly does!

I feel very foolish for having missed that one selection in Queries. I was under the impression that since I had selected the content type, which had a taxonomy field, that the field would be available like the other fields in the content type. I know I used the "Has Terms" filter, so am at fault for not having paid attention and seen the "Has Terms" filter right next to it.

So, I now know that I can set up a query where one of my content types (say, Biographies) can be filtered by the Alpha Key taxonomy field. What I am not seeing (Perhaps because I am not looking in the right place? I've looked at all the selections and none of them seem to do what I need, unlike the "Has Terms" filter.) is a way to either sort by a taxonomy value or group by that value. I anticipate needing to do variations on the following queries:
  • Show all Biographies where the Alpha Key is "[Letter]" - this I can do with "Has Terms"
  • Show all Biographies where the Tag is "[Occupation]" (Use "Has Tags") and sort them by Alpha Key order - I can't find a way to sort by Alpha Key, though I can sort the taxonomy itself.
  • Show all Biographies with Completion Status "Complete" (Use "Has Terms") and group them by Alpha Key - I can't figure out how to group by Alpha Key
I will experiment with the Lists Module since it is no longer deprecated. I also see you have a number of recent posts addressing various topics I'm interested in, so I will be reading and trying them out.

Design question - given the kinds of queries I want to create (the examples above are representative of 85% of the queries I would make) am I better off using Lists or Taxonomies?

Thank you very much for taking the time to correct my error and point me in the right direction.
Sep 29, 2014 at 10:33 PM
You're welcome.

Regarding your design question, I think you're better off using Projections and Taxonomies, but definitely try Lists.

Alternatively, you could work with the Enumeration field, where you get to specify a list of options (similar to the TaxonomyField, but less advanced). Using EnumerationField, you can have the query sort on that value.
I'm afraid you currently can't sort on a taxonomy term. Someone will have to implement such a sort criteria provider.
Sep 30, 2014 at 12:23 AM
Edited Sep 30, 2014 at 3:13 AM
I will look into the Enumeration field so that I understand what it can do.

I'm a little confused on what exactly I need to download to try out the Lists feature - link? (Edit - never mind - I figured it out...)

I like the Taxonomies - they are much more powerful than the usual lists I wrestle with and more like the Managed Metadata terms in SharePoint. Come to think of it, I can't group or sort on MMD fields, either, though they're unbeatable for search.

You've been incredibly helpful and I appreciate your responses to my questions.
Oct 1, 2014 at 3:38 AM
You're very welcome. Let us know if you have any other questions, we're happy to help wherever we can.