Casecommons/pg_search

Queries using a single character sometimes don't work

lightbe opened this issue · 1 comments

When I do a single character query for a, i, s or t I don't receive any results. For those same letters if I do a two character query starting with the letter I get results. Here are two examples.

Query for a received no results. Query for aa got the following results.

aa5j3uktdeb2gknqx99.ga
aa5j3uktdeb2gknqx99.ml
aa5j3uktdeb2gknqx99.tk
aa5zy64.com
aaaa22222.info
aaaa66666.info

Query for i received no results. Query for ia got the following results.

ia4stypglismiks.cf
ia4stypglismiks.ga
ia4stypglismiks.gq
ia4stypglismiks.ml
ia4stypglismiks.tk
iamail.com

I'm expecting rows to display for a, i, s and t like they do when I do a single character query for the other alphabets & single digits.

Ruby code

if params[:query].present?
   @bounce_domains = BounceDomain.order("domain ASC").text_search(params[:query]).to_a
else
   .......
end

pg_search code in my model:

  include PgSearch::Model
  pg_search_scope :domain_search, against: [:domain], using: {tsearch: {dictionary: "english", prefix: true}}

  def self.text_search(query)
    if query.present?
      domain_search(query)
    else
      all
    end
  end

I'm using:

Ruby 2.7.5
ActiveRecord 7.0.3.1
PostgreSQL 14.4

This is because you're using dictionary: "english"

The english text search configuration filters out stopwords like "a" and "I" which are very common in English. You probably want "simple" as the dictionary if your search text needs to support searching arbitrary strings of characters that are not English prose.