Django: which search library do you recommend for Windows? [closed] - django

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I develop site on Windows, but when I tried to add search, I encountered too many problems with Sphinx and Haystack+Xapian. Possible solution is to go to Linux, but I don't want to change my working environment. What search library/server/etc do you recommend for Windows? Which version, repository, tutorials have you used? Maybe you can wrote your own mini-tutorial? I really frustrated with this problem and cannot step forward for several days.

Finally I got Sphinx to work. Still problems with searching in multiple tables but this is solvable I believe.
Useful links:
How to install and implement Sphinx Search on XAMPP for Windows 7 with MySQL and PHP
Tutorial: Installing on Windows
Installing Sphinx on Windows
In the following snippets paths on my system are used.
Search function in views.py:
def search(request):
from sphinxapi import SphinxClient, SPH_MATCH_ANY, SPH_SORT_RELEVANCE
S = request.GET['search']
client = SphinxClient()
client.SetServer('127.0.0.1', 9312)
#client.SetSelect("*, AVG(price) AS avgprice")
client.SetMatchMode(SPH_MATCH_ANY)
client.SetSortMode(SPH_SORT_RELEVANCE)
client.SetFieldWeights({'header': 20, 'text': 10})
result = client.Query(S, '*')
matches = result["matches"]
ids = [match["id"] for match in matches]
article = {"header": "Search results", "text": ""}
if ids != []:
objects = Main.objects.filter(pk__in = ids)
for object in objects:
url = request.build_absolute_uri(object.get_absolute_url())
article["text"] += "" + object.header + "" + "\n"
ResponseDict = {"articles": [article]}
else:
ResponseDict = {"articles": []}
return render_to_response("index.html", ResponseDict,
context_instance = RequestContext(request))
sphinx.conf (which is in ...\Sphinx\bin folder):
source src1
{
type = pgsql
sql_host = localhost
sql_user = <db user>
sql_pass = <pwd>
sql_db = <db name>
sql_port = 5432
sql_query = \
SELECT id, header, text \
FROM app_main
sql_query_info = SELECT * FROM app_main WHERE id=$id
sql_attr_uint = source_id
}
source src2
{
type = pgsql
sql_host = localhost
sql_user = <db user>
sql_pass = <pwd>
sql_db = <db name>
sql_port = 5432
sql_query = \
SELECT id, header, text \
FROM app_comment
sql_query_info = SELECT * FROM app_comment WHERE id=$id
sql_attr_uint = source_id
}
index test1
{
source = src1
source = src2
path = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/data/test1
docinfo = extern
charset_type = utf-8
}
index testrt
{
type = rt
rt_mem_limit = 32M
path = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/data/testrt
charset_type = utf-8
rt_field = title
rt_field = content
rt_attr_uint = gid
}
indexer
{
mem_limit = 32M
}
searchd
{
listen = 127.0.0.1:9312
log = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/log/searchd.log
query_log = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/log/query.log
read_timeout = 5
max_children = 30
pid_file = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = D:/blizzard/Projects/Python/Web/moz455/app/sphinx/data
}
Search is available after creating \sphinx, \sphinx\data and \sphinx\log folders in app folder, indexing with command
D:/Old/Sphinx/bin/indexer --config D:/Old/Sphinx/bin/sphinx.conf --all
and starting searchd with command
D:/Old/Sphinx/bin/searchd --config D:/Old/Sphinx/bin/sphinx.conf

Related

Browsing through multiple audio files for playback on Asterisk dialplan

I'm trying to make a voicemail system on Asterisk 16, FreePBX 16 and CentOS 7 that lets people browse and choose from a list of prerecorded audio files. When the caller enters the menu to select the audio files, they're told how to browse through the different files. In the /var/lib/asterisk/sounds/ directory, the files are named from 1 to 3 (1.wav, 2.wav etc.) currently and the caller presses 1 to go to the previous file and 2 to go to the next file and 3 to select the current file they're listening to. The extensions part goes as such:
[prerecorded]
exten = s,1,NoOp(Pre-recorded messages)
same = n,Set(LOOP=0)
same = n,Set(FILE=1)
same = n(timeout),Wait(1)
same = n,Playback(browsing_tutorial)
same = n(loop),NoOp(Loop)
same = n,Background(${FILE})
same = n,WaitExten(5)
exten = 1,1,NoOp(Previous file)
same = n,Set(FILE=$[ ${FILE} - 1])
same = n,GoToIf($[ ${FILE} = 0 ]?:s,loop)
same = n,Playback(first_file)
same = n,Set(FILE=1)
same = n,GoTo(s,loop)
exten = 2,1,NoOp(Next file)
same = n,Set(FILE=$[ ${FILE} + 1])
same = n,GoToIf($[ ${FILE} = 4 ]?:s,loop)
same = n,Playback(last_file)
same = n,Set(FILE=3)
same = n,GoTo(s,loop)
exten = #,1,NoOp(Repeat)
same = n,GoTo(s,1)
exten = t,1,NoOp(No input)
same = n,Set(LOOP=$[ ${LOOP} + 1 ])
same = n,GoToIf($[ ${LOOP} > 2 ]?:s,timeout)
same = n,HangUp()
Doing it this way lets me browse through the files, but it warrants editing the extensions every time I add or remove any prerecorded files (which will be done often). If there's any way I can do this without needing to edit the extensions, it would be great.
You can write your own application using native C/C++ interface in asterisk, if you skilled enough. See app_voicemail.c
You also can use AGI or ARI interface and control dialplan with scripted language
Other option is voicemail storage in db and db-driven app using func_odbc

How to parse list-Python

I'm trying to get EBS volumes ID so i can create LLD Zabbix discovery
https://github.com/omni-lchen/zabbix-cloudwatch/blob/master/awsLLD.py
def getEBS(a, r):
account = a
aws_account = awsAccount(account)
aws_access_key_id = aws_account._aws_access_key_id
aws_secret_access_key = aws_account._aws_secret_access_key
aws_region = r
#component = c
# Init LLD Data
lldlist = []
llddata = {"data":lldlist}
# Connect to EC2 service
conn = awsConnection()
conn.ebsConnect(aws_region, aws_access_key_id, aws_secret_access_key)
ebsConn = conn._aws_connection
# Save EBS function results in a list
functionResultsList = []
# Save volume names in a list
tdata = []
# Get a list of EBS volumes
functionResults = ebsConn.get_all_volumes()
output:
[Volume:vol-029213f06d66eadac, Volume:vol-00fbd5dfaebd79e83, Volume:vol-0eeb126d13ecf0eed, Volume:vol-09a1f3446b3f78ea5]
I'm having issues parsing above output to get
vol-029213f06d66eadac
vol-0eeb126d13ecf0eed
vol-09a1f3446b3f78ea5
I know i need to write something like:
for la in functionResultsList:
print la[0]
getting first element
but don't know how to continue
removed list and used:
for la in range(len(functionResults)):
print functionResults[la]
output:
Volume:vol-029213f06d66eadac
Volume:vol-00fbd5dfaebd79e83
Volume:vol-0eeb126d13ecf0eed
Volume:vol-09a1f3446b3f78ea5
New to python and don't know what's list actually- but i don't think it's reason for downwote

Updating the parent via rally API

I have more than 1000 projects which are in closed state under one of our work space.
I got that data from - https://rally1.rallydev.com/slm/webservice/1.29/subscription?fetch=Workspaces,Name,Projects,State
We want to update the "Parent" for the projects which are marked as "Closed".
import sys
from pyral import Rally, rallyWorkset
options = [arg for arg in sys.argv[1:] if arg.startswith('--')]
args = [arg for arg in sys.argv[1:] if arg not in options]
server = <server>
apikey = <api_key>
workspace = <workspace>
project = <project_name>
rally = Rally(server,apikey=apikey, workspace=workspace, project=project)
rally.enableLogging('mypyral.log')
Method to check the status of the projects -
projects = rally.getProjects(workspace=workspace)
for proj in projects:
print (" %12.12s %s %s" % (proj.oid, proj.Name, proj.State))
I didnt find any reference to update the project parent here - Rest API post method - http://pyral.readthedocs.io/en/latest/interface.html?highlight=post
I would do it in the following way:
#get object for 'New Parent':
target_project = rally.getProject('NewParentForClosedProjects')
projects = rally.getProjects(workspace=workspace)
for proj in projects:
#get children of project
children = proj.Children
for child in children:
#if project closed:
if child.State == 'Closed':
#Then update Parent to new one:
project_fields = {
"ObjectID": child.oid,
"Parent": target_project.ref
}
try:
result = rally.update('Project', project_fields)
print "Project %s has been successfully updated with new %s parent" % (str(child.Name), str(child.Parent))
except RallyRESTException, ex:
print "Update failure for Project %s" % (str(child.Name))
print ex

py2app - preserve directory structure

I would like to make a mac os x app for distributing my program.
The problem is that current script puts "images/Diagram.png" and other files under "images" folder to "Resources" but not to "Resources/images" as expected
What can I change in this setup.py part in order to put png files under images?
mainscript, ico, icns = "aproxim.py", "sum.ico", "sum.icns"
files = ["images/Diagram.png", "images/document.png", "images/Exit.png", "images/floppydisc.png",
"images/folder.png", "images/Info.png", "images/settings.png"]
scripts = ["app_settings_dialog", "app_window", "approximator", "approximator2", "data_format",
"easy_excel", "functions", "main_window", "settings_dialog",
"util_data", "util_parameters"]
description = "Approximator is program for experimental data approximation and interpolation (20 dependencies for select)"
common_options = dict(name = "Approximator", version = "1.7", description = description)
if sys.platform == 'darwin':
setup(
setup_requires = ['py2app'],
app = [mainscript],
options = dict(py2app = dict(includes = scripts, resources = files, iconfile = icns)),
**common_options)
It is easy, hope it is useful for other Python developers:
resources = [('images', files), ('', [ico])]

Django sphinx works only after app restart

I've set up django-sphinx in my project, which works perfectly only for some time. Later it always returns empty result set. Surprisingly restarting django app fixes it. And search works again but again only for short time (or very limiter number of queries). Heres my sphinx.conf:
source src_questions
{
# data source
type = mysql
sql_host = xxxxxx
sql_user = xxxxxx #replace with your db username
sql_pass = xxxxxx #replace with your db password
sql_db = xxxxxx #replace with your db name
# these two are optional
sql_port = xxxxxx
#sql_sock = /var/lib/mysql/mysql.sock
# pre-query, executed before the main fetch query
sql_query_pre = SET NAMES utf8
# main document fetch query
sql_query = SELECT q.id AS id, q.title AS title, q.tagnames AS tags, q.html AS text, q.level AS level \
FROM question AS q \
WHERE q.deleted=0 \
# optional - used by command-line search utility to display document information
sql_query_info = SELECT title, id, level FROM question WHERE id=$id
sql_attr_uint = level
}
index questions {
# which document source to index
source = src_questions
# this is path and index file name without extension
# you may need to change this path or create this folder
path = /home/rafal/index/index_questions
# docinfo (ie. per-document attribute values) storage strategy
docinfo = extern
# morphology
morphology = stem_en
# stopwords file
#stopwords = /var/data/sphinx/stopwords.txt
# minimum word length
min_word_len = 3
# uncomment next 2 lines to allow wildcard (*) searches
min_infix_len = 1
enable_star = 1
# charset encoding type
charset_type = utf-8
}
# indexer settings
indexer
{
# memory limit (default is 32M)
mem_limit = 64M
}
# searchd settings
searchd
{
# IP address on which search daemon will bind and accept
# optional, default is to listen on all addresses,
# ie. address = 0.0.0.0
address = 127.0.0.1
# port on which search daemon will listen
port = 3312
# searchd run info is logged here - create or change the folder
log = ../log/sphinx.log
# all the search queries are logged here
query_log = ../log/query.log
# client read timeout, seconds
read_timeout = 5
# maximum amount of children to fork
max_children = 30
# a file which will contain searchd process ID
pid_file = searchd.pid
# maximum amount of matches this daemon would ever retrieve
# from each index and serve to client
max_matches = 1000
}
and heres my search part from views.py:
content = Question.search.query(keywords)
if level:
content = content.filter(level=level)#level is array of integers
There are no errors in any logs, it just isnt returning any results. I have set 'indexer --rotate --all' to be run every 5 mins in cron, and searchd is up and running all time.
All help would be most appreciated.
What's the version of sphinx? django-sphinx? sphinxsearch api? python?
Anyway, try to remove the indexer from the cron & see if this problem persists. Let me know how this goes.