Problem/Motivation
Indexing a specific item fails with:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
Steps to reproduce
- Create a content type A with a plaintext field field_text.
- Create a content type B with a content reference field field_ref.
- Create a search api database server.
- Create a search api index using the database server. The index should index content of type B
- Add field_text through the reference of field_ref to the index fields. I. e. nodes of type B should be found via the content of field_text of its referenced items of type A.
- Create two nodes of type A. The first should contain "abc" in field_text, the second should contain "abc " in field_text.
- Create a node of type B that references both nodes of type A.
- Reindex the index. This should now fail because of the integrity constraint violation cited above.
Proposed resolution
The error seems to stem from the whitespace in field_text. The database seems to strip of the whitespace at the end of the field and therefore it regards the two values the same.
If this is intended behavior of the database, the search_api_db module should trim whitespaces of the field content so it will not try to insert the "same" item twice into the database.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3199355-2--db_backend_trailing_space.patch | 2.44 KB | drunken monkey |
Comments
Comment #2
drunken monkeyThanks a lot for reporting this problem!
An important information in the IS, that would have saved me about an hour of work, is that you indexed the field with type “String”, not “Fulltext”. Anyways, I figured it out and was able to reproduce the problem, even in an automated test. With this, it’s also pretty clear how to fix this.
Patch attached, please test/review!
Comment #3
drunken monkeyCommitted.