示例#1
0
def main():
    logging.basicConfig()

    dsn = "dbname='pgtxtest' user='******' password='******'"
    main_index = PGTextIndex(discriminator=discriminate_thing,
                             dsn=dsn,
                             drop_and_create=True)

    # Try to expose a bug in concurrent indexing.
    def reindex_loop():
        index = PGTextIndex(discriminator=discriminate_thing, dsn=dsn)
        for j in range(1000):
            obj10 = Thing(
                10, "Document",
                "Document body %d from thread %s" % (j, thread.get_ident()))
            index.index_doc(obj10.docid, obj10)
            transaction.commit()

    threads = []
    for _i in range(8):
        t = Thread(target=reindex_loop)
        threads.append(t)
        t.start()

    for t in threads:
        t.join()

    print main_index.apply('body')
示例#2
0
 def reindex_loop():
     index = PGTextIndex(discriminator=discriminate_thing, dsn=dsn)
     for j in range(1000):
         obj10 = Thing(10, "Document", "Document body %d from thread %s"
                       % (j, thread.get_ident()))
         index.index_doc(obj10.docid, obj10)
         transaction.commit()
示例#3
0
def main():
    logging.basicConfig()

    dsn = "dbname='pgtxtest' user='******' password='******'"
    main_index = PGTextIndex(discriminator=discriminate_thing,
                             dsn=dsn,
                             drop_and_create=True)

    # Try to expose a bug in concurrent indexing.
    def reindex_loop():
        index = PGTextIndex(discriminator=discriminate_thing, dsn=dsn)
        for j in range(1000):
            obj10 = Thing(10, "Document", "Document body %d from thread %s"
                          % (j, thread.get_ident()))
            index.index_doc(obj10.docid, obj10)
            transaction.commit()

    threads = []
    for _i in range(8):
        t = Thread(target=reindex_loop)
        threads.append(t)
        t.start()

    for t in threads:
        t.join()

    print main_index.apply('body')
示例#4
0
 def reindex_loop():
     index = PGTextIndex(discriminator=discriminate_thing, dsn=dsn)
     for j in range(1000):
         obj10 = Thing(
             10, "Document",
             "Document body %d from thread %s" % (j, thread.get_ident()))
         index.index_doc(obj10.docid, obj10)
         transaction.commit()
示例#5
0
def main(args=sys.argv):
    if PGTextIndex is None:
        print >> sys.stderr, NO_PG_TEXT_INDEX
        sys.exit(1)
    parser = OptionParser(description=__doc__)
    parser.add_option(
        '-C',
        '--config',
        dest='config',
        default=None,
        help="Specify a paster config file. Defaults to $CWD/etc/karl.ini")
    parser.add_option('-D',
                      '--dsn',
                      dest='dsn',
                      default=None,
                      help="dsn to connect to postgresql database")
    parser.add_option('-n',
                      '--database-name',
                      dest='database_name',
                      default=None,
                      help="Name of database to connect to")
    parser.add_option('-d',
                      '--dry-run',
                      dest='dry_run',
                      action="store_true",
                      default=False,
                      help="Don't commit the transactions")
    parser.add_option('-i',
                      '--interval',
                      dest='commit_interval',
                      action="store",
                      default=200,
                      help="Commit every N transactions")

    options, args = parser.parse_args()
    if args:
        parser.error("Too many parameters: %s" % repr(args))

    commit_interval = int(options.commit_interval)

    config = options.config
    if config is None:
        config = get_default_config()
    root, closer = open_root(config)

    def output(msg):
        print msg

    try:
        index = PGTextIndex(
            get_weighted_textrepr,
            options.
            dsn,  # "dbname=karl user=karl host=localhost password=karl",
            database_name=options.database_name)

        if options.dry_run:
            transaction.abort()
        else:
            transaction.commit()

        # reindex_catalog commits its own transactions
        catalog = root.catalog
        catalog['texts'] = index
        reindex_catalog(root,
                        commit_interval=commit_interval,
                        dry_run=options.dry_run,
                        output=output)
    except:
        transaction.abort()
        raise