def indexFingerprint(self, batch_mode=False):
        def is_if_yes_no(question):
            return question.type in 'choice-yesno' or \
                    question.type in 'choice-yesnocomment' or \
                    question.type in 'choice-yesnodontknow'

        d = {}

        # Get parameters that are only on fingerprint
        # type_t
        d['id'] = self.fingerprint_hash
        d['type_t'] = self.questionnaire.slug
        d['date_last_modification_t'] = self.last_modification.strftime(
            '%Y-%m-%d %H:%M:%S.%f')
        d['created_t'] = self.created.strftime('%Y-%m-%d %H:%M:%S.%f')

        d['user_t'] = self.unique_users_string()

        d['percentage_d'] = self.fill

        adicional_text = ""

        # Add answers
        answers = Answer.objects.filter(fingerprint_id=self)

        for answer in answers:
            question = answer.question

            # We try to get permissions preferences for this question
            permissions = self.getPermissions(
                QuestionSet.objects.get(id=question.questionset.id))

            slug = question.slug_fk.slug1

            if permissions.allow_indexing or slug == 'database_name':
                setProperFields(d, question, slug, answer.data)
                if is_if_yes_no(question) and 'yes' in answer.data:
                    adicional_text += question.text + " "
                if answer.comment != None:
                    d['comment_question_' + slug + '_t'] = answer.comment

        d['text_t'] = generateFreeText(d) + " " + adicional_text
        d['mlt_t'] = generateMltText(d)

        if batch_mode:
            return d
        else:
            print "-- Indexing unique fingerprint hash " + str(
                self.fingerprint_hash)
            c = CoreEngine()

            results = c.search_fingerprint("id:" + self.fingerprint_hash)
            if len(results) == 1:
                # Delete old entry if any
                c.delete(results.docs[0]['id'])

            c.index_fingerprint_as_json(d)
示例#2
0
    def indexFingerprint(self, batch_mode=False):
        def is_if_yes_no(question):
            return question.type in 'choice-yesno' or \
                    question.type in 'choice-yesnocomment' or \
                    question.type in 'choice-yesnodontknow'

        d = {}

        # Get parameters that are only on fingerprint
        # type_t
        d['id']=self.fingerprint_hash
        d['type_t'] = self.questionnaire.slug
        d['date_last_modification_t'] = self.last_modification.strftime('%Y-%m-%d %H:%M:%S.%f')
        d['created_t'] = self.created.strftime('%Y-%m-%d %H:%M:%S.%f')

        d['user_t'] = self.unique_users_string()

        d['percentage_d'] = self.fill

        adicional_text = ""


        # Add answers
        answers = Answer.objects.filter(fingerprint_id=self)

        for answer in answers:
            question = answer.question

            # We try to get permissions preferences for this question
            permissions = self.getPermissions(QuestionSet.objects.get(id=question.questionset.id))

            slug = question.slug_fk.slug1

            if permissions.allow_indexing or slug == 'database_name':
                setProperFields(d, question, slug, answer.data)
                if is_if_yes_no(question) and 'yes' in answer.data:
                    adicional_text += question.text+ " "
                if answer.comment != None:
                    d['comment_question_'+slug+'_t'] = answer.comment


        d['text_t']= generateFreeText(d) +  " " + adicional_text
        d['mlt_t'] = generateMltText(d)

        if batch_mode:
            return d
        else:
            print "-- Indexing unique fingerprint hash "+str(self.fingerprint_hash)
            c = CoreEngine()

            results = c.search_fingerprint("id:"+self.fingerprint_hash)
            if len(results) == 1:
                # Delete old entry if any
                c.delete(results.docs[0]['id'])

            c.index_fingerprint_as_json(d)
示例#3
0
def convertFieldsOnSolr(fields, new_type):
    c = CoreEngine()

    suffix = assert_suffix(new_type)

    if suffix == None:
        print '-- Invalid new type, process cancelled.'
        return False

    documents = c.search_fingerprint("*:*")

    print "Started converting fields on all databases, number of databases: " + str(
        len(documents))

    for document in documents:
        doc = document
        del doc['_version_']

        for field in fields:
            try:
                value = doc[str(field) + '_t']

                value = convert_value(value, new_type)

                if value == None:
                    print "-- Couldn't convert field " + str(
                        field) + " for database " + doc['id'] + ". " + str(
                            doc[str(field) +
                                '_t']) + " is not of type " + str(new_type)
                else:
                    doc[str(field) + suffix] = value

            except KeyError:
                print "-- " + str(
                    doc['id']) + ' doesn\'t have the field ' + str(
                        field) + ', ignoring this field on this database.'

        c.delete(doc['id'])
        c.index_fingerprint_as_json(doc)

    print "Done converting fields on all databases"
    return True
示例#4
0
def convertFieldsOnSolr(fields, new_type):
    c = CoreEngine()

    suffix = assert_suffix(new_type)


    if suffix == None:
        print '-- Invalid new type, process cancelled.'
        return False

    documents = c.search_fingerprint("*:*")

    print "Started converting fields on all databases, number of databases: "+str(len(documents))

    for document in documents:
        doc = document
        del doc['_version_']

        for field in fields:
            try:
                value = doc[str(field)+'_t']

                value = convert_value(value, new_type)

                if value == None:
                    print "-- Couldn't convert field "+str(field)+" for database " + doc['id'] + ". "+str(doc[str(field)+'_t'])+" is not of type " + str(new_type)
                else:
                    doc[str(field)+suffix] = value

            except KeyError:
                print "-- "+str(doc['id'])+' doesn\'t have the field '+str(field)+', ignoring this field on this database.'

        c.delete(doc['id'])
        c.index_fingerprint_as_json(doc)

    print "Done converting fields on all databases"
    return True
示例#5
0
def unindexFingerprint(fingerprint_id):
    c = CoreEngine()
    c.delete(fingerprint_id)
示例#6
0
def unindexFingerprint(fingerprint_id):
    c = CoreEngine()
    c.delete(fingerprint_id)