"""
author: Zack Schwartz (zacharyhschwartz@gmail.com)
date created: 12/5/2011
"""

import sunburnt
import urllib2


class Indexer(object):
    def __init__(self):
        self.solr_interface = sunburnt.SolrInterface("http://localhost:8983", "helpers/schema.xml")

    def insert_data(self, status):
        document = [{'author': status['author'],
                     'links': status['webpage']['real_url'],
                     'text': status['text'],
                     'id': status['id']
                    }]                  
        xml = self.solr_interface.add(document)
        self.make_request(xml)

    def make_request(self, xml):
        req = urllib2.Request("http://localhost:8983/solr/update?commit=true", data=xml)
        req.add_header('Content-type', 'text/xml')
        openobj = urllib2.urlopen(req)

    
