Exemplo n.º 1
0
    def test_delete_document(self, session, index, job):
        session.add(job)
        session.commit()

        doc = job.to_document()

        index = Index()
        index.add_document(doc)

        hits = index.search(job.title)
        assert len(hits) == 1

        index.delete_document(doc['id'])

        hits = index.search(job.title)
        assert len(hits) == 0
Exemplo n.º 2
0
    def test_delete_document(self, session, index, job):
        session.add(job)
        session.commit()

        doc = job.to_document()

        index = Index()
        index.add_document(doc)

        hits = index.search(job.title)
        assert len(hits) == 1

        index.delete_document(doc['id'])

        hits = index.search(job.title)
        assert len(hits) == 0
Exemplo n.º 3
0
    def test_add_document(self, session, index, job):
        session.add(job)
        session.commit()

        index = Index()
        index.add_document(job.to_document())

        hits = index.search(job.title)
        assert len(hits) == 1
        assert int(hits[0]['id']) == job.id
Exemplo n.º 4
0
    def test_add_document(self, session, index, job):
        session.add(job)
        session.commit()

        index = Index()
        index.add_document(job.to_document())

        hits = index.search(job.title)
        assert len(hits) == 1
        assert int(hits[0]['id']) == job.id
Exemplo n.º 5
0
    def test_search_limit(self, session, index, job):
        doc = job.to_document()
        timestamp = doc['created']

        bulk = []
        for i in range(15):
            doc = copy.deepcopy(doc)
            doc['id'] = unicode(i)
            doc['created'] = timestamp - timedelta(days=i)
            bulk.append(doc)

        index = Index()
        index.add_document_bulk(bulk)

        # Search with ascending sort, should return the ids in reverse order.
        hits = index.search(job.title, sort=('created', 'asc'))
        assert [int(hit['id']) for hit in hits] == range(15)[::-1]

        # Search with descending sort.
        hits = index.search(job.title, sort=('created', 'desc'))
        assert [int(hit['id']) for hit in hits] == range(15)
Exemplo n.º 6
0
    def test_search_limit(self, session, index, job):
        doc = job.to_document()
        timestamp = doc['created']

        bulk = []
        for i in range(15):
            doc = copy.deepcopy(doc)
            doc['id'] = unicode(i)
            doc['created'] = timestamp - timedelta(days=i)
            bulk.append(doc)

        index = Index()
        index.add_document_bulk(bulk)

        # Search with ascending sort, should return the ids in reverse order.
        hits = index.search(job.title, sort=('created', 'asc'))
        assert [int(hit['id']) for hit in hits] == range(15)[::-1]

        # Search with descending sort.
        hits = index.search(job.title, sort=('created', 'desc'))
        assert [int(hit['id']) for hit in hits] == range(15)
Exemplo n.º 7
0
def main(query, session):
    name = settings.SEARCH_INDEX_NAME
    directory = settings.SEARCH_INDEX_DIRECTORY

    if not IndexManager.exists(name, directory):
        die('Search index does not exist!')

    if isinstance(query, str):
        query = unicode(query, 'utf-8')

    index = Index()
    for result in index.search(query):
        job = session.query(Job).get(result['id'])
        print job
Exemplo n.º 8
0
    def test_update_document(self, session, index, job):
        session.add(job)
        session.commit()

        doc = job.to_document()

        index = Index()
        index.add_document(doc)

        doc['job_type'] = u'updated'
        index.update_document(doc)

        hits = index.search(u'updated')
        assert len(hits) == 1
        assert int(hits[0]['id']) == job.id
Exemplo n.º 9
0
    def test_update_document(self, session, index, job):
        session.add(job)
        session.commit()

        doc = job.to_document()

        index = Index()
        index.add_document(doc)

        doc['job_type'] = u'updated'
        index.update_document(doc)

        hits = index.search(u'updated')
        assert len(hits) == 1
        assert int(hits[0]['id']) == job.id
Exemplo n.º 10
0
    def search_jobs(self, query, sort=None, limit=None):
        index = Index()
        hits = []

        kwargs = dict()
        if sort:
            kwargs['sort'] = sort
        if limit:
            kwargs['limit'] = limit

        for hit in index.search(query, **kwargs):
            job = db.session.query(Job).get(hit['id'])
            # Make sure that we don't accidentally return an unpublished job
            # that happened to be in the search index.
            if job and job.published:
                hits.append(job)

        return hits
Exemplo n.º 11
0
    def search_jobs(self, query, sort=None, limit=None):
        index = Index()
        hits = []

        kwargs = dict()
        if sort:
            kwargs['sort'] = sort
        if limit:
            kwargs['limit'] = limit

        for hit in index.search(query, **kwargs):
            job = db.session.query(Job).get(hit['id'])
            # Make sure that we don't accidentally return an unpublished job
            # that happened to be in the search index.
            if job and job.published:
                hits.append(job)

        return hits
Exemplo n.º 12
0
 def search(self, query):
     index = Index()
     return index.search(query)
Exemplo n.º 13
0
 def search(self, query):
     index = Index()
     return index.search(query)