Problem With PGSearch Documents

Feature(s) impacted

Data Visualisation in my Forest Dashboard, on specific models only

Observed behavior

I have setup a multisearch using PGSearch on two of my models, User and Address, with a PGSearch document generated in my postgres DB. Since then, my dashboard returns a 500 when I try to display these models’ indexes. Other models not included in PGSearch are displayed without trouble.

Expected behavior

Visualizing my models’ indexes correctly.

Failure Logs

Forest :deciduous_tree::deciduous_tree::deciduous_tree: Records Index error: uninitialized constant ForestLiana::UserSpace::PgSearchDocumentSerializer

Context

Please provide in this mandatory section, the relevant information about your configuration:

  • Project name: depozen
  • Team name: depozen
  • Environment name: development
  • Agent type & version: Where can I find it ?
  • Recent changes made on your end if any: use of PGSearch multisearch

Hello @julien-mathieu, Welcome to our community ! :tada:

What version of forest are you using ? Forest-liana (rails) ?

How do you integrates PGSearch to your application ?

Kind regards,
Morgan

Hey! Thanks for your answer and welcome message!

I am indeed using the forest_liana gem in Rails 6.1.4 / Ruby 2.7.4

I configured a multisearch based on two models. This multi search creates a PGSearch Document that is referenced in my DB. This document is then referenced in my models. In my forestadmin-schema.json this is materialized by { "field": "pg_search_document", "type": "Number", "default_value": null, "enums": null, "integration": null, "is_filterable": true, "is_read_only": false, "is_required": false, "is_sortable": true, "is_virtual": false, "reference": "PgSearch__Document.id", "inverse_of": "searchable", "relationship": "HasOne", "widget": null, "validations": [] }
However the models cannot be loaded due to this references to a table that on the other hand is not referenced in my schema.rb models.

Thanks for help!

Hi @julien-mathieu

I assume you are using the pg_search gem.
Could you share your user and address templates ? :pray:

I’ll try to reproduce on my end.

Indeed!

Here is what I have in my models (as pg_search_document reference is not listed in my schema tables) :

for User

  include PgSearch::Model

  multisearchable against: %i[first_name last_name email]

  pg_search_scope :user_search,
                  against: %i[first_name last_name email],
                  using: {
                    tsearch: { prefix: true }
                  }

for Address

  include PgSearch::Model
  multisearchable against: %i[line1 city zipcode]

Thanks!

The multisearch is the problem since it creates a search document through the command PgSearch::Multisearch.rebuild(Address, User) in which Address and User instances are referenced.

I managed to reproduce the issue.
I have a very simple solution to work around this issue.

Just create a model pg_search_document.rb in your model directories.

class PgSearchDocument < ApplicationRecord
end
2 Likes

Works like a charm! Thanks for your help :slight_smile:

1 Like