Skip to content

Instantly share code, notes, and snippets.

View lbjay's full-sized avatar

Jay Luker lbjay

View GitHub Profile
require_dependency 'vendor/plugins/blacklight/app/controllers/catalog_controller.rb'
class CatalogController < ApplicationController
def solr_search_params(extra_controller_params={})
solr_parameters = super extra_controller_params
if solr_parameters.key? :q
solr_parameters[:q] = solr_parameters[:q].gsub(/\S+/) { |match|
if match.include? ':' or match.index('=') != 0
match
require_dependency 'vendor/plugins/blacklight/app/controllers/catalog_controller.rb'
class CatalogController < ApplicationController
# prepend_before_filter :transform_syntax
def solr_search_params(extra_controller_params={})
solr_parameters = super extra_controller_params
my_parameters = solr_parameters.clone
if my_parameters.key? :q
@lbjay
lbjay / memoize.py
Created November 4, 2010 19:32
python memoize decorator example
def memoize(fn):
memory = {}
def simple_memoizer(*param_tuple):
if param_tuple in memory:
return memory[param_tuple]
else:
memory[param_tuple] = result = fn(*param_tuple)
return result
return simple_memoizer
# put this in any .rb file in config/initializers , make up your own, put it in an
# existing one, whatever works for you.
# As with many things in rails/Blacklight, there are many ways to do this, but
# this is one, it looks kinda complicated becuase it's trying to deal with
# cache_classes=false business.
module LocalAssetInclude
def add_local_assets
# # my_local_stylesheet.css should be found in your app's public/stylesheets/
16:18:02 cbeer_ | in the routes config for catalog, you can tell the
resources mapper what an id looks like
16:18:30 cbeer_ | so, for openvault, we have ids like
org.wgbh.mla:348bd4b1ae559bcd90abab7b114328312a4bf800
16:19:00 cbeer_ | so my catalog route looks like
16:19:06 cbeer_ | map.resources(:catalog,
16:19:07 cbeer_ | [...]
16:19:11 cbeer_ | requirements => { :id =>
/([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|~|_|(%[0-9A-F]{2}))+/ }
16:19:13 cbeer_ | )
## IN THE PYTHON VIRTUALENV ##
In [1]: import pysolr
In [2]: conn = pysolr.Solr('http://adsset:8986/solr/fulltext')
In [3]: %timeit r = conn.search('galaxy', fl=['id'], rows=10)
1 loops, best of 3: 50 s per loop
Python 2.6.4 (r264:75706, Jun 4 2010, 18:20:16)
Type "copyright", "credits" or "license" for more information.
IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: import solr
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">4</int><lst name="params"><str name="id">10525</str><str name="qt">document</str><str name="debugQuery">true</str></lst></lst><result name="response" numFound="0" start="0"/><lst name="debug"><str name="rawquerystring">{!raw f=id v=$id}</str><str name="querystring">{!raw f=id v=$id}</str><str name="parsedquery">id:EXCEPTION(val=10525)</str><str name="parsedquery_toString">id:10525</str><lst name="explain"/><str name="QParser"/><lst name="timing"><double name="time">2.0</double><lst name="prepare"><double name="time">0.0</double><lst name="org.apache.solr.handler.component.QueryComponent"><double name="time">0.0</double></lst><lst name="org.apache.solr.handler.component.FacetComponent"><double name="time">0.0</double></lst><lst name="org.apache.solr.handler.component.MoreLikeThisComponent"><double name="time">0.0</double></lst><lst name="org.apache.solr.handler.component.HighlightComponent">
[Thu Sep 02 10:34:39 2010] [error] /usr/local/lib/python2.6/dist-packages/pyRXP-1.13-py2.6-linux-i686.egg/pyRXP.py:3: UserWarning: Module _mysql was already imported from /usr/lib/pymodules/python2.6/_mysql.so, but /usr/lib/pymodules/python2.6 is being added to sys.path
[Thu Sep 02 10:34:40 2010] [error] [client 131.142.42.128] mod_wsgi (pid=13249): Target WSGI script '/opt/invenio/invenio/var/www-wsgi/invenio.wsgi' cannot be loaded as Python module.
[Thu Sep 02 10:34:40 2010] [error] [client 131.142.42.128] mod_wsgi (pid=13249): Exception occurred processing WSGI script '/opt/invenio/invenio/var/www-wsgi/invenio.wsgi'.
[Thu Sep 02 10:34:40 2010] [error] [client 131.142.42.128] Traceback (most recent call last):
[Thu Sep 02 10:34:40 2010] [error] [client 131.142.42.128] File "/opt/invenio/invenio/var/www-wsgi/invenio.wsgi", line 23, in <module>
[Thu Sep 02 10:34:40 2010] [error] [client 131.142.42.128] from invenio.webinterface_handler_wsgi import application
[Thu Sep 02 10:34:40 2010] [error] [client 1
#!/usr/bin/env python
import sys
import traceback
from optparse import OptionParser
from pymarc import Field, Record, MARCWriter
from invenio.search_engine import perform_request_search, get_record
# these go in the 07 position
# see http://www.loc.gov/marc/bibliographic/bdleader.html