-
Notifications
You must be signed in to change notification settings - Fork 17
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
ID = int('0x'+str(document['_id']), 16) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'])) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.