Git Product home page Git Product logo

Comments (5)

mrkamel avatar mrkamel commented on May 26, 2024

Hi, that's currently not supported out of the box. Moreover, to support it while staying database agnostic we need to add type cast statements to the generated sql, because e.g. postgres doesn't support it without explicit type casts. It would be possible to add it as a new feature via something like

search_scope ... do
  options :numbers, :cast => :string
end

The obvious downside of this would be: it can no longer be treated as an integer, such that

Order.search "number > 10"

will work on strings instead of integers and imo produces unexpected results. Moreover, there are performance issues, but if you're using wildcard LIKE queries (instead of fulltext indices), this should be negligible. I'll consider this feature to be added in the future, but can't give an ETA, but you're welcome to add a PR.

So, currently you can add an additional string column to your schema or change your search query to:

Order.search "number >= 20590001 and number <= 20590009

from search_cop.

biggless avatar biggless commented on May 26, 2024

Great! Thanks a lot!

from search_cop.

westonganger avatar westonganger commented on May 26, 2024

+1 the cast to string option would be great

from search_cop.

westonganger avatar westonganger commented on May 26, 2024

@mrkamel I would be interested in helping out in implementing the :cast option. Any hints on where to start?

from search_cop.

westonganger avatar westonganger commented on May 26, 2024

Looks like this functionality can be achieved using Custom Operators

search_scope :search do
  attributes :number

  generator :like_string do |column_name, raw_value|
    pattern = quote("%#{raw_value}%")
    "#{column_name} LIKE #{pattern}"
  end
end

Book.search(number: {like_string: "123"})

from search_cop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.