def test_simple_search (self): try: search_index = SearchIndex(self.context) hits, searcher = search_index.search('test') for i, doc in hits: foo, bar = doc.get('uid'), hits.score(i) if searcher: searcher.close() except Exception, e: self.fail('Error searching: %s' % e)
def test_simple_search(self): try: search_index = SearchIndex(self.context) hits, searcher = search_index.search('test') for i, doc in hits: foo, bar = doc.get('uid'), hits.score(i) if searcher: searcher.close() except Exception, e: self.fail('Error searching: %s' % e)
config = canary.context.CanaryConfig() config.read_file(options.config) context = canary.context.Context(config) source_catalog = context.get_source_catalog() ctm = source_catalog.get_complete_mapping() if not args: print usage sys.exit(0) query_str = options.boolean.join( [' "%s" [%s] ' % (term, options.field) for term in args]) #print query_str.strip() search_index = SearchIndex(context) hit_list = [] hits, searcher = search_index.search(query_str) for i, doc in hits: hit_list.append(doc.get('uid')) searcher.close() output = [] for id in hit_list: rec = QueuedRecord(context, int(id)) if options.locations: study = Study(context, rec.study_id) for loc in study.locations: out = [] out.extend((id, loc.uid, loc.study_id, loc.feature_id)) feature = Feature(uid=loc.feature_id)
(p_exp[0], p_coh[0], p_csec[0], p_desc[0], precords[0], pstudies[0]), ('Experimental', 'Cohort', 'Cross-Sectional', 'Descriptive', '# Studies Total', '# Records w/Linkage')) ## legend((p_exp[0], p_desc[0], p_agg[0], p_csec[0], p_coh[0], ## p_cc[0], p_dm[0], precords[0], pstudies[0]), ## ('Experimental', 'Descriptive', 'Aggregate', ## 'Cross-Sectional', 'Cohort', 'Case-Control', 'Disease Model', #savefig(('%s' % token.replace(' ', '_'))) show() cla() if __name__ == '__main__': context = Context() search_index = SearchIndex(context) searches = ( 'Lead [exposure]', 'Hantavirus [exposure]', 'peromyscus [species]', 'Michigan [location]', 'DDT [exposure]', '2003 [year]', 'cats and dogs', '"Burger J" [author]', 'cross-sectional [methodology]', 'case-control [methodology] and cattle [species]', 'disease-model [methodology]', '"age factors" [risk_factors]', 'Sarin [exposure]', 'Arsenic [exposure]',
def run(search_index): while True: print print "Hit enter with no input to quit." command = raw_input("Query: ") if command == '': return #query_parser = QueryParser('all', analyzer) #query_parser.setOperator(query_parser.DEFAULT_OPERATOR_AND) #query = QueryParser.parse(unicode(command), 'all', analyzer) #query = query_parser.parseQuery(unicode(command)) #print "[Parsed Query: %s]" % query #hits = searcher.search(query) #print "%s total matching documents." % hits.length() hits, searcher = search_index.search(command) for i, doc in hits: print doc.get('uid'), hits.score(i) searcher.close() if __name__ == '__main__': context = canary.context.Context() #directory = FSDirectory.getDirectory(context.config.search_index_dir, False) #searcher = IndexSearcher(directory) #analyzer = StandardAnalyzer() #run(searcher, analyzer) search_index = SearchIndex(context) run(search_index)
'Cross-Sectional', 'Descriptive', '# Studies Total', '# Records w/Linkage')) ## legend((p_exp[0], p_desc[0], p_agg[0], p_csec[0], p_coh[0], ## p_cc[0], p_dm[0], precords[0], pstudies[0]), ## ('Experimental', 'Descriptive', 'Aggregate', ## 'Cross-Sectional', 'Cohort', 'Case-Control', 'Disease Model', #savefig(('%s' % token.replace(' ', '_'))) show() cla() if __name__ == '__main__': context = Context() search_index = SearchIndex(context) searches = ( 'Lead [exposure]', 'Hantavirus [exposure]', 'peromyscus [species]', 'Michigan [location]', 'DDT [exposure]', '2003 [year]', 'cats and dogs', '"Burger J" [author]', 'cross-sectional [methodology]', 'case-control [methodology] and cattle [species]', 'disease-model [methodology]', '"age factors" [risk_factors]', 'Sarin [exposure]', 'Arsenic [exposure]',