Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8391357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:14:22+00:00 2026-06-09T19:14:22+00:00

I am using pg_search for fulltext search, it works fine when I type a

  • 0

I am using pg_search for fulltext search, it works fine when I type a search term, but when I give it a empty string I expect it to return all models, instead I get no results.

How can I configure pg_search_scope to return all models on empty search?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:14:23+00:00Added an answer on June 9, 2026 at 7:14 pm

    Here’s my answer from https://github.com/Casecommons/pg_search/issues/49


    I don’t think that having an empty query should always trigger all records, for a couple reasons.

    First, I don’t think that there is a well-defined order to return records in. (The usual sorting by search rank is meaningless without a query)

    Second, I think that the database should define how the various search features treat a blank string, so that all of the logic lives in just one place.

    So, I want to offer this workaround, which I think will work out better for your situation.

    class MyModel < ActiveRecord::Base
      include PgSearch
    
      pg_search_scope :search_by_name, :against => :name
    
      def self.search(query)
        if query.present?
          search_by_name(query)
        else
          # No query? Return all records, newest first.
          order("created_at DESC")
        end
      end
    end
    

    This solution should still be chainable, so you can call something like this in your controller safely (assuming you’re using a pagination library like kaminari.

    MyModel.where(:published => true).search(params[:query]).page(params[:page])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am testing performance for PostgreSQL full text search (using pg_search gem) and solr
I am currently using Act_as_taggable_on for tagging and pg_search to search through my postgresql
Using a populated Table Type as the source for a TSQL-Merge. I want to
Using the Redis info command, I am able to get all the stats of
Using import datetime in python, is it possible to take a formatted time/date string
I'm using a loop to loop through a search engine page to gather data,
I am currently trying to do a complicated WHERE search on a table using
I tried using gem install pg but it doesn't seem to work. gem install
I am trying to access textbox value using the jQuery code; $(#pg_textbox).val(); But it
I want to search a table with multiple conditions in Rails. I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.