Giter VIP home page Giter VIP logo

Comments (3)

ankane avatar ankane commented on August 15, 2024

Hi @satyakampandya, thanks for the feature request. However, I don't understand the problem you're try to solve. Can you share more about the specific problem, and possibly a code example of what you're envisioning?

from searchkick.

satyakampandya avatar satyakampandya commented on August 15, 2024

Scenario:

In my codebase, I am handling Elasticsearch connectivity issues by rescuing Faraday::TimeoutError. However, this approach causes issues with my existing code that relies on @products for fetching suggestions.

def retrieve_products
  @products = base_elasticsearch
rescue Faraday::TimeoutError
  @products = []
end

Proposed Solution:

To address this issue, I propose the creation of a new method called none that sets @products, allowing to gracefully handle Elasticsearch downtime without breaking your existing codebase.

def retrieve_products
  @products = base_elasticsearch
rescue Faraday::TimeoutError
  @products = Searchkick::Results.none
  # Alternatively, you can use a custom `none` method:
  # @products = Product.search(none: true)
end
searcher = build_searcher(search_params)
products = searcher.retrieve_products
products_suggestions = products.suggestions             
# products.suggestions will work, it'll return [] if Elasticsearch is down
required_hits = (10 - products_suggestions.count)      
# products_suggestions.count will work, it'll return 0 if Elasticsearch is down

This approach ensures that your existing code can continue to use @products without disruption, and it provides a more structured way to handle Elasticsearch downtime using the none method.

In summary, this proposal introduces a new method to gracefully handle exceptions while maintaining the stability of your codebase in situations where Elasticsearch is unavailable.

from searchkick.

ankane avatar ankane commented on August 15, 2024

Thanks for the additional explanation. However, I don't see a strong reason for including it in the gem (users can do nil checks or implement their own null objects as needed).

from searchkick.

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.