aboutsummaryrefslogtreecommitdiff
path: root/benchmark/testelasticsearch.py
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-02-03 19:38:50 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-02-03 19:38:50 +0100
commita6bc5bf8d7d003b6cf4e623485b330e1e2830703 (patch)
tree0495b71bcb0ec6e9b72dfa954d11c7ed857aee7a /benchmark/testelasticsearch.py
parentRemoved import of 'conf' module. (diff)
downloadnewspipe-a6bc5bf8d7d003b6cf4e623485b330e1e2830703.tar.gz
newspipe-a6bc5bf8d7d003b6cf4e623485b330e1e2830703.tar.bz2
newspipe-a6bc5bf8d7d003b6cf4e623485b330e1e2830703.zip
Added naive benchmarks for Whoosh and ElasticSearch.
Diffstat (limited to 'benchmark/testelasticsearch.py')
-rw-r--r--benchmark/testelasticsearch.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/benchmark/testelasticsearch.py b/benchmark/testelasticsearch.py
new file mode 100644
index 00000000..7a5d1d5b
--- /dev/null
+++ b/benchmark/testelasticsearch.py
@@ -0,0 +1,58 @@
+#! /usr/bin/env python
+#-*- coding: utf-8 -*-
+
+import elasticsearch
+from elasticsearch import client
+
+from pyaggr3g470r import utils
+
+# Connect to Elasticsearch node specified in the configuration file:
+es = elasticsearch.Elasticsearch(hosts={"127.0.0.1" : 9200})
+
+def delete_index():
+ """
+ Deletes all indexes.
+ """
+ es = elasticsearch.Elasticsearch(hosts={"127.0.0.1" : 9200})
+ ic = client.IndicesClient(es.indices.client)
+ try:
+ ic.delete("")
+ except:
+ pass
+
+def create_index(articles):
+ """
+ Creates the index.
+ """
+ for article in articles:
+ res = es.index(
+ index="pyaggr3g470r",
+ doc_type="text",
+ id=str(article.id),
+ body={
+ "title": article.title,
+ "content": utils.clear_string(article.content)
+ }
+ )
+ return True
+
+def search(term):
+ """
+ Search a term.
+ """
+ try:
+ return es.search(index="pyaggr3g470r", body=
+ {"query" : {
+ "filtered" : {
+ "query" : {
+ "query_string" : {
+ "default_field" : "content",
+ "query" : term
+ }
+ }
+ }
+ }
+ }, size=5000)
+ except elasticsearch.exceptions.NotFoundError as e:
+ logger.warning(str(e))
+ return None \ No newline at end of file
bgstack15