Currently in Search API there is the assumption that some processors can transform the text from field values to tokenized text type.
We should make sure this logic is really robust and in the core of Search API. I believe this logic is broken now and it should have tests.
One proposal is to always convert text to tokenized text before sending it to the processors so that the processors can process the text in a consistent manner.
I'd like to hear the opinion of Drunken Monkey and others here.
Estimated Value and Story Points
This issue was identified as a Beta Blocker for Drupal 8. We sat down and figured out the value proposition and amount of work (story points) for this issue.
Value and Story points are in the scale of fibonacci. Our minimum is 1, our maximum is 21. The higher, the more value or work a certain issue has.
Value : 1
Story Points: 13
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 2274279-11--text_tokenizing.patch | 43.51 KB | drunken monkey |
Comments
Comment #1
drunken monkeyTests are of course a good idea, but I'm pretty sure this works fine at least in D7. But of course there might have been some errors introduced during the port.
You mean to just convert each text field value to a tokenized version with just a single token, and then let processors split that further, if they want? Might be an idea, yes. However, one problem would then be that it's not readily apparent whether any tokenizing happened on the content, which is, e.g., important for the database backend (which has to fallback to its own tokenizing if handed untokenized text).
Something to consider in any case would be to make a "Token" class for this, instead of using a magic array. We might even want to make a class for each data type we support, encapsulate conversion logic there (instead of having that in each backend separately) and also use those to implement custom data type support (by letting other modules just add new types with their classes).
This would be a lot more work, of course, but also be a lot cleaner and have additional benefits. (E.g., I have currently no idea how we should support custom data types at all.)
Then we could just let the class for fulltext data have some methods for tokenizing the data.
Comment #2
drunken monkeyIf we want a new way of handling tokenized text, I'd say we first need to identify what use cases it has to cover and make sure there are no problems with one. I can think of the following:
Your proposal of converting the field values to single tokens even before handing them to the processors would, as far as I see it, solve most of those. The middle one could be solved by a
isTokenized()method (if it's an object – one more magic array key otherwise (or, a little cleaner but still ugly, an "extra data" entry on the search item)), with only Tokenizer setting this. (This would also be an improvement in that values that were only run through the HTML filter won't be recognized as "tokenized".) The last one could be solved by an extra method or function doing this conversion.Comment #3
aspilicious commentedI'm not a processor expert but the above plans *sounds* ok.
Comment #4
nick_vhSounds like a plan indeed.
Tokenization can still be very useful for Solr if you want to extract certain things out of your text and give it extra boost. Such as the HTML filter does.
Renamed the title to rework the conversion and I'm going to play with this as soon as possible.
Comment #5
drunken monkeyIn theory, yes. However, boosting individual tokens doesn't work with Solr, since Solr only takes a boost for the whole field. So either we'd have to use some magic with additional fields, like the apachesolr module, or the HTML Filter only makes sense to strip HTML from the data for Solr.
Comment #6
drunken monkeyComment #7
nick_vhComment #8
nick_vhMoving to Major after discussion at Drupalcamp Vienna
Comment #9
drunken monkeyThis seems a lot cleaner to me and passes at least the unit tests.
The basic principle is that the values of fulltext fields are now always
TextvalueInterfaceobjects, with methods for getting the text value, the original text value and a set of tokens (if set – tokens are also classed objects). Text values can also have properties that processors are encouraged to set, if it makes sense, so it's easy to determine whether a certain text value has been, e.g., tokenized yet.Does that make sense to you? Does it cover all our requirements? (Seems that way to me.) Did I forget anything or do you have other suggestions?
Btw: already using #2648050: [policy, no patch] Stop disallowing camelCase for local variables / parameters here, which should be finalized soon enough. Yay for saner setters!
Comment #10
borisson_Let's replace this comment with: "Returns a proper value when this object is printed", because I think everyone can see that this is an implementation of __toString() ;)
See above.
Comment #11
drunken monkeyAs per personal discussion with Joris, I left the doc comments as-is but refactored the splitting into words (though unrelated, in truth) into a method so it's more self-documenting.
Comment #12
borisson_Comment #13
drunken monkeyComment #14
borisson_Tagging this with the dev days tag.
Comment #16
drunken monkeyGood idea, thanks!
Test bot is also happy, so: committed.
Thanks again for your review!