`
orcl_zhang
  • 浏览: 243366 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

the readme of searchlogic

阅读更多

Before I use a library in my application I like to glance at the source and try to at least understand the basics of how it works. If you are like me, a nice little explanation from the author is always helpful:

Searchlogic utilizes method_missing to create all of these named scopes. When it hits method_missing it creates a named scope to ensure it will never hit method missing for that named scope again. Sort of a caching mechanism. It works in the same fashion as ActiveRecord's "find_by_*" methods. This way only the named scopes you need are created and nothing more.

The search object is just a proxy to your model that only delegates calls that map to named scopes and nothing more. This is obviously done for security reasons. It also helps make form integration easier, by type casting values, and playing nice with form_for. This class is pretty simple as well.

That's about it, the named scope options are pretty bare bones and created just like you would manually.

 

Searchlogic利用method_missing的创建这些命名范围的。当它攻击的method_missing它创建一个命名范围,以确保它永远不会达到方法命名范围的method messing。这样的缓存机制。该工程作为的ActiveRecord的“find_by_ *”方法相同的方式。只有这样命名的范围你需要的是创造,仅此而已。

分享到:
评论
2 楼 orcl_zhang 2010-01-08  
rails中很多地方应用到了method_missing这个方法。
searchlogic是一个不错的应用。
1 楼 orcl_zhang 2009-12-12  
=== Searchlogic provided scopes

Let's take some basic scopes that Searchlogic provides for every model:
  # We have the following relationships

  User.has_many_orders
  Order.has_many :line_items
  LineItem

  # Set conditions on association columns
  User.orders_total_greater_than(20)
  User.orders_line_items_price_greater_than(20)

  # Order by association columns
  User.ascend_by_order_total
  User.descend_by_orders_line_items_price

This is recursive, you can travel through your associations simply by typing it in the name of the method. Again these are just named scopes. You can chain them together, call methods off of them, etc.
==========
Accident.belongs_to :employee
Employee.has_many :accidents

Employee.find_by_name['z']
Accident.employee_name_like['z']

So magic!

相关推荐

    Android代码-MyOwnNotes

    ============== MyOwnNotes 2 This is Version 2, a complete rewrite of MyOwnNotes. This application does not depend on the server side owncloud ...Make sure you read the README of the appropriate branc

    开源的readme.md编写工具

    **开源的README.md编写工具** 在软件开发领域,README文件是项目的重要组成部分,它提供了项目的概述、安装指南、使用说明以及贡献方式等信息。随着Markdown的流行,许多开发者选择使用Markdown格式来编写README,...

    复杂网络大家名著:Complex Networks---Principles, Methods and Applications书籍配套数据

    Here you find all the data sets described and ...The archive contains one folder for each dataset, The file README.txt in each folder contains some relevant information about the corresponding data set.

    README_readme_

    【标题】:“README_readme_”通常是指一个项目或软件中的README文件,它是用来提供关于项目基本信息、如何运行以及使用指南的重要文档。 【描述】:“A basic readme file for running benami games”说明这个...

    README文件模板-New.zip

    在软件开发领域,README文件是项目中的重要组成部分,它提供了关于项目的基本信息,帮助用户理解项目的用途、如何安装和使用,以及如何贡献代码等。"README文件模板-New.zip" 是一个压缩包,包含了两种类型的README...

    readme.rar

    《readme.rar 文件详解及其在IT中的重要性》 在信息技术领域,`readme.rar`文件是一个常见的元素,它在软件开发、数据管理和共享、项目协作等场景中扮演着重要的角色。本文将深入探讨`readme`文件的含义、功能以及...

    faac-1.28.tar.zip_On the Up_aac encoder_faac-1.28.tar_faac-1.28.

    FAAC is an MPEG-4 and MPEG-2 AAC encoder. Note that the quality of FAAC is not up to par with the currently ... The original license text can be found in the README file included in the download package.

    Readme 破解使用说明

    Readme 破解使用说明

    从Readmemd文件创建美观简单的HTML页面

    const readmeContent = fs.readFileSync('Readme.md', 'utf8'); const htmlContent = marked(readmeContent); // 将生成的HTML写入新的文件 fs.writeFileSync('index.html', htmlContent); ``` 虽然这会生成一个...

    matlab README.md

    readme,matlab处理文件

    README.mdown

    缺少README.mdown可以下载使用

    gdb调试工具

    If you are receiving this as part of a GDB release, see the file gdb/README. If with a binutils release, see binutils/README; if with a libg++ release, see libg++/README, etc. That'll give you info ...

    loadrunner 9.5 crack readme

    loadrunner 9.5 crack readme

    README.md编写教程(基本语法)

    README.md编写教程(基本语法) Markdown是一种纯文本格式的标记语言。通过简单的标记语法,它可以使普通文本内容具有一定的格式。

    快速风格迁移pytorch源码实现

    The algorithm can be used to mix the content of an image with the style of another image. For example, here is a photograph of a door arch rendered in the style of a stained glass painting. The ...

    jdk18 64.zip

    The links below are provided to allow review before download of the README and THIRDPARTYREADME files associated with archived versions of Java SE and JavaFX. If you require access to a version not ...

    Carsim_Programs_solvers_ReadMe.rar

    标题中的"Carsim_Programs_solvers_ReadMe.rar"是一个压缩包文件,主要涉及的内容是关于 Carsim 软件与 Simulink 的联合仿真操作,尤其是解决输入输出信号选择的问题。Carsim 是一款广泛用于汽车动力学模拟的高级...

    i.MX 6 Series Firmware Guide

    This document’s purpose is to help software engineers create board bring up and test code for ... The README.pdf document in the package describes how to build and run the drivers and the test code.

    Grub4Dos 中文ReadMe

    Grub4dos 中文ReadMe 0.4.4版

    p6880880_112000_Linux-x86-64

    This is the README file for OPatch 11.2.0.3.15, the Oracle Interim One-off Patch Installer. This patch (6880880) installs the "OPatch" utility. OPatch is used for patching Oracle software. If you ...

Global site tag (gtag.js) - Google Analytics