1

I have a search index created using search api and I have a view created based on the search index. I have a taxonomy term field called subscription which is indexed. I need to sort my view based on the subscription field and it should be based on the taxonomy term weight and not by the term name. I am able to add the subscription field in my sort criteria but it doesn't seem to be working the way it is expected.

I referred to multiple links but those seem to work only for views based on content and not based on search index.

How do I sort the view(based on Search index) by taxonomy term weight?

  • Did you look at this issue queue ? – Pravin Ajaaz Apr 13 '15 at 10:01
  • That seems to be related to Apache Solr and I am using drupal search api for creating my view. – Bhuvana Apr 13 '15 at 11:42
2

I'm not sure if you have figured this out yet, but I found the solution to this, so I'll post it here in case anyone else comes along this page.

If you go to your search index and go to the Fields tab, you'll see at the very bottom there is text that says "Add related fields". It took a while for me to see this there, since it's kind of inconspicuous and under the form submit button. But if you click that and select your taxonomy, it will add the set of taxonomy fields to the available list of fields to index. Check "Weight", then that will be available in your view.

0

Well, I will try to explain my approach.

I didn't use Sorts module. The steps I took are the following:

I made a custom field with this hook: hook_entity_property_info_alter() in a separate module. In my getter callback I found the weight of the term I wanted and returned it as INTEGER like: return intval($weight); I ticked the newly created field to index it and chose Integer as format. Re-indexed the index. Lastly, in my view in Sort criteria I chose Sort ascending and voila!!

  • Sounds interesting. I will give it a try and get back to you. Thanks @geodoo – Bhuvana Apr 13 '16 at 4:14
  • If you need any help with this I can provide some code. Feel free to ask! You are welcome @Bhuvana – geodoo Apr 14 '16 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.