sphinx测试数据生成
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测试数据生成的更多相关文章
- [Dynamic Language] 用Sphinx自动生成python代码注释文档
用Sphinx自动生成python代码注释文档 pip install -U sphinx 安装好了之后,对Python代码的文档,一般使用sphinx-apidoc来自动生成:查看帮助mac-abe ...
- 收藏清单: python测试数据生成及代码扫描最全工具列表
Test Data manipulation 测试数据的操作和处理 faker - 生成假数据的python库 fake2db - 创建假数据库 ForgeryPy - 使用起来很简单的假数据生成库. ...
- 使用sphinx快速生成Python API 文档
一 简单介绍 不管是开源还是闭源,文档都是很重要的.当然理论上说,最好的文档就是代码本身,但是要让所有人都能读懂你的代码这太难了.所以我们要写文档.大部分情况,我们不希望维护一份代码再加上一份文档, ...
- 使用python编写量子线路打印的简单项目,并使用Sphinx自动化生成API文档
技术背景 该文章一方面从量子线路的打印着手,介绍了一个简单的python量子线路工程.同时基于这个简单的小工程,我们顺带的介绍了python的API文档自动化生成工具Sphinx的基本使用方法. 量子 ...
- OnlineJudge测试数据生成模板
int类型数据生成一(正数最多4位): #include <bits/stdc++.h> using namespace std; int main() { freopen("t ...
- Junit单元测试数据生成工具类
在Junit单元测试中,经常需要对一些领域模型的属性赋值,以便传递给业务类测试,常见的场景如下: com.enation.javashop.Goods goods = new com.enation. ...
- MySQL快速生成本地测试数据
利用数据的存储过程生成测试数据: 我们可以通过数据库的的 INSERT 语句直接在存储过程中向普通数据表中添加数据,但是 当我们添加到百万数据后,往普通表插入测试数据的性能就会明显降低.所以在这里建议 ...
- 使用faker 生成测试数据
测试数据生成 faker基础使用 from faker import Faker f=Faker(locale='zh_CN') print(f.name()) address 地址 person 人 ...
- Sphinx和coreseek检索引擎
Sphinx是检索英文用,coreseek是检索中文用. Sphinx(斯芬克斯)是一个基于SQL的全文检索引擎,可以结合MySQL,PostgreSQL做全文搜索,它可以提供比数据库本身更专业的搜索 ...
随机推荐
- bootspring + mybaits +mysql Date 类型的处理
mysql 中有date 类型的属性,java实体类中对应的属性是java.sql.Date 类的. 最初的bug是怎么新增,joinDate 值都是null. 千辛万苦学会了用String转Date ...
- sqlserver复制表数据到另一个表
SQL Server中,如果目标表存在: insert into 目标表 select * from 原表; SQL Server中,,如果目标表不存在: select * into 目标表 from ...
- python013 Python3 循环语句
Python3 循环语句本章节将为大家介绍Python循环语句的使用.Python中的循环语句有 for 和 while.Python循环语句的控制结构图如下所示: while 循环Python中wh ...
- SPOJ GNYR09F 数字上的找规律DP
Problem C SPOJ GNYR09F dp题,dp可能刚刚开始对大家来说比较难,但是静下心来分析还是比较简单的: dp(i ,j ,k)表示前i个数中,当前累积和为j,末尾数字为k的 ...
- python学习之-- random模块
random模块random.random():随机打印一个小数random.randint(1,10):随机打印1-10之间的任意数字(包括1和10)random.randrange(1,10):随 ...
- Substrings--poj1226(字符串)
Description You are given a number of case-sensitive strings of alphabetic characters, find the larg ...
- [Bzoj2039]小Z的袜子 (莫队算法模板题)
2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 11866 Solved: 5318[Sub ...
- MySQLWorkbench里的稀奇事之timestamp的非空默认值
在创建表时,某字段为非空时间戳,timestamp not null 问题来了,使用workbench建表时,如果值非空,是需要有一个默认值的,不然会报错. 那么,如果是更新时自动填充可以使用DEFA ...
- matlab 画图技巧
基本画图工具:matlab 画图中线型及颜色设置 matlab中坐标轴设置技巧 **Matlab中的坐标轴设置技巧** axisoff; %去掉坐标轴 axistight; ...
- Java线程池的简单使用
最近由于公司的业务需求,需要使用线程池来进行对数据进行处理,所以就简单的学习了一下线程池的东西,刚接触感觉挺难的,不过使用了就不感觉那么难了,还是蛮简单的, package com.yd.sms.jo ...