Example #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
Example #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
Example #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
Example #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
Example #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)
Example #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)
Example #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
Example #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
Example #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
Example #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
Example #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
Example #12
0
 def search(self, query):
     index = Index()
     return index.search(query)
Example #13
0
 def search(self, query):
     index = Index()
     return index.search(query)