All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Multiple Search Fields Issue with matrix fields

RobertGranlund 23 Dec 2015 21:14 question, complete

I am having a hard time figuring something out with Low Search and cannot find any documentation on this issue.

I have a search form where you can enter a keyword and then I have two select drop-downs. On the select drop-downs, each option is set to search a specific matrix field. I want to be able to set multiple select options so when the search runs, it searches the specific option fields I have chosen and only those. In addition, I dont want it to filter, meaning the keyword does not need to be found in both of the matrix fields, it can be found in either.

Also, I am wondering if there is a way to set multiple search.matrix_field:field on a single option? I hope someone gets back to me cause this is getting kind of serious on my end and I don't want to have to start over with a different search plugin option.

Replies

  1. Low 28 Dec 2015 18:56

    If you're using the Keywords filter, you can't target a specific Matrix column. (Searchable Matrix and Grid columns are concatenated together into a single searchable string, which Low Search uses for its keywords index).

    If you want to target a specific Matrix column, you'll have to use the Field Search filter. This isn't as flexible as the Keywords filter (instead, it works identically to the native search: parameters, but can target Matrix cols), but might suit your needs here.

    If you want a single input field for search terms, and a drop down for choosing which Matrix column you want to target, you can use a custom extension, or you can use JavaScript to modify the name="" html-attribute of the search terms field based on the value selected in the drop down.

    You can't target multiple fields/columns in one parameter using the Field Search filter. For that, you need the Keywords filter, where all searchable fields are given a weight >= 1. Note that, in this case, searchable Matrix columns are treated as a single field.

  2. RobertGranlund 28 Dec 2015 19:10

    Can you show me an example of how to write the following:
    "You can't target multiple fields/columns in one parameter using the Field Search filter. For that, you need the Keywords filter, where all searchable fields are given a weight >= 1. Note that, in this case, searchable Matrix columns are treated as a single field. "

  3. Low 28 Dec 2015 19:19

    You'll have to create a Collection, which is used by the Keywords filter. Make sure the Matrix field itself is searchable and the appropriate columns are marked as searchable, too. If they weren't, re-save each entry to populate the searchable data. Then make sure the Matrix field has a weight >= 1 in the Collection settings, and build the index for your Collection.

    Then you can use the Keywords example, which should return entries where the search terms are present in the Matrix field.

  4. RobertGranlund 28 Dec 2015 19:28

    What I am trying to do is the following:

    Is this possible or is there a different way to do this?

    Low 28 Dec 2015 19:56

    Can you verify this reply? Looks like something was stripped out.

  5. Low 28 Dec 2015 19:31

    I think GetSat might have stripped some content from your last reply. If you're sharing code, try using http://pastie.org/ or http://pastebin.com/

  6. RobertGranlund 28 Dec 2015 20:56

    Here it is again and also an image of it:

  7. Low 28 Dec 2015 21:06

    No, that's not how Low Search (and web forms in general) works.

    Use name="keywords" and the Keywords filter instead, if you need to target multiple fields combined with OR.

  8. RobertGranlund 28 Dec 2015 21:25

    Can you please show me an example of that and the use of OR? Can name="Keywords" be used on a Select/options?

  9. Low 28 Dec 2015 21:45

    For example, if you create a Collection where you give weight to fields "Title", "Foo", "Bar" and "Baz", and use this:

    <input name="keywords">


    And you search for "lorem", then LS will return entries where Title OR Foo OR Bar OR Baz contains "lorem"; all searchable fields are basically one big single searchable field, together.

    You *can* use something like this:

    <select name="keywords"> 
    <option>Lorem ipsum</option>
    </select>


    ...which will use the keywords "Lorem ipsum" in the same way as above. Depending on the keywords:mode, it will return entries where the combined Title, Foo, Bar and Baz fields contains Lorem AND Ipsum (for keywords:mode="auto" and keywords:mode="all"); Lorem OR Ipsum (for keywords:mode="any"); "Lorem ipsum" exactly (for keywords:mode="exact").

    If you need help implementing Low Search on your site: I offer implementation aid for a flat fee. If you're interested in that, you can contact me directly.

  10. RobertGranlund 28 Dec 2015 22:08

    I'm still not understanding how I can use a text input or select to search 3 or 4 specific matrix fields that are in different channels. I have a form where a user can search for entries that have a PDF attached to the entry, a Video or an image. The videos, PDFs and images are all contained in a matrix field , There are 3 or 4 different matrix fields in 3 or 4 different channels that I want to search specifically with is NOT Empty. Does that make sense?

    I also have noticed that if I enter Avia i my search keywords it works 100% but if I enter Avia NX it does not. I have it set to keywords:mode="any"

  11. Low 29 Dec 2015 06:59

    Keywords will search one or more Collections.
    Collections consist of one or more searchable Channel Fields.
    If the Field is a Matrix or Grid field, the field consists of all searchable Columns.
    That's how you could search multiple fields across multiple channels with a single input field. I don't know how else to explain it to you.

    What the Keywords filter *doesn't* let you do, is making sure specific fields (or matrix columns) are empty or not. For that, you would need to use the Field Search filter, which can target specific fields or columns. You *can* combine the two filters.

    Also note that attaching a PDF to a field will not make the content of the PDF searchable. It will just use the file name.

    So, if you make sure your collections are set up properly, and you use this set of parameters (which can be any combination of form input fields or hard-coded parameters on the Results tag):

    keywords="lorem ipsum" search:matrix_field:column_name="not IS_EMPTY"


    ...you get entries that contain "lorem ipsum" AND where the column_name of matrix_field is not empty.

    So, if you use this:

    keywords="lorem ipsum" search:matrix_field:column_name="not IS_EMPTY" search:other_matrix_field:other_column_name="not IS_EMPTY"


    LS will check if the entries contain "lorem ipsum", column_name of matrix_field is not empty AND other_column_name of other_matrix_field is ALSO not empty.

    This will require both matrix fields to belong to the same channel. If they don't, the column name of one matrix field will always be empty, so you will get No Results all the time.

    There are 3 or 4 different matrix fields in 3 or 4 different channels that I want to search specifically with is NOT Empty.


    This is not possible with Low Search (or any other search add-on that I know of) out of the box. The only way to perhaps get the functionality you're after, is to use a custom filter, where you can create custom SQL queries. But I reckon even that is quite tricky to accomplish.

  12. RobertGranlund 29 Dec 2015 15:51

    OK, this is pretty much were I am going. I think I can accomplish this with hidden input fields and dynamically populate them with jQuery.

    But to make sure I am clear, with this example:
    keywords="lorem ipsum" search:matrix_field:column_name="not IS_EMPTY" search:other_matrix_field:other_column_name="not IS_EMPTY"

    1. if it is a text input, can keywords="" be empty?
    2. Can I use multiple text input fields with the same setup?

    Finally, you mentioned the following:
    keywords="lorem ipsum" search:matrix_field:column_name="not IS_EMPTY" search:other_matrix_field:other_column_name="not IS_EMPTY"

    LS will check if the entries contain "lorem ipsum", column_name of matrix_field is not empty AND other_column_name of other_matrix_field is ALSO not empty.

    Is it possible to write the input in a manner so is that it is NOT AND but OR? for example;
    keywords="lorem ipsum" search:matrix_field:column_name="not IS_EMPTY" OR search:other_matrix_field:other_column_name="not IS_EMPTY"

  13. Low 30 Dec 2015 08:43

    1. if it is a text input, can keywords="" be empty?

    Yes.

    2. Can I use multiple text input fields with the same setup?

    You can't use multiple instances of the same parameter, no. So no multiple name="keywords" or keywords="".

    NOT AND but OR

    No. All parameters are combined with AND, as is the case with all EE tags. I have looked into using OR, but that goes against the whole parameter paradigm, and I haven't found a stable and robust solution for it. So for now, you'd need a custom filter to combine parameters like that with OR.

  14. RobertGranlund 30 Dec 2015 21:55

    This answers that for me, thank you.

    Where is the best tutorial for creating a search result filer?

  15. Low 31 Dec 2015 09:09

    There's the development docs, starting here: http://gotolow.com/addons/low-search/...