Problem/Motivation

Indexing a specific item fails with:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

Steps to reproduce

  1. Create a content type A with a plaintext field field_text.
  2. Create a content type B with a content reference field field_ref.
  3. Create a search api database server.
  4. Create a search api index using the database server. The index should index content of type B
  5. 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.
  6. Create two nodes of type A. The first should contain "abc" in field_text, the second should contain "abc " in field_text.
  7. Create a node of type B that references both nodes of type A.
  8. 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.

Comments

lukas_w created an issue. See original summary.

drunken monkey’s picture

Component: General code » Database backend
Status: Active » Needs review
Related issues: +#2926733: Duplicate entry when indexing rendered html output
StatusFileSize
new2.44 KB

Thanks 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!

drunken monkey’s picture

Status: Needs review » Fixed

Committed.

  • drunken monkey committed 989a2ec on 8.x-1.x
    Issue #3199355 by drunken monkey: Fixed error when indexing strings with...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.