Example #1
0
def test_query_while_indexing():
    try:
        logger.info('starting jinad...')
        os.system('nohup jinad > jinad.log 2> jinaderr.log &')
        time.sleep(5)
        logger.info('starting app.py...')
        os.system(f'nohup {sys.executable} -u app.py -t flows > flow.log 2> flowerr.log &')
        time.sleep(20)
        logger.info('rolling update done in process')
        # add query testing
        query_doc = Document()
        query_doc.text = 'hello world'
        response = _query_docs([query_doc.dict()])
        matches = response['search']['docs'][0].get('matches')
        logger.info(f'got {len(matches)} matches')
        assert matches

    except (Exception, KeyboardInterrupt):
        raise
    finally:
        logger.warning('entering finally...')
        os.system('pkill jinad')
        os.system(f'pkill {sys.executable}')
        logger.warning('following is output from .log files:')
        os.system(f'cat *.log')
Example #2
0
def _docs_from_file(file: str):
    docs = []
    for text in list(_input_lines(filepath=file)):
        d = Document()
        d.text = text
        docs.append(d.dict())
    return docs
Example #3
0
def query_restful():
    while True:
        text = input('please type a sentence: ')
        if not text:
            break

        query_doc = Document()
        query_doc.text = text
        response = _query_docs([query_doc.dict()])

        for doc in response['search']['docs']:
            matches = doc.get('matches')
            len_matches = len(matches)
            logger.info(
                f'Ta-Dah🔮, {len_matches} matches we found for: "{text}" :')

            for idx, match in enumerate(matches):
                score = match['score']['value']
                if score < 0.0:
                    continue
                logger.info(f'> {idx:>2d}({score:.2f}). {match["text"]}')