Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented basic Sphinxsearch indexer worker. #167

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pypln/backend/workers/sphinxsearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# coding: utf-8
#
# Copyright 2012 NAMD-EMAP-FGV
#
# This file is part of PyPLN. You can get more information at: http://pypln.org/.
#
# PyPLN is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyPLN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyPLN. If not, see <http://www.gnu.org/licenses/>.

import cPickle

import nltk
from collections import defaultdict
from pypelinin import Worker
import MySQLdb

SPHINX_HOST = "127.0.0.1"
SPHINX_PORT = 9306
SPHINX_INDEX = 'pypln_realtime'


class Sphinxsearch(Worker):
"""Insert a document into a RT index in sphinsearch"""
requires = ['text', '_id']
def __init__(self):
connection = MySQLdb.connect(hostname=SPHINX_HOST, port=SPHINX_PORT)
cursor = connection.cursor()

def process(self, document):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please insert a little test to this method? As Sphinx API is compatible with MySQL/MariaDB, we can test it using MySQL instead of having Sphinx installed just for running tests, since MySQL is way easier to deploy.

ID = int('0x'+str(document['_id']), 16)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may have here the same problem we had in mediacloud. There we decided to reindex the entire collection every time, but in PyPLN's case this makes less sense (because of the way documents are usually inserted). We may have to find another solution for this.

self.cursor.execute("INSERT INTO {} (id, text) values ({}, {})".format(SPHINX_INDEX, ID, document['text']))


1 change: 1 addition & 0 deletions requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Pillow
# If you have problems installing wordcloud, please install Cython before
# running `pip install -r requirements/production.txt`
-e git+https://github.com/flavioamieiro/word_cloud.git#egg=wordcloud
MySQL-python
7 changes: 4 additions & 3 deletions scripts/sphinx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ source mongodb1
}


index mongo
index pypln_realtime
{
type = rt
source = mongodb1
path = /tmp/mongo
docinfo = extern
charset_type = utf-8
rt_field = text

}


Expand Down