Skip to content

Instantly share code, notes, and snippets.

from postneo.category.models import Category
from postneo.blog.models import Entry
from lxml import etree
tree = etree.parse(open('../../../wordpress-20090526.xml', 'r'))
def field_data(tree, name):
"""Return the text for a field element with a particular name"""
return tree.find("field[@name='%s']" % name).text
from Queue import Queue
class FuckingQueue(Queue):
pass
# Calculate the years between 1900 and 2100 in which July 4th falls on a Saturday
import datetime
for year in range(1900,2101):
dt = datetime.datetime(year, 7, 4)
if dt.strftime('%w') == '6':
print year ,
# Yields 1903 1908 1914 1925 1931 1936 1942 1953 1959 1964 1970 1981 1987 1992 1998
# 2009 2015 2020 2026 2037 2043 2048 2054 2065 2071 2076 2082 2093 2099
import appuifw
import e32
import simplejson as json
import urllib
def exit_key_handler():
app_lock.signal()
info = []
main_listbox = None
[8:43pm] jefftriplett: matt_c: dance
[8:43pm] matt_c: 0-\-<
[8:43pm] matt_c: 0-/-<
[8:44pm] matt_c: 0->-<
[8:44pm] matt_c: 0-[-< whew, I'm tired.
[8:44pm] matt_c: 0-[-< <-- this is totally me doing the robot.
[8:45pm] jefftriplett: well done

Faceting on something like a full author name with Solr and Haystack is a bit tricky. One way to solve this is to set up Solr to have a copy of your author information in a string field instead of a text_ws field to avoid stemming and splitting on whitespace.

Schema.XML:

<!-- Author field to facet on (we might have multiple authors) -->
<field name="author" type="text_ws" indexed="true" stored="true" multiValued="true" omitNorms="true"/>
<field name="author_exact" type="string" indexed="true" stored="true" multiValued="true" omitNorms="true"/>
<copyField source="author" dest="author_exact" />

Then in your customized search view (perhaps in get_results), instead of faceting on your author field, we facet on author_exact:

Biscuits
2 C flour
2 tsp baking powder
1/2 tsp baking soda
1 T sugar
1/2 tsp salt
2 T vegan butter
1 C plain non-dairy milk
Gravy
# First column is a timestamp, second column is a response time. Example:
# "time","response"
# 2009-11-23 07:34:01.778955,0.599255
data <- read.csv("~/response_log.csv", header=TRUE)
processed_time <- transform(data$time, strptime(data$time, "%Y-%m-%d %H:%M:%S"))
plot(processed_time, data$response)
from django import forms
from django.utils.encoding import force_unicode
from taggit.managers import TaggableManager
from taggit.utils import parse_tags
# Extended from django-taggit (http://github.com/alex/django-taggit)
class ExtendedTagField(forms.CharField):
"""An extended TagField that makes use of the tag parser from django-tagging."""
def clean(self, value):
from haystack.indexes import *
from haystack import site
from publications.models import Publication
class PublicationIndex(SearchIndex):
text = CharField(document=True, use_template=True)
author = MultiValueField()
def prepare_author(self, obj):
return [unicode(a) for a in obj.authors.all()]