Problem/Motivation

When adding an entity's title field to an index it defaults to using the "string" data type, which means the field's contents are not findable by searching the index. This results in a bad experience as additional steps (changing the field type) are needed for what would be the expected use case.

Proposed resolution

Change all "string" -like fields to use the "Fulltext" data type.

Remaining tasks

Work out how to make known string-like fields default to the "Fulltext" data type.
Make the change.
Write text coverage.

Comments

DamienMcKenna created an issue. See original summary.

drunken monkey’s picture

Status: Active » Needs review

Thanks for creating this issue.

The attached patch would implement this change for the string type, it could of course also be expanded to encompass similar types (listed in the same array structure). However, there are also some string fields where String is the correct Search API data type, making the experience confusing the other way round. As I don’t think its possible to, generically, distinguish between the two, we are left with the choice in which way we want users to be confused. (Filtering, facetting and sorting might not work correctly for machine name-like fields indexed as Fulltext.)

Before making this change, I’d therefore appreciate more feedback/opinions from others on what the default should be. I’ll post the issue in #1188562: [meta] Important project announcements and hope that some feedback will come in.

mandclu’s picture

I always thought that fulltext fields were used for indexing towards relevance, and string fields for matching/filtering, facets, etc. Not sure if that distinction still holds true.

If it is, I would be against changing the default behaviour personally. Typically I'll index the rendered content for relevance, and then index specific fields to use as filters or facets.

marios anagnostopoulos’s picture

Probably a poll would help here(?) It's just a matter of preference IMO.

The string type is useful for exposed filters, facets etc. and you would not want those fields to be mapped as keyword fields.

In my experience, most of the filtering is done via exposed filters or facets, and you would not want the fields used for them to be mapped as keyword fields, since you don't want any fuzziness to apply when using them to search/filter.

There might be cases where you only use text search, but most of the times you would want to combine a full text search with filters of some sort, and although many of the filters might be coming from non string fields (entity references etc), I think there is a higher chance of needing more string fields than keywords fields. Then again it is kinda pointless to argue about it since it is implementation/business requirement dependent and may vary.

I agree with the point that

I don’t think its possible to, generically, distinguish between the two, we are left with the choice in which way we want users to be confused

so although I would generally prefer for it to stay as it is, I don't thing it really matters that much.

markabur’s picture

Most of the cases where I use Search API need sorting and filtering, so for me the current behavior makes more sense than defaulting to fulltext for everything. But I'm mindful of the difference when I'm setting up the index, so it doesn't really matter.

dorficus’s picture

I'm definitely in favor of changing over to fulltext. From the description from the Data Types section of admin/config/search/search-api/index/default/fields it says

Fulltext fields are analyzed fields which are made available for fulltext search. This data type should be used for any fields (usually with free text input by users) which you want to search for individual words.

From that description, I'd think that most of the user input fields should be fulltext.

It also seems, and I should mention that I'm relatively ignorant when compared to a lot of people when it comes to Search stuff, that SOLR uses fulltext pretty heavily. I can't speak to facets or filters and the implications of changing over for them, but my opinion, after recently changing several fields over from string to fulltext, is that fulltext should be the default.

Again, I admit ignorance, so if there is a strong argument against, this is definitely not the hill I'm going to die on.

maskedjellybean’s picture

I agree completely with changing the default to fulltext. I don't know why we assume a text field is being added in order to use as a facet. I've done a lot of that too of course, but facets is a separate module. I think text fields should be indexed using the data type that would make them most useful by default with only search_api installed.

marios anagnostopoulos’s picture

@maskedjellybean We don't assume facets will be used, we mention them in the same context as exposed filters, which also use the string type (I believe)

BTW am I the only one not seeing a patch?

mkalkbrenner’s picture

Changing the default type to full text might cause that people think less about their configs.

I see the same error in the index configs again and again. As a rule of thumb, adding more fields to Solr or elastic search leads to fewer or worse results!

Even with the database backend the algorithms for the query parsers are not entirely specified if you search across multiple fields.

From my point of view full text should be the default type for aggregated fields. Separated fields should only serve special use-cases like facets, filters, etc.
Therefore string is the correct default type.

Again, ideally an indexed entity should only have one full text field searched at query time.

marios anagnostopoulos’s picture

Some engines (I know that it applies to elasticsearch for example) have optimization processes for fulltext fields.

This means 2 things:

  • Unnecessary overhead might be introduced if those optimizations are executed for fields that do not require them, (because it has become the default behavior and the developer did not bother to change it)
  • If left as string fields and used for fulltext search elastic would throw an error/warning complaining that it will be a big performance issue to execute fulltext searches using fields since they have not been preprocessed (tokenized / analyzed / stemmed or w/e)

The initially mentioned performance overhead, is probably insignificant in smaller applications and would not apply to very junior people or straight up site builders, while anyone might just use a fulltext filter in a view while having the elastic connector installed, and crash their search page.

@mkalkbrenner I believe that was partially your point as well right?

mkalkbrenner’s picture

Fultext is the right choice for most searches.
But you should avoid to have multiple full text fields.
Not because of performance penalties but because of the quality of search results.

Each field you configure as full text becomes selectable in views for full text search boxes.
What if you select "all terms must exist"?
Does it mean all terms in one field or split across multiple fields. If you carefully think about all available query parsers and search modes selectable in views, you'll recognize that any combination has a kind of undefined or unpredictable behavior if you select multiple fields.

In former times we had one "content" field in the Solr schema where we copied all text or string fields too.
But as we merged the competing Solr projects of D7 we adopted Search API's flexibility and freedom of configuration.

From my point of view we must educate the users to use only one (or a few targeting different use-cases) combined / aggregated fields to index the "string" content of their entity fields as full text instead of setting full text as default type for any string field which will lead to more selectable fields in views and finally worse results.

Anyway, it is just my opinion and I want to share my experience. Maybe we can improve the out of the box search experience here.

drunken monkey’s picture

Status: Needs review » Active

BTW am I the only one not seeing a patch?

Ah, yes, I forgot to attach it. Sorry!

Anyways, looks like it’s not needed at the moment, as we have a majority for keeping the current behavior:

  • In favor of change (3): DamienMcKenna, dorficus, maskedjellybean
  • Against change (4): mandclu, Marios Anagnostopoulos, markabur, mkalkbrenner

My bias is also anti-change in general, as it’s better to be consistently confusing than switch between different confusing behaviors.

Also, I’m rather convinced by mkalkbrenner’s description, as he has probably the most experience with debugging inexperienced users’ setups.

I’m keeping this open for now, in case someone has still a good argument to make pro-change, but this would be “won’t fix” currently.

damienmckenna’s picture

There are plenty of reasons to have multiple "fulltext" fields on a given index.

There's the assumption that the rendered output will be fulltext, either using the "full" view mode, so that's one.

The entity's label (e.g. node title) needs to be a fulltext field because the rendered entity output doesn't include the label/title, so that's two.

Then there are often fields which aren't included in the regular "full" rendered view mode but also need to be added, e.g. summary text fields used on teasers, so that's three or more.

Then add something like meta tags (#2901039: Add a TypedData plugin to support Search API) integration, extra fields used for boosting specific entities in the results, etc, etc.

So saying a site should only have one or two fulltext fields is a major assumption on content architectures.

drunken monkey’s picture

@ DamienMcKenna: There’s the “Aggregate field” field type for this. Just create one fulltext field containing all the fulltext fields you want.
Also, this has nothing to do with the issue in question anymore.

mkalkbrenner’s picture

FYI: Within Search API Solr we now have the auto_aggregated_fulltext_field which is comparabel to the old "content" field in the Solr schema of Drupal 6 and 7.

vivek panicker’s picture

I just created a new site and I was not aware that only full text fields were searchable.
It took me a long time to get to know this fact.
If indexed fields are fulltext by default, then it would be very helpful for those setting up a new site, since if someone is setting up a search index, they would surely want to search for content also.

mkalkbrenner’s picture

On more important note: facets can only be built from simple types like string or numeric, not from fulltext fields.

vivek panicker’s picture

Yes, that is true.
But for facets, we need to install an additional module.
Those who don't install that module and only need search available, which this module provides, for them searching will not work because the fields are not fulltext fields.
I was wondering if we could like have default fulltext fields, then when the facets module is installed, clone the fulltext fields to text fields, using hook_modules_installed().