Ejemplo n.º 1
0
def create_search_document(id, obj):
    """
    Creates a new document that can be written to the search index.
    The first parameter has to be an id following the scheme
    "searchprovider-id", the second one should be a dictionary containing the
    document's data.
    Never create the search documents manually but use this function!
    """
    doc = UnprocessedDocument()
    doc.id = id
    for key, value in obj.iteritems():
        # if the returned object is a list item we iterate over it and
        # set `key` multiply to all its children, otherwise once for
        # the value.
        for v in (value if isinstance(value, list) else [value]):
            doc.fields.append(Field(key, unicode(v)))
    return doc
Ejemplo n.º 2
0
def create_search_document(id, obj):
    """
    Creates a new document that can be written to the search index.
    The first parameter has to be an id following the scheme
    "searchprovider-id", the second one should be a dictionary containing the
    document's data.
    Never create the search documents manually but use this function!
    """
    doc = UnprocessedDocument()
    doc.id = id
    for key, value in obj.iteritems():
        # if the returned object is a list item we iterate over it and
        # set `key` multiply to all its children, otherwise once for
        # the value.
        for v in (value if isinstance(value, list) else [value]):
            doc.fields.append(Field(key, unicode(v)))
    return doc
Ejemplo n.º 3
0
    def add_doc(self, doc):
        """ doc: a dict """
        content = doc['text']
        document = UnprocessedDocument()
        document.fields.append(Field('text', content))

        for k, v in doc.iteritems():
            if k in ['text', 'id']:
                continue
            if type(v) == list:
                for item in v:
                    document.fields.append(Field(k, ensure_unicode(item)))
            else:
                document.fields.append(Field(k, ensure_unicode(v)))
        document.id = str(doc['id'])
        try:
            self.lock.acquire()
            self.dbconn.add(document)
        except errors.IndexerError as e:
            print str(e)
        finally:
            self.lock.release()
Ejemplo n.º 4
0
    def add_doc(self, doc):
        """ doc: a dict """
        content = doc['text']
        document = UnprocessedDocument()
        document.fields.append(Field('text', content))

        for k, v in doc.iteritems():
            if k in ['text', 'id']:
                continue
            if type(v) == list:
                for item in v:
                    document.fields.append(Field(k, ensure_unicode(item)))
            else:
                document.fields.append(Field(k, ensure_unicode(v)))
        document.id = str(doc['id'])
        try:
            self.lock.acquire()
            self.dbconn.add(document)
        except errors.IndexerError as e:
            print str(e)
        finally:
            self.lock.release()