Simple addition to add support for taxonomy terms as filters. There is still weirdness with the urls generated in the facet blocks. All tids are collected into one url argument regardless of if they come from a filter or different arguments (Same as: #566618: Are multiple separate taxonomy arguments possible?)

Not very tested, so let me know if I'm missing something in how this should work.

Comments

jtsnow’s picture

Title: Add filter support for taxonomy terms » Add field/filter support for taxonomy terms
StatusFileSize
new3.59 KB

I also created a filter for taxonomy terms along with a field handler. My filter looks similar to the first patch. I have tested mine fairly thoroughly and it works for me.

Remon’s picture

Version: » 6.x-1.x-dev

patch of #1 works

Scott Reynolds’s picture

Status: Needs review » Reviewed & tested by the community

cool queuing this up to be committed.

tauno’s picture

Status: Needs work » Reviewed & tested by the community

Should the taxonomy term selected in the filter be showing up in facet block links? Using the patch from #1 I get links like:
/url/arg1/(515),7426 (where 515 is the term in my non-exposed filter) instead of /url/arg1/7426

It also causes no results to be returned even though there should be some. Does the (tid) format only work with the 2.x branch of apachesolr?

Scott Reynolds’s picture

Status: Reviewed & tested by the community » Needs work

This should be independent of the apache solr version. So there must be a bug in the patch. It shouldn't make a difference which apache solr integration version you are using.

The only thing really that the apache solr search integration module provides for Solr Views is indexing and some default values.

tauno’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5 KB

It looks like the issue is that the taxonomy term filter was getting grouped in with the taxonomy term argument when generating the url. The reason my initial patch worked and #1 didn't is that I was not properly grouping the selected terms into a sub query.

This patch adds an argument to add_filter() to keep track of if a filter is a views filter or not and then uses that to check if the filter should be added to the argument.

Does this seem like the right approach? Another option I came up with was to check for the presence of ( ) instead of adding an additional value to the _facets array - but that seems like a bad option.

drupalusering’s picture

really cool filter feature you are implementing, but for some reason i get this error message when selecting a filter "Error: handler for apachesolr > tid doesn't exist! "

tauno’s picture

Status: Needs review » Needs work

viktor, in your apachesolr_views/handlers folder, is there a file named: apachesolr_views_handler_filter_tid.inc?

This patch still needs work though, exposed taxonomy filters don't seem to work properly with the facet blocks.

drupalusering’s picture

no the patch for some reason fails to create the file. When i manually created it the view still gets invalid handler error

domidc’s picture

If you expose taxonomy filter, it doesnt play nicely with the facets.

I have applied the patch in #6

The links in my taxonomy facets are build like this: installation/pathtosolrview/[tid]?tid=[tid] , so clicking this I get the tid in my exposed field resulting in "the term not found" because it expects the name of term in ?tid=term_name

When I filter with the exposed form it filters down nicely resulting in following url installation/pathtosolrview/?tid='term_name' Then again the facets links are build wrong resulting in installation/pathtosolrview/[tid]?tid=[tid]

Also when I use the exposed filter of my vocabulairy the facet of the same vocabulairy does not drill down the results.

rssfrrst’s picture

does this patch need updating for the new version released in march? I keep getting errors when I attempt to apply the patch in #6.

torgospizza’s picture

Yeah, the patch breaks almost completely for me. I'm attempting to roll one that works with the latest version. I really need this functionality in apachesolr_views to create a catalog view using solr as the backend.

Will post ASAP.

colinsherry’s picture

Patch works for me but the facets break.

toemaz’s picture

Applied the patch from #6 and hacked my way to a solution

Added template file apachesolr-facet-link.tpl.php and added

  if (!empty($options['query']['tid'][0]['value'])) {
    $options['query']['tid'] = $options['query']['tid'][0]['value'];
  }

before

  $options['attributes']['class'] = 'apachesolr-unclick';
  print apachesolr_l("(-)", $path, $options) . ' '. $facet_text;

Better solution is obviously required.

zualas’s picture

Apart from breaking the facets, the filter has other issues:
1) incompatible with "apachesolr:Search" filter. Gives a PHP error if both taxonomy filter and also the Search filter are filled.
2) Gives a PHP error after clicking "apply" if the term is not present in the vocabulary.

The error in both cases is:

Call to a member function pre_execute() on a non-object in /home/p/www/sites/all/modules/apachesolr_views/apachesolr_views_query.inc on line 311
torgospizza’s picture

The changes in the latest dev build of apachesolr_views has broken the Taxonomy facets for me. (I had them working at one point, using the code from the patch in #6).

Any update to this would be most appreciated.

Scott Reynolds’s picture

The patch from 6 is very broken and I really don't like the change to the add_filter function

It looks like the issue is that the taxonomy term filter was getting grouped in with the taxonomy term argument when generating the url. The reason my initial patch worked and #1 didn't is that I was not properly grouping the selected terms into a sub query.

This is out of scope. Not yet ready to expose subquery support in the Views ui. Its getting there but not there yet (you can do it with filters).

I would like to get #1, without the field stuff, because we already have that set up.

njbooher’s picture

StatusFileSize
new2.39 KB

This patch fixes the PHP error when the provided term doesn't belong to the filter's vocabulary. I don't know how to go about fixing the facet blocks.

zualas’s picture

Patch from #18 doesn't work for me. After applying it, every time I set up an exposed autocomplete filter and try to find something with it, it gives me a blank page.

At the same time, if I have the tid filter and the Solr Seach filter exposed for the same view, it will give an error 'The Apache Solr search engine is not available. Please contact your site administrator.' if I leave the tid filter blank and enter data in search filter. If I enter both or only the tid filter, I am given a blank results page.

njbooher’s picture

StatusFileSize
new2.66 KB

Sorry, I hadn't tested it with autocomplete enabled. Try this one.

njbooher’s picture

StatusFileSize
new2.64 KB

Oops, small problem with that one too. Try this instead.

zualas’s picture

@njbooher: thanks for your work! I tested the latest patch and was able to search by taxonomy terms successfully.

As a next step, I would suggest looking into a possibility to search for node by the taxonomy term translation from the i18 tables, similar to what has been done here for the Content Taxonomy autocomplete. Not sure I can come up with a patch, but I will try to take a look if I can port some code from there.

torgospizza’s picture

Question, does the filter need to be "Exposed" for this to work? I had one of the earlier patches working just by having the Taxonomy Terms Argument in place, but that doesn't seem to work either. (By "doesn't seem to work" I mean, the Facet Block either has a link to the current View I'm on, or it links to a long URL but when you click on it, it doesn't do any actual filtering.

Suggestions? Otherwise thanks for working on this! Really need this functionality something fierce :)

Maikel’s picture

I applied the patch from #21 but when i try to add the filter 'Apache Solr: Taxonomy terms' i get the following message 'Configure filter Broken/missing handler'.
Is there something i am overlooking?

njbooher’s picture

StatusFileSize
new2.48 KB

@torgosPizza: I haven't tested the patch with facet blocks; however, exposing the filter would be required for them to work.

@Maikel: The patch from #21 works for me, though I have since removed some duplicate code locally. See if the attached updated patch makes any difference.

digi24’s picture

@njbooher
Your filter seems only to search for terms, would it be possible to add a filter for tids like it was the case in the first patches?

Or is your patch just an addition to other patches?

njbooher’s picture

Which widget are you using? Dropdown displays term names but works with term ids. If you expose the form you can direct people to pages with certain filters enabled by passing ids through the url. (Eg. http://mysite/insects?type[]=157).

digi24’s picture

@njbooher
Thank you very much, the dropdown solved my problem, I did not realise the difference between the two widgets.

The patch in #25 is working fine.

torgospizza’s picture

Thanks for the patch! It seems to work well with an exposed form (even an exposed form in a block). Haven't yet tested it with multiple terms yet. However it's only halfway there - getting the facets to work is my next step, and one I'm really hoping to fix. For now I could hard-code some URLs in there as described in #27, but in the end that's not a good solution, since adding new terms becomes a chore when you have to add links all over.

Since the facets still don't work, and having an exposed form of any kind is kind of...ugly, I'm going to try and figure out why the facets were working for me at one point and see if I can roll a patch that will solve it. If others get there before me, even better. :)

EDIT: Unless, Scott, you're still not ready to expose some of the subquery stuff. I read through this thread again and it sounds like there are still some things that need to be fixed/cleaned up before we can have solid taxonomy term filtering happening. Is this true? What can we do to help get it there? Thanks again for the great module.

kenorb’s picture

URL for Taxonomy terms as exposed filters looks weird:
&tid[0][value]=366&tid[0][exclude]=&sort_by=changed&sort_order=ASC
Related issue: #856522: Taxonomy facet blocks no longer working

floretan’s picture

Note that the patch from #25 uses an "or" operator even when the filter settings are set to "and".

njbooher’s picture

StatusFileSize
new2.54 KB

Patch updated to use the correct operator. For those seeking facet block support, see #906508: Fix exposed filter facet blocks.

digi24’s picture

Thanks njbooher, filter now works as expected.

kenorb’s picture

Status: Needs work » Needs review
tauno’s picture

Assigned: tauno » Unassigned

Unassigning from me.

dstuart’s picture

Status: Needs review » Reviewed & tested by the community

Have Applied the Patch and works as expected other than the uglyness that is brought up in #30

ordually’s picture

Thanks for the great patch! It's working great with #906508: Fix exposed filter facet blocks. Fit the bill for just what I needed, to allow users to filter the view results by multiple vocabularies.

@Maikal in #24: I had the same issue you're seeing. Turned out to be an issue with how I was applying the patch file. The patch is 2 changes, one of which is the creation of a new file "handlers/apachesolr_views_handler_filter_tid.inc". When I ran

patch < apachesolr_views_taxonomy_2.patch

it created the file "apachesolr_views_handler_filter_tid.inc". Note the missing "handlers/" in the path! Reading the patch man page makes me suspect that it *should* have put it in the proper path. Check if your file is in the "apachesolr_views" directory instead of the proper "apachesolr_views/handlers" directory.

kenorb’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Rajesh Ashok’s picture

#32 works for me