Sphinx Configuration to handle German Umlauts - php

I'm using this index configuration:
index humans
{
source = src_humans
path = /usr/local/sphinx/var/data/humans
charset_table = 0..9, A..Z->a..z, _, a..z, U+C4->U+E4, U+D6->U+F6, U+DC->U+FC, U+DF, U+E4, U+F6, U+FC
html_strip = 1
html_index_attrs = img=src,alt; a=href,title
morphology = libstemmer_de
min_infix_len = 3
stopwords = /tmp/stopwords_de.txt
}
My indexer runs through:
Sphinx 2.3.1-id64-beta (r4926)
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/usr/local/sphinx/etc/sphinx.conf'...
indexing index 'humans'...
WARNING: index 'humans': dict=keywords and prefixes and morphology enabled, forcing index_exact_words=1
WARNING: Attribute count is 0: switching to none docinfo
collected 2 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 2 docs, 989 bytes
total 0.043 sec, 22888 bytes/sec, 46.28 docs/sec
total 3 reads, 0.000 sec, 2.0 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 1.9 kb/call avg, 0.0 msec/call avg
rotating indices: successfully sent SIGHUP to searchd (pid=8908).
When I search with $sc->Query('*gef*') I get a found document with "Gefährlich" in its description, but not when I search with $sc->Query('*gefä*').
What do I do wrong?
My whole MySQL-DB and every single file belonging to the project is UTF-8 encoded.
Thanks in advance!

I fixed this behavior with
sql_query_pre = SET NAMES utf8.

When I used Sphinx, I had in my searchd config something like
collation_server = utf8_general_ci
And in my index config:
charset_type = utf-8
I hope, it can help you

Related

No enabled local indexes to search

I'm trying to set up my Sphinx3 search, I'm using the minimal default config file from
the distribution.
source src
{
type = mysql
sql_host = localhost
sql_user = a0239779_a*
sql_pass = r*
sql_db = a0239779_r*
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
FROM documents
sql_attr_uint = id
sql_attr_timestamp = date_added
}
index test1
{
source = src
path = /home/a0239779/sphinx/data/test1
}
index testrt
{
type = rt
rt_mem_limit = 128M
path = /home/a0239779/sphinx/data/testrt
rt_field = title
rt_field = content
rt_attr_uint = gid
}
indexer
{
mem_limit = 128M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = /home/a0239779/sphinx/log/searchd.log
query_log = /home/a0239779/sphinx/log/query.log
read_timeout = 5
max_children = 30
pid_file = /home/a0239779/sphinx/log/searchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = /home/a0239779/sphinx/data
}
I did the indexing, it seems allrght
[a0239779#jarl bin]$ indexer -c /home/a0239779/sphinx/etc/sphinx.conf --all
Sphinx 2.1.5-id64-release (rel21-r4508)
Copyright (c) 2001-2014, Andrew Aksyonoff
Copyright (c) 2008-2014, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/home/a0239779/sphinx/etc/sphinx.conf'...
indexing index 'test1'...
WARNING: attribute 'id' not found - IGNORING
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 227 bytes
total 0.013 sec, 17048 bytes/sec, 300.41 docs/sec
skipping non-plain index 'testrt'...
total 3 reads, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
total 10 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
I made a start of the search, it seems allrght
[a0239779#jarl bin]$ ./sphinx.sh start
Sphinx 3.1.1 (commit 612d99f)
Copyright (c) 2001-2018, Andrew Aksyonoff
Copyright (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/home/a0239779/sphinx/etc/sphinx.conf'...
listening on all interfaces, port=9312
listening on all interfaces, port=9306
precaching index 'test1'
WARNING: index 'test1': prealloc: /home/a0239779/sphinx/data/test1.sph is
v.38 (from Sphinx 2.x), binary is v.48; NOT SERVING
precaching index 'testrt'
precached 2 indexes in 0.001 sec
I checked the work of the search through the command, allrght
[a0239779#jarl bin\]$ search --config /home/a0239779/sphinx/etc/sphinx.conf 'another'
Sphinx 2.1.5-id64-release (rel21-r4508)
Copyright (c) 2001-2014, Andrew Aksyonoff
Copyright (c) 2008-2014, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/home/a0239779/sphinx/etc/sphinx.conf'...
index 'test1': query 'another ': returned 1 matches of 1 total in 0.000 sec
displaying matches:
1. document=3, weight=2769, date_added=Sun Oct 11 19:25:17 2020
words:
1. 'another': 1 documents, 2 hits
index 'testrt': search error: failed to open /home/a0239779/sphinx/data/testrt.sph:
No such file or directory.
Then I want to test direct SQL queries
mysql -h127.0.0.1 -P9306
mysql> SELECT * FROM test1 WHERE MATCH('another');
ERROR 1064 (42000): no enabled local indexes to search
Why is that?
Also I do show all tables
mysql> SHOW TABLES;
+--------+------+
| index | type |
+--------+------+
| testrt | rt |
+--------+------+
1 row in set (0.00 sec)
Why only 1 table? Where is my table "test1"
I am trying to test it via PHP
$db = new PDO("mysql:host=127.0.0.1; port=9306; dbname=a0239779_r--; charset=utf8;",
"a0239779_a--", "a0239779_r--");
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$stmt = $db->query("SELECT * FROM `test1` WHERE MATCH('another')");
$results = $stmt->fetchAll();
var_dump($results);
Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 no enabled
local indexes to search
Should there be an index table test1 for SQL queries?
How can I use the RT table for SQL queries?
The indexer did not create indexes because the old version 2.1.5 was launched when the command to index without absolute paths to the executable file and config
search --config /home/a0239779/sphinx/etc/sphinx.conf 'another'
Sphinx 2.1.5-id64-release (rel21-r4508)

Can we change the return output of sqlldr command

Am using
$command = "sqlldr userid=abc/abc_def#defghijk CONTROL= $controlFileName DATA=\"$csvFilePath\" LOG=$logFile1 BAD=$logFile2";
exec($command,$output,$returnValue);
And got the output :
SQL*Loader: Release 11.2.0.1.0 - Production on Wed Feb 19 15:53:58 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Load completed - logical record count 196.
Instead of this output, is it possible to get the below part of result from log file into PHP :
Table table_name:
195 Rows successfully loaded.
1 Row not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Partition SYS_P42102: 195 Rows loaded.
Bind array size not used in direct path.
Column array rows : 5000
Stream buffer bytes: 256000
Read buffer bytes: 1048576
Total logical records skipped: 2
Total logical records read: 196
Total logical records rejected: 1
Total logical records discarded: 0
Total stream buffers loaded by SQL*Loader main thread: 2
Total stream buffers loaded by SQL*Loader load thread: 0
i.e, i want to return value from sqlldr command that how many rows was read and how many rejected and how many inserted?
thanks.

Sphinx returns digits instead of string in matches array

I made a sphinx configuration with 10 fields.
Some of the fields are string, so I defined it in source part of configuration like this:
sql_attr_uint = section_id
sql_field_string = name
sql_field_string = element_code
sql_field_string = section_code
All indexed whell:
collected 18334 docs, 2.5 MB
sorted 18.9 Mhits, 100.0% done
total 18334 docs, 2460468 bytes
total 13.065 sec, 188322 bytes/sec, 1403.26 docs/sec
total 44 reads, 0.112 sec, 3255.7 kb/call avg, 2.5 msec/call avg
total 366 writes, 0.386 sec, 735.4 kb/call avg, 1.0 msec/call avg
rotating indices: successfully sent SIGHUP to searchd (pid=3131).
And when I'm trying to search some query exactly from the command line, everything works fine, I see text-values of the string-fields, which I defined before. But when I'm going to sphinxapi and make the same search query it returns the same result, but instead of string-values I see digits, which changing with every query:
[96659] => Array
(
[weight] => 1
[attrs] => Array
(
[name] => 140436931107525
[element_code] => 140436931107617
[section_id] => 4016
[section_code] => 140436931107680
)
)
Please anybody, what it means? I need string-values, I don't want to make additional sql-queries to DB.
It sounds like your sphinxapi.php file is too old. Use the one from the version of sphinx you have installed.

Using Sphinx with PHP. Error with the "search" : "Search error: ."

I'm testing Sphinx with PHP (tutorial : http://www.siteduzero.com/informatique/tutoriels/creer-un-moteur-de-recherche-avec-sphinx-et-php)
If I run "search" like this :
search -i news navigateur
I have the following error :
index 'news': search error: .
The indexer works fine :
$ sudo indexer news
Sphinx 2.0.6-release (r3473) Copyright (c)
2001-2012, Andrew Aksyonoff Copyright (c) 2008-2012, Sphinx
Technologies Inc (http://sphinxsearch.com)
using config file '/usr/share/php/sphinx/etc/sphinx.conf'...
indexing index 'news'...
collected 57 docs, 0.7 MB sorted 0.1 Mhits, 100.0%
done total 57 docs, 689264 bytes total 0.050 sec, 13684561 bytes/sec,
1131.67 docs/sec
total 3 reads, 0.000 sec, 115.5 kb/call avg, 0.1 msec/call avg
total 9 writes, 0.000 sec, 83.5 kb/call avg, 0.0 msec/call avg
And, testing with the API, the PHP code return nothing. Anybody already have this error ?
Here the config file :
index news {
source = news
path = /usr/share/php/sphinx/var/data/news
}
indexer {
mem_limit = 32M
}
searchd {
port = 3312
log = /usr/share/php/sphinx/var/log/searchd/searchd.log
query_log = /usr/share/php/sphinx/var/log/searchd/query.log
pid_file = /usr/share/php/sphinx/var/log/searchd/searchd.pid
}
source news {
type = mysql
sql_host = localhost
sql_user = root
sql_pass =
sql_db = siteduzero_sphinx
sql_query_pre = SET NAMES utf8
sql_query = SELECT id\
, categorie\
, titre\
, contenu FROM news
sql_attr_uint = categorie
sql_query_info = SELECT titre FROM news WHERE id=$id }
Thanks.
Fabrice
Just ran into the same problem. The root of evil in the last config parameter. This command will work correctly:
search -i news --noinfo navigateur
Or you can remove this string from config:
sql_query_info = SELECT titre FROM news WHERE id=$id
If you don't need it.
It's a bug in the search utility.
The good news is the search utility, is just a testing tool, so its not critical. Its not actually used for anything other than testing.
As for your problem with the API, do you have the searchd daemon running?
Rather than just saying it returns 'nothing', you should use getLastError and getLastWarning to investigate why...

Sphinx_Query failed: no enabled local indexes to search

Hi I configured sphinx search in my test server.
Now I am getting this kind of an error "Sphinx_Query failed: no enabled local indexes to search".
I am not getting why this error. Any body can help me plese.
This is my sphinx conf
source objectcollection
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = root
sql_db = mydatabase
sql_port = 3306
sql_query = \
SELECT id, id as mid obtype_id, searchtext from tab_objectcollection;
sql_attr_uint = mid
sql_attr_uint = obtype_id
sql_query_info = SELECT * FROM tab_objectcollection WHERE id=$id
}
index combinedobject
{
source = objectcollection
path = /usr/local/sphinx/var/data/objectcollection
morphology = stem_en
min_stemming_len = 4
stopwords = /usr/local/sphinx/var/data/stopwords.txt
min_word_len = 3
min_prefix_len = 3
min_infix_len = 0
enable_star = 1
phrase_boundary = ., ?, !, U+2026 # horizontal ellipsis
phrase_boundary_step = 100
html_strip = 1
}
indexer
{
# memory limit, in bytes, kiloytes (16384K) or megabytes (256M)
# optional, default is 32M, max is 2047M, recommended is 256M to 1024M
mem_limit = 256M
# maximum xmlpipe2 field length, bytes
# optional, default is 2M
#
max_xmlpipe2_field = 16M
# write buffer size, bytes
# several (currently up to 4) buffers will be allocated
# write buffers are allocated in addition to mem_limit
# optional, default is 1M
#
#write_buffer = 16M
}
searchd
{
listen = 3312
max_matches = 10000
log = /usr/local/sphinx/var/log/searchd.log
query_log = /usr/local/sphinx/var/log/query.log
pid_file = /usr/local/sphinx/var/log/searchd.pid
}
Thanks
Have you
Actully built the index - ie called 'indexer' program, to make the index files.
Started the Search Daemon - searchd
I think this error means that sphinx can't find the file(s) specified by "path" in your index. In my case I had:
path = /var/lib/sphinxsearch/data/delta
And I had ran the indexer successfully (or so I thought) like this:
indexer delta --rotate
It said there were some documents collected. HOWEVER it actually created these files:
/var/lib/sphinxsearch/data/delta.new.sp?
And searchd failed to rotate the files. Thus spake the log:
WARNING: rotating index 'delta': rename '/var/lib/sphinxsearch/data/delta.mvp' to '/var/lib/sphinxsearch/data/delta.old.mvp' failed: No such file or directory
The solution was: delete those new files and run indexer without --rotate the first time.
The fact that --rotate doesn't work the first time seems like a bit of a bug to me, but I can't really be bothered to submit a bug report. It probably requires me to register or some nonsense. Anyway, hope this helps.
What I Understand by your question is, in the configuration file you have to mention which table or data is to be Indexed into it. Also there could be a problem with Sphinx daemon, that it is not able to create the Indexed data and write it into files. Do check with the above.
Hope to be of help somehow.
This seems to be an issue with sphinx 2.0.5, it's filed here:
http://sphinxsearch.com/bugs/view.php?id=1268
Try using a different version (I tried 2.0.6 and the problem is gone)

Categories