Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cwninja-has_related

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cwninja-has_related

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Has related is used by Reevoo to create similar product recommendations.

Example Index Builder:

namespace :apache do
  desc "Parse the last apache logs for similar products"
  task :find_similar_products => :environment do
    log_files = ENV["LOG_FILES"] || "/var/log/httpd/access.*.gz"

    prefs = Hash.new{|h,k| h[k] = Hash.new(0) }

    Dir.glob(log_files) do |filename|
      File.open(filename) do |f|
        Zlib::GzipReader.new(f).each_line do |line|
          product_id, ip = parse_log_line(line)
          if product_id and ip
            prefs[product_id][ip] += 1
          end
        end
      end
    end

    HasRelated.dump_dataset(prefs, "Product")
  end
end

(You will need to define your own parse_log_line method)

Example Usage:

class Product < ActiveRecord::Base
  has_related "related_products"
end

most_related_product = Product.related_products.first

Happy hunting.

FAQs

Package last updated on 11 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc