5

I have a content type and the content type has a taxonomy term field (tags) and a entity reference field (author as another content type).

I'm trying to create an "advanced search" with views exposed filter.

enter image description here

What I want to do is to allow users to search in node titles and inside these fields without an autocomplete function. I don't want to force the users to write and select an author, but I want to let them to write a word and then search.

For example:

If a user enter John in the author field then search; all the nodes should be listed with the authors name that include "John": John A., Michael John, Another John etc.

How can I do this?

  • I don't know with this module but you could write your own queries. – GwenM Dec 30 '15 at 9:17
  • If I type something in "seach in titles" and "search in authors" does it look for the title the author wrote? If not you don't really need a entity reference for authors, just authors name field is enough. IMO using your custom queries will do the trick. – GwenM Dec 30 '15 at 9:31
2
+100

Use relationships to expose the exact field, for instance use taxonomy relationship and then instead of the taxonomy field expose taxonomy term name with the relationship selected. Do the same for entity reference.

  • It works like a charm. :) Need to test more. Thanks a lot. – herci Jan 5 '16 at 22:54
1

I think the best way to achieve you goal is to use search_api module that provides a rich set of options alongside views, besides indexing based on the fields that you need to search by which increase performance especially in case of your data becomes big over time and have millions of records.

It provides faceted search that lets you create a facet search easily or use views if you need.

The default search server will be your DB or you could use apachesolr or elasticsearch if you need high performance search.

Good tutorial on using search api found here

1

Combined fields filter with Entity Reference does not work, I found Combined fields filter not working with entity reference.

Therefore, you will have to use it as a standalone, not combined, filter until this bug is fixed, which does not look like it will be any time soon.

1

I believe that what you need is: Global: Combine fields filter. This is a filter provided by Views out of the box. In this filter's settings you can (1) add your 'author field', or even more fields (2) set the Operator, provided by that filter, to: Contains all words so to return results like you said:

If a user enter John in the author field then search; all the nodes should be listed with the authors name that include "John": John A., Michael John, Another John etc.

and (3) it is working as a simple text field, not as an auto-complete field.

I Hope that helps!

Update:

I admit that my answer is incomplete but it is working, however there is a peculiarity: if you look closely the View's query that is being constructed , and especially the where clause, for that particular field type (entity reference or term reference) you will see that includes the field_name_target_id/field_name_tid field instead of the field_name_value field and while you are searching for text it's reasonable that you get no results, but if you search with the nid/tid you will get the desired results. So all you have to do is to include in the where clause the field you want to search at and hook_views_query_alter is the most appropriate hook. Of course the use of relationships is acceptable, but I just wanted to make it clear that it is working and that it is not a bug, in my humble opinion.

  • Thanks for your answer. I had already tried it but it doesn't work for taxonomy terms and entity references. – herci Dec 31 '15 at 16:29
  • 1
    I have done this for many Views with many type of fields and it's working, what is not working for you, the search results the filter or nothing at all? – mchar Dec 31 '15 at 17:02
  • I tried this both in a "normal" Views and in a Views with Search Api index but none of them work. It simply doesn't give a result. Could you please explain it step by step then I can check if I miss something. Thanks. – herci Dec 31 '15 at 17:04
  • If you get no results, perhaps your problem has to do with your query, I mean the way it is constructed. Be sure that what you are searching for exists. – mchar Dec 31 '15 at 17:41
  • 1
    @mchar Combined fields filter with Entity Reference does not work, see my answer over here – No Sssweat Jan 5 '16 at 4:49

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.