I'm using Sphinx to provide a search webpage to a huge set of data, recently I upgraded Sphinx from v2.1.8 to v2.2.4
I had some troubles in config file, one of them is that 'enable_star' option has been removed, which affected the expected results in my search page, so if search for 'rea' it will not return 'real madrid' until I complete typing 'real', the same issue at words ends 'madrid'.
The expected results if I searched for 'mad' :
Real Madrid
Atlatico Madrid
Mad-Croc
Madila
mad bla
In my case I get 'Mad-Croc' and 'mad bla'.
Here is a part of my config file :
docinfo = extern
mlock = 0
morphology = stem_en
min_word_len = 1
expand_keywords = 1
dict = keywords
PHP Code :
$_sphinx = new SphinxClient();
$_sphinx->SetServer('............', '....');
$_sphinx->SetMatchMode(SPH_MATCH_ANY);
$_sphinx->SetFieldWeights(array('auther_name' => 50));
$_sphinx->SetArrayResult(true);
$_sphinx->SetSortMode(SPH_SORT_EXTENDED2, 'cat_priority DESC, #weight DESC');
//////////////////
$_result = $_sphinx->Query($searchTerm . '*');
could any body look for this.
You dont seem to have min_prefix_len setup on your index, suggest you add it.
Although not sure how your index would ever of worked, as min_prefix_len, would be required for enable_star=0 to have an effect.
That should allow expand_keywords to work its magic. At which poing suggest removing the * from the end of the query. Which would only affect the last word entered anyway, and * should autotmatically by added by expand_keywords setting anyway.
Related
Good time of day!
There is such config Sphinx
source txtcontent : ru_config
{
sql_query = SELECT `id` as `txt_id`, 1 as index_id, `type_id`,`content_type_id`, `title`, `annonce`, `content` FROM `TxtContent` WHERE `status` = 1 AND `content_type_id` != 14
sql_attr_uint = index_id
sql_attr_uint = type_id
}
The entire table is indexed, and is stored in one large search index.
When it comes to find what is in it then all works OK
But today the task was to search for categories
The categories described in the field and have a type_id of type int
How in php using SphinxAPI to perform such a search?
Standard search looks like this.
$sphinxClient = new SphinxClient();
$sphinxClient->SetServer("127.0.0.1", 3312 );
$sphinxClient->SetLimits( 0, 700,700 );
$sphinxClient->SetSortMode(SPH_SORT_RELEVANCE);
$sphinxClient->SetArrayResult( true );
$result = $sphinxClient->Query( $this->query, 'txtcontent provider item');
I tried to add
$sphinxClient->SetFilter('type_id','1');
To search only where type_id = 1 but it didn't help.
Actually how can I search for a specific category? option to find everything in php to let go of the result excess is not considered (otherwise, the search will then be saturada existing limit) how to do it "properly" via the API without placing each topic in a separate search index?
setFilter takes an Array of values. And they need to be numeric (type_id is a numeric attribute)
$sphinxClient->SetFilter('type_id',array(1));
The sphinxapi class actully uses assertions to detect invalid data like this, which I guess you have disabled (otherwise would of seen them!).
My current Sphinx configurations only returns results matching the whole words, but i would like sphinx to return search for parts of word too.
e.g.
if i search for word
block
it should return result containng all words whic contains word block and not just exat matches.
e.g.
blockbuster
megablockbuster
megablock
its simillar to using block in query
my current SPhinxQL query looks like this
SELECT id FROM disk_index1 WHERE MATCH('block') LIMIT 0,25 OPTION max_matches = 10000
i have tried answer from
ref: searching in a part of word with Sphinx
enable_star=1
but
its depreciated now.
i have even tried running query like this
SELECT id FROM disk_index1 WHERE MATCH('*block*') LIMIT 0,25 OPTION max_matches = 10000
but still it doesnt returns partial words matches
How can i enable partial word matches ? in SPhinxQL ?
Sphinx Server version: 2.2.9-id64-release (rel22-r5006)
on Cent Os 7 x 64
my current index configuration has
docinfo = extern
morphology = stem_en
enable_star = 1
You can use min_infix_len and min_prefix_len to achieve this:
Infix length setting enables wildcard searches with term patterns like
'start*', '*end', '*middle*', and so on. It also lets you disable too
short wildcards if those are too expensive to search for.
Read more on Sphinx Search current documentation.
I have the following PHP script and am using the sphinx search API. I want to search for a custom keyword but only in the title column of the MySQL database.
$s = new SphinxClient;
$s->setServer("localhost", 9312);
$s->setMatchMode(SPH_MATCH_EXTENDED);
$s->SetLimits(0, 10000);
$result = $s->Query("#(title) apple");
Unfortunately this returns nothing but when i use the following script:
$s = new SphinxClient;
$s->setServer("localhost", 9312);
$s->setMatchMode(SPH_MATCH_EXTENDED);
$s->SetLimits(0, 10000);
$result = $s->Query("apple");
I obtain the results, the problem is that the script searches in all columns.
What am I doing wrong?
I should also mention that on localhost (using XAMPP) it is working fine like in the first example.
One thing I do notice, you dont explicitly note which index going to search - so the Query() searches ALL indexes.
Persumably then on one server you have an index that doesnt contain #title.
... for maximum compatiblity (so it doesnt matter waht other indexes add to the server, should probably search a specific index...
$s->Query("#(title) apple",'my_index');
I am using the following code:
include('sphinxapi.php');
$search = "John"
$s = new SphinxClient;
$s->SetServer("localhost", 9312);
$s->SetMatchMode(SPH_MATCH_EXTENDED2);
$s->SetSortMode(SPH_SORT_EXTENDED, 'name ASC');
$nameindex = $s->Query("$search");
echo $nameindex['total_found'];
This returns a blank page however without the SetSortMode it works fine and returns the number of results. No matter what I set the SetSortMode to it does not work. Any ideas as to why this would be?
I am indexing one column called name
You can't sort by (normal) fields in Sphinx, only attributes, or fields marked with the sql_field_string setting (which creates an attribute of the same name). So you'll need to either add an attribute with the same column, or use sql_field_string - they're equivalent.
Also: I've removed the thinking-sphinx tag - you're not using Ruby, and thus not the Thinking Sphinx library.
I have a problem with Sphinx. I have configuration like this:
sql_query = \
SELECT id, product_title, product_inf, product_code, ptype_name, title, cat, value, car \
FROM Catalog_View;
sql_attr_uint = car
sql_attr_uint = cat
Catalog_View is a view which collect data from several tables. It works good and haven't got any problem. I created index with this configuration:
index src1
{
source = src1
path = /var/data/src1
docinfo = extern
mlock = 0
morphology = stem_en, stem_ru
min_word_len = 3
charset_type = sbcs
min_prefix_len = 0
min_infix_len = 3
enable_star = 1
}
And indexer done his job perfect. But when I'm looking for empty query (like this '') and setup two filters
$cl->SetFilter('cat',array(9));
$cl->SetFilter('car',array(2));
I loose a lot of matches. For example when I use SQL-query to Catalog_View I have 76 rows, and the same in Sphinx gives me only 11 rows. I can't figure out what am i doing wrong. Everything seems fine except filter.
Actually I have the same problem with filters when I'm looking for non-empty query.
I stumbled upon this one too. My solution was making document IDs unique. If you have duplicated document IDs the possible result can be the same. I suppose Sphinx would take only first unique document thrashing all duplicated data.