def title_search(d): """ Pass in form data for a given title search, and get back a corresponding solr query. """ q = ["+type:title"] if d.get('state'): q.append('+state:"%s"' % d['state']) if d.get('county'): q.append('+county:"%s"' % d['county']) if d.get('city'): q.append('+city:"%s"' % d['city']) if d.get('newspaper_type'): q.append('+newspaper_type:"%s"' % d['newspaper_type']) if d.get('region'): q.append('+region:"%s"' % d['region']) for term in d.get('terms', '').replace('"', '').split(): q.append('+(title:"%s" OR essay:"%s" OR note:"%s" OR edition:"%s" OR place_of_publication:"%s" OR url:"%s" OR publisher:"%s")' % (term, term, term, term, term, term, term)) if d.get('frequency'): q.append('+frequency:"%s"' % d['frequency']) if d.get('language'): q.append('+language:"%s"' % d['language']) if d.get('ethnicity'): q.append('+' + _expand_ethnicity(d['ethnicity'])) if d.get('labor'): q.append('+subject:"%s"' % d['labor']) year1 = d.get('year1', None) if not year1: year1 = '1690' year2 = d.get('year2', None) if not year2: year2 = '2017' # don't add the start_year restriction if it's the lowest allowed year if year1 != '1690': q.append('+end_year:[%s TO 9999]' % year1) # don't add the end_year restriction if it's the max allowed year # particularly important for end_years that are coded as 'current' if year2 != '2009': q.append('+start_year: [0 TO %s]' % year2) if d.get('lccn'): q.append('+lccn:"%s"' % _normal_lccn(d['lccn'])) if d.get('material_type'): q.append('+holding_type:"%s"' % d['material_type']) q = ' '.join(q) # keep the gap 10 for year range 100, 20 for year range 200 and so on range_gap = int(math.ceil((int(year2) - int(year1)) / 100.0)) * 5 year_facets = range(int(year1), int(year2), range_gap or 1) facets = {'facet': 'true', 'facet_field': ['state', 'county'], 'facet_mincount': 1, 'year_facets': year_facets} return q, facets
def title_search(d): """ Pass in form data for a given title search, and get back a corresponding solr query. """ q = ["+type:title"] if d.get('state'): q.append('+state:"%s"' % d['state']) if d.get('county'): q.append('+county:"%s"' % d['county']) if d.get('city'): q.append('+city:"%s"' % d['city']) for term in d.get('terms', '').replace('"', '').split(): q.append('+(title:"%s" OR essay:"%s" OR note:"%s" OR edition:"%s" OR place_of_publication:"%s" OR url:"%s" OR publisher:"%s")' % (term, term, term, term, term, term, term)) if d.get('frequency'): q.append('+frequency:"%s"' % d['frequency']) if d.get('language'): q.append('+language:"%s"' % d['language']) if d.get('ethnicity'): q.append('+' + _expand_ethnicity(d['ethnicity'])) if d.get('labor'): q.append('+subject:"%s"' % d['labor']) year1 = d.get('year1', None) if not year1: year1 = '1690' year2 = d.get('year2', None) if not year2: year2 = '2009' # don't add the start_year restriction if it's the lowest allowed year if year1 != '1690': q.append('+end_year:[%s TO 9999]' % year1) # don't add the end_year restriction if it's the max allowed year # particularly important for end_years that are coded as 'current' if year2 != '2009': q.append('+start_year: [0 TO %s]' % year2) if d.get('lccn'): q.append('+lccn:"%s"' % _normal_lccn(d['lccn'])) if d.get('material_type'): q.append('+holding_type:"%s"' % d['material_type']) q = ' '.join(q) # keep the gap 10 for year range 100, 20 for year range 200 and so on range_gap = int(math.ceil((int(year2) - int(year1)) / 100.0)) * 5 year_facets = range(int(year1), int(year2), range_gap or 1) facets = {'facet': 'true', 'facet_field': ['state', 'county'], 'facet_mincount': 1, 'year_facets': year_facets} return q, facets
def title_search(d): """ Pass in form data for a given title search, and get back a corresponding solr query. """ q = ["+type:title"] if d.get("state"): q.append('+state:"%s"' % d["state"]) if d.get("county"): q.append('+county:"%s"' % d["county"]) if d.get("city"): q.append('+city:"%s"' % d["city"]) for term in d.get("terms", "").replace('"', "").split(): q.append( '+(title:"%s" OR essay:"%s" OR note:"%s" OR edition:"%s" OR place_of_publication:"%s" OR url:"%s" OR publisher:"%s")' % (term, term, term, term, term, term, term)) if d.get("frequency"): q.append('+frequency:"%s"' % d["frequency"]) if d.get("language"): q.append('+language:"%s"' % d["language"]) if d.get("ethnicity"): q.append("+" + _expand_ethnicity(d["ethnicity"])) if d.get("labor"): q.append('+subject:"%s"' % d["labor"]) year1 = d.get("year1", None) if not year1: year1 = "1690" year2 = d.get("year2", None) if not year2: year2 = "2009" # don't add the start_year restriction if it's the lowest allowed year if year1 != "1690": q.append("+end_year:[%s TO 9999]" % year1) # don't add the end_year restriction if it's the max allowed year # particularly important for end_years that are coded as 'current' if year2 != "2009": q.append("+start_year: [0 TO %s]" % year2) if d.get("lccn"): q.append('+lccn:"%s"' % _normal_lccn(d["lccn"])) if d.get("material_type"): q.append('+holding_type:"%s"' % d["material_type"]) q = " ".join(q) # keep the gap 10 for year range 100, 20 for year range 200 and so on return q
def title_search(d): """ Pass in form data for a given title search, and get back a corresponding solr query. """ q = ["+type:title"] if d.get('state'): q.append('+state:"%s"' % d['state']) if d.get('county'): q.append('+county:"%s"' % d['county']) if d.get('city'): q.append('+city:"%s"' % d['city']) for term in d.get('terms', '').replace('"', '').split(): q.append( '+(title:"%s" OR essay:"%s" OR note:"%s" OR edition:"%s" OR place_of_publication:"%s" OR url:"%s" OR publisher:"%s")' % (term, term, term, term, term, term, term)) if d.get('frequency'): q.append('+frequency:"%s"' % d['frequency']) if d.get('language'): q.append('+language:"%s"' % d['language']) if d.get('ethnicity'): q.append('+' + _expand_ethnicity(d['ethnicity'])) if d.get('labor'): q.append('+subject:"%s"' % d['labor']) if d.get('year1') and d.get('year2'): # don't add the start_year restriction if it's the lowest allowed year if d.get('year1') != '1690': q.append('+end_year:[%s TO 9999]' % d['year1']) # don't add the end_year restriction if it's the max allowed year # particularly important for end_years that are coded as 'current' if d.get('year2') != '2009': q.append('+start_year: [0 TO %s]' % d['year2']) if d.get('lccn'): q.append('+lccn:"%s"' % _normal_lccn(d['lccn'])) if d.get('material_type'): q.append('+holding_type:"%s"' % d['material_type']) q = ' '.join(q) return q
def title_search(d): """ Pass in form data for a given title search, and get back a corresponding solr query. """ print "this is d" + str(d) q = ["+type:title"] if d.get('state'): q.append('+state:"%s"' % d['state']) if d.get('county'): q.append('+county:"%s"' % d['county']) if d.get('city'): q.append('+city:"%s"' % d['city']) for term in d.get('terms', '').replace('"', '').split(): q.append('+(title:"%s" OR essay:"%s" OR note:"%s" OR edition:"%s" OR place_of_publication:"%s" OR url:"%s" OR publisher:"%s")' % (term, term, term, term, term, term, term)) if d.get('frequency'): q.append('+frequency:"%s"' % d['frequency']) if d.get('language'): q.append('+language:"%s"' % d['language']) if d.get('ethnicity'): q.append('+' + _expand_ethnicity(d['ethnicity'])) if d.get('labor'): q.append('+subject:"%s"' % d['labor']) if d.get('year1') and d.get('year2'): # don't add the start_year restriction if it's the lowest allowed year if d.get('year1') != '1690': q.append('+end_year:[%s TO 9999]' % d['year1']) # don't add the end_year restriction if it's the max allowed year # particularly important for end_years that are coded as 'current' if d.get('year2') != '2009': q.append('+start_year: [0 TO %s]' % d['year2']) if d.get('lccn'): q.append('+lccn:"%s"' % _normal_lccn(d['lccn'])) if d.get('material_type'): q.append('+holding_type:"%s"' % d['material_type']) q = ' '.join(q) return q