import json
from random import sample, randint
from uuid import uuid4 def gen_random_words():
with open("D:\\exp\\test_data\\dictionary.txt") as f:
words = [word.strip() for word in f]
f.close()
# print "OK. words length:", len(words)
return sample(words, 3000)
return [] total_words = 0
def sample_words(search_words, random_words):
global total_words
sample_cnt = 1000
for word in random_words:
total_words += 1
if len(search_words) < sample_cnt:
search_words.append(word)
else:
if randint(1, total_words) <= sample_cnt:
kick_off = randint(0, sample_cnt-1)
search_words[kick_off] = word def gen_an_event(words, search_words):
query_words = sample(words, randint(1, 10))
sample_words(search_words,query_words)
title = " ".join(query_words)
query_words = sample(words, randint(1, 100))
sample_words(search_words,query_words)
content = " ".join(query_words)
event_data = {"title": title, "content": content}
return event_data if __name__ == "__main__":
search_words = []
for i in range(1):
words = gen_random_words()
lines_cnt = 500000
es_out_put = [""]*lines_cnt
for i in range(0, lines_cnt):
event = gen_an_event(words, search_words)
es_out_put[i] = " (%d, 2, 9, NOW(), '%s', '%s'), \n" % (i+5, event["title"], event["content"])
# print es_out_put
# print splunk_out_put
out_puts = [es_out_put]
file_name = str(uuid4()) + ".txt"
for i,dir_name in enumerate(["Sphinx"]):
outfile = "D:\\test_data\\%s\\%s" % (dir_name, file_name)
f = open(outfile, "w")
for j in range(0, lines_cnt):
f.write(out_puts[i][j])
f.close()
print outfile
outfile = "D:\\test_data\\search_words2.txt"
f = open(outfile, "w")
f.write(json.dumps(search_words))
f.close() sql = '''
DROP TABLE IF EXISTS test.documents;
CREATE TABLE test.documents
(
id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
group_id INTEGER NOT NULL,
group_id2 INTEGER NOT NULL,
date_added DATETIME NOT NULL,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL
); REPLACE INTO test.documents ( id, group_id, group_id2, date_added, title, content ) VALUES
( 1, 1, 5, NOW(), 'test one', 'this is my test document number one. also checking search within phrases.' ),
( 2, 1, 6, NOW(), 'test two', 'this is my test document number two' ),
( 3, 2, 7, NOW(), 'another doc', 'this is another group' ),
( 4, 2, 8, NOW(), 'doc number four', 'this is to test groups' ); DROP TABLE IF EXISTS test.tags;
CREATE TABLE test.tags
(
docid INTEGER NOT NULL,
tagid INTEGER NOT NULL,
UNIQUE(docid,tagid)
); INSERT INTO test.tags VALUES
(1,1), (1,3), (1,5), (1,7),
(2,6), (2,4), (2,2),
(3,15),
(4,7), (4,40);
'''

sphinx测试数据生成的更多相关文章

  1. [Dynamic Language] 用Sphinx自动生成python代码注释文档

    用Sphinx自动生成python代码注释文档 pip install -U sphinx 安装好了之后,对Python代码的文档,一般使用sphinx-apidoc来自动生成:查看帮助mac-abe ...

  2. 收藏清单: python测试数据生成及代码扫描最全工具列表

    Test Data manipulation 测试数据的操作和处理 faker - 生成假数据的python库 fake2db - 创建假数据库 ForgeryPy - 使用起来很简单的假数据生成库. ...

  3. 使用sphinx快速生成Python API 文档

    一  简单介绍 不管是开源还是闭源,文档都是很重要的.当然理论上说,最好的文档就是代码本身,但是要让所有人都能读懂你的代码这太难了.所以我们要写文档.大部分情况,我们不希望维护一份代码再加上一份文档, ...

  4. 使用python编写量子线路打印的简单项目,并使用Sphinx自动化生成API文档

    技术背景 该文章一方面从量子线路的打印着手,介绍了一个简单的python量子线路工程.同时基于这个简单的小工程,我们顺带的介绍了python的API文档自动化生成工具Sphinx的基本使用方法. 量子 ...

  5. OnlineJudge测试数据生成模板

    int类型数据生成一(正数最多4位): #include <bits/stdc++.h> using namespace std; int main() { freopen("t ...

  6. Junit单元测试数据生成工具类

    在Junit单元测试中,经常需要对一些领域模型的属性赋值,以便传递给业务类测试,常见的场景如下: com.enation.javashop.Goods goods = new com.enation. ...

  7. MySQL快速生成本地测试数据

    利用数据的存储过程生成测试数据: 我们可以通过数据库的的 INSERT 语句直接在存储过程中向普通数据表中添加数据,但是 当我们添加到百万数据后,往普通表插入测试数据的性能就会明显降低.所以在这里建议 ...

  8. 使用faker 生成测试数据

    测试数据生成 faker基础使用 from faker import Faker f=Faker(locale='zh_CN') print(f.name()) address 地址 person 人 ...

  9. Sphinx和coreseek检索引擎

    Sphinx是检索英文用,coreseek是检索中文用. Sphinx(斯芬克斯)是一个基于SQL的全文检索引擎,可以结合MySQL,PostgreSQL做全文搜索,它可以提供比数据库本身更专业的搜索 ...

随机推荐

  1. 67. @Transactional的类注入失败【从零开始学Spring Boot】

    [从零开始学习Spirng Boot-常见异常汇总] Spring的代理模式有两种:java自带的动态代理模式和cglib代理模式,cglib代码模式适用于没有接口的类,而java自带适用于接口类,默 ...

  2. C#通信学习(一)

    基础知识 TCP/IP:Transmission Control Protocol/Internet Protocol,传输控制协议/因特网互联协议,又名网络通讯协议.简单来说:TCP控制传输数据,负 ...

  3. CentOS 中 YUM 安装桌面环境

    CentOS 作为服务器的操作系统是很常见的,但是因为需要稳定而没有很时髦的更新,所以很少做为桌面环境.在服务器上通常不需要安装桌面环境,最小化地安装 CentOS(也就是 minimal CentO ...

  4. HDU1711 最基础的kmp算法

    Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], .... ...

  5. 反编译sencha toucha打包的apk文件,修改应用名称支持中文以及去除应用标题栏

    一.去除安卓应用标题栏 sencha touch打包android安装包,去掉标题栏titlebar的简单方法 (有更复杂更好的方法,参看"二.利用反编译修改apk的应用名称为中文" ...

  6. CodeForces - 320B Ping-Pong (Easy Version)

    题目最开始 完全不懂 配合案例也看不懂-_- 总之就是用传递性 问能否从a区间到b区间 dfs(x,y) 走遍与第x区间所有的 联通区间 最后检验 第y区是否被访问过 是一道搜索好题 搜索还需加强 # ...

  7. 2016 Multi-University Training Contest 1 solutions BY HIT

    首先向大家表示抱歉,因为这套题是去年出的,中间间隔时间太长,今年又临时准备仓促, 所以部分题目出现了一些问题,非常抱歉. Abandoned country 首先注意到任意两条边的边权是不一样的,由此 ...

  8. Visual Studio 2017 RC的坑

    ASP.NET Core Project add Docker Project Support的问题 执行上面操作以后,如果本机没有装好docker,就会一直报错,无法build通过,无论你在Proj ...

  9. 学习日常笔记<day16>mysql加强

    1.数据约束 1.1什么是数据约束 对用户操作表的数据进行约束 1.2 默认值 作用:当永辉对使用默认值的字段不插入值的时候,就使用默认值 注意: 1)对默认值字段插入null是可以的 2)对默认值字 ...

  10. 109.Convert sorted list to BST

    /* * 109.Convert sorted list to BST * 2016.12.24 by Mingyang * 这里的问题是对于一个链表我们是不能常量时间访问它的中间元素的. * 这时候 ...