Hi, this question is very simple and probably there are good tutorials on how to do this, but i didn't find anything. If you have a tutorial, please post a link.
I need to create a custom search form that has various fields and those fields performs search only on the relative field.
This means that if i have a content type with the following fields:
"job requested"
"previous exerience"
"city"
i want a search page with the same three fields and when the user enter a value in the "city" field, it searches for that data only in that field: if i search the "city" field for "milan" i want to find only nodes with the word "milan" entered in the field "city" and not with the word "milan" entered in the body.
I think i need separete indexes for each fields, but how must i realize the form?
Comments
Comment #1
drunken monkeyNo, there currently aren't any tutorials for most of such uncommon tasks, and this sadly also isn't that simple to do.
First off, it is not possible to set several independent fulltext keywords for different field values (in a way that they influence the results' scores). You have to use the keys of one field as the "normal" search keys (and set the searched fields to that field) and the others as filters.
Do all three of these fields contain fulltext data, or are some of them simple strings which should only be found when entered in that exact way?
In any case, it should probably be possible to simply build such a form with the "Search views" module. Just add all three fields as exposed filters and select "Use as: Search keys" for only one of those.
When you want to build the form yourself, I don't really know what you need to know. Just build the form for the user to input the data and then use a search query to retrieve the results, like this:
And no, you don't need separate indexes, just index all needed fields in one index.
Comment #2
nicola.peluchetti commentedthank you for the quick answer. All those fields are just string fields where i need an exact match. Maybe in this way it's easier to implement such a thing?
Comment #3
drunken monkeyYes, in this case you only need the
condition()method and should call it for all three fields with the appropriate values. You can also build a view normally, adding three exposed filters.But if you only need exact matches, you could probably even use a normal view and don't need the Search API at all?
Comment #4
nicola.peluchetti commentedWell, when i understand exactly how views work you might be right. If you think this can be done only with views, i'll try that path. The problem is that views 3 hasn't got a documantation and i'm new to Drupal, i'll try this too!
Comment #5
drunken monkeyWell, no, not only. You can of course also code your own form.
However, Views already has all of this set up, and when you want to use Drupal, you'll practically have to get comfortable with Views at some point anyways. I know, the documentation always lags behind, but I'm sure there are a few good tutorials out somewhere. Or, just play around with it, the UI isn't that unintuitive anymore, I think.
Comment #6
drunken monkeyI guess this is fixed now …