Esempio n. 1
0
def search(breadcrumbs,topic,source,query):
  facets=get_entities('*:*')
  sources=get_feeds('*:*')
  search_handler=get_handler('/select')
  
  if (query is None or len(query)==0) and (topic is None) and (source is None):
      # do a default search over the top 3 topics so we show some new/popular items instead of just random items
      if len(facets)>0:
        query='"' + '" OR "'.join(facets[:3])+'"'
  
  if (topic is not None) or (source is not None):
    if query is not None and len(query)>0:
      query='+'+query
    if topic is not None:
      query=join_query(query,'+entitykey:'+topic)
    if source is not None:
      query=join_query(query,'+feedkey:'+source)

  results=clean_results_summaries(search_handler(query))

  topics=[{'name':facet,'key':feeds.create_slug(facet)} for facet in facets]
  sources=[{'name':source,'key':feeds.create_slug(source)} for source in sources]

  tagcloud=[{'text':word,'freq':freq,'link':'?q='+word} for (word,freq) in get_top_words(results)]
 
  return {'results':results,'tagcloud':tagcloud,'topics':topics,'sources':sources,'breadcrumbs':breadcrumbs}
Esempio n. 2
0
def get_topics():
  entitysearch=get_handler('/entities')
  entity_results=entitysearch('*:*')
  # for each entity, get top sources...
  return [{'name':key,
        'key':feeds.create_slug(key),
        'results':get_topic_headlines(feeds.create_slug(key))} for key,value in entity_results.facet_counts['facet_fields']['entity'].iteritems()]
Esempio n. 3
0
def search(breadcrumbs,topic,source,category,query,clustered,clusterfieldname,handler):
  facets=get_entities('*:*')
  categories=get_categories('*:*')
  sources=get_feeds('*:*')
 
  if (topic is not None) or (source is not None) or (category is not None):
    if len(query)>0:
      query='+('+query+')'
    if category is not None:
      query=query + ' +categorykey:'+category
    if topic is not None:
      query=query + ' +entitykey:'+topic
    if source is not None:
      query=query + ' +feedkey:'+source

  results=handler(query)

  topics=[{'name':facet,'key':feeds.create_slug(facet)} for facet in facets]
  sources=[{'name':source,'key':feeds.create_slug(source)} for source in sources]
  categories=[{'name':source,'key':feeds.create_slug(source)} for source in categories]

  entities=[{'name':key,'key':key} for key,value in results.facet_counts['facet_fields']['entity'].iteritems()]

  clustered_results=[]
  if clustered:
    if results.grouped.has_key(clusterfieldname):
      for group in results.grouped[clusterfieldname]['groups']:
        doclist=group['doclist']
        root=doclist[0]
        clustered_results.append(root)
        if len(doclist)>0:
          root['similar']=doclist[1:]
      results=clustered_results

  return {'results':results,'entities':entities  ,'topics':topics,'sources':sources,'breadcrumbs':breadcrumbs,'categories':categories}
Esempio n. 4
0
def searchcarrot(breadcrumbs,topic,source,category,query,clustered):
  facets=get_entities('*:*')
  categories=get_categories('*:*')
  sources=get_feeds('*:*')

  handler=get_handler('/searchcarrotclustered')
 
  if (topic is not None) or (source is not None) or (category is not None):
    if len(query)>0:
      query='+('+query+')'
    if category is not None:
      query=query + ' +categorykey:'+category
    if topic is not None:
      query=query + ' +entitykey:'+topic
    if source is not None:
      query=query + ' +feedkey:'+source

  results=handler(query)

  topics=[{'name':facet,'key':feeds.create_slug(facet)} for facet in facets]
  sources=[{'name':source,'key':feeds.create_slug(source)} for source in sources]
  categories=[{'name':source,'key':feeds.create_slug(source)} for source in categories]
  
  clustered_results=[]
  doc_map={}
  for result in results.results:
    doc_map[result['id']]=result

  max_docs_per_cluster=8
  
  for carrot_cluster in results.clusters:
    docids=carrot_cluster['docs']
    docs=[]
    for docid in docids:
      docs.append(doc_map[docid])  
      if len(docs)>=max_docs_per_cluster:
        break
    label=" ".join(carrot_cluster['labels'])
    clustered_results.append({'label':label,'docs':docs})

  return {'clusters':clustered_results,'topics':topics,'sources':sources,'breadcrumbs':breadcrumbs,'categories':categories}
Esempio n. 5
0
def get_sources():
  sources=get_feeds('*:*')
  return [{'name':key,
        'key':feeds.create_slug(key),
        'results':get_source_headlines(feeds.create_slug(key))} for key in sources]