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. SPOJ GNYR09F 数字上的找规律DP

    Problem C      SPOJ GNYR09F dp题,dp可能刚刚开始对大家来说比较难,但是静下心来分析还是比较简单的: dp(i ,j ,k)表示前i个数中,当前累积和为j,末尾数字为k的 ...

  2. BZOJ:[JSOI2009]游戏Game【二分图匹配乱搞】

    题目大意:n*m的棋盘,其中有些区域是禁区,两个人在棋盘上进行博弈,后手选择棋子的初始位置,然后先后手轮流将棋子往上下左右移动,走过的区域不能再走,问能否有一个位置使得后手必胜 Input 输入数据首 ...

  3. FLEX中restrict限定TextInput输入

    restrict限制的意思 1. 限制某个字符的输入,用符号 ^ 跟上要限制的字符,可跟多个字符  <!-- 限制字符"~"的输入 --> <mx:TextInp ...

  4. Python的描述符

    1.描述符的定义 描述符是与特定属性互相绑定的一种协议,通过方法被触发修改属性,这些方法包括__get__(),__set__(),__delete__().将这些方法定义在类中,即可实现描述符 2. ...

  5. 【转】Wireshark技巧-过滤规则和显示规则

    原文: http://www.cnblogs.com/icez/p/3973873.html ----------------------------------------------------- ...

  6. CentOS里route命令详解

    Route 功能简述:linux系统中的route命令能够用于IP路由表的显示和操作.它的主要作用是创建一个静态路由让指定一个主机或者一个网络通过一个网络接口,如eth0.当使用"add&q ...

  7. [Javascript] Use JavaScript's for-in Loop on Objects with Prototypes

    Loops can behave differently when objects have chained prototype objects. Let's see the difference w ...

  8. Android开发艺术-第二章 IPC 机制

    2.1 Android IPC 简单介绍 IPC 意为进程间通信或者跨进程通信,线程是 CPU 调度的最小单元,是一种有限的系统资源. 进程一般指一个执行单元.不论什么操作系统都须要对应的 IPC 机 ...

  9. java 实现打印当前月份的日历

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcTc0NTQwMTk5MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  10. C++第9周(春)项目5 - 一元一次方程类

    课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目5]设计一元一次方程类.求形如ax+b= ...