M
M
Mikhail Smirnov2021-01-29 14:47:03
Sphinx
Mikhail Smirnov, 2021-01-29 14:47:03

How to configure search without spaces in sphinx?

Search string: "DRM 06P"
There is such an entry in the database: 'Blah blah blah DRM 06 P'

if you search for "DRM 06 P", it finds it without problems, but users can enter an article with or without spaces into the search,
or as in the example in in one place there is a gap in the other there is not.

It turns out that you should search, for example, for such queries:
1. blah blah DRM 06 P
2. blah blah DRM 06P
3. blah blah DRM06P

source mainSourse
{
  type			= mysql
  sql_host		= localhost
  sql_user		= root
  sql_pass		=
  sql_db		= test
  sql_port		= 3306	# optional, default is 3306
  sql_query_pre	= SET NAMES utf8
}

source testSearch : mainSourse
{

  sql_query= SELECT bt_search_tags.ID as id, bt_search_tags.content AS content FROM bt_search_tags;
  
  #type of group fields
  #sql_field_string = id
  sql_field_string = content
}

index content
{
  source = testSearch
  path	 = C:/sphinx/data/testSearch/testSearch
  morphology = stem_en, stem_ru, soundex
  min_word_len = 1
  
  charset_type   = utf-8
    charset_table  = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F, U+401->U+451, U+451
    blend_chars    = &, ., +, U+23
    min_infix_len  = 2
    enable_star    = 1
    index_exact_words = 1
    html_strip     = 1
wordforms = C:/sphinx/data/wordforms.txt
}


$sth = $pdo->prepare("SELECT id, content, WEIGHT() as w FROM content WHERE MATCH('@content {$q}') LIMIT 1000 OPTION ranker = expr('sum(4*lcs+100/(min_hit_pos)+bm25)')");
    $sth->execute(array('21'));
    $array = $sth->fetchAll(PDO::FETCH_ASSOC);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2021-01-30
@opium

Apparently it is necessary to make min infixes postfixes up to 1 in this case

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question