1

我在不返回任何结果的新表上有一个新索引。这很奇怪,我以前从未遇到过这个问题。其他索引(构建几乎相同)可以通过搜索 CLI 和我的 API 进行搜索。

这是我的conf文件

source topicalindex
{
  type            = pgsql
  sql_host        = localhost
  sql_user        = user
  sql_pass        = password
  sql_db          = db
  sql_port        = 5432  # optional, default is 3306
  sql_query       = SELECT id, topic, reference, start_ref, end_ref, see_also_html FROM my_topicalindex
  sql_attr_uint   = topic
  sql_attr_uint   = reference
}


index topicalindex_index
{
  source          = topicalindex
  path            = /path/to/data/topical_index
  docinfo         = extern
  charset_type    = utf-8
}

indexer
{
  mem_limit       = 32M
}

searchd
{
  listen          = 3312
  log             = /path/to/searchd.log
  query_log       = /path/to/query.log
  read_timeout    = 5
  max_children    = 30
  pid_file        = /usr/local/var/searchd.pid
  max_matches     = 30000
  seamless_rotate = 1
  preopen_indexes = 0
  unlink_old      = 1
}

这是证明数据库中有内容的摘录

[myself]:myapp(master)$ psql -d mydb -h localhost
psql (9.2.2)
Type "help" for help.

esv=# SELECT * FROM my_topicalindex LIMIT 1;
  id  |  topic  |     reference      | start_ref | end_ref | see_also_html 
------+---------+--------------------+-----------+---------+---------------
 2810 | Abraham | Genesis chs. 11–25 |   1011001 | 1025034 | blank
(1 row)

下面是索引过程:

$ indexer --rotate --all --config /path/to/sphinx-topical.conf
Sphinx 0.9.9-rc2 (r1785)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file '/path/to/sphinx-topical.conf'...
indexing index 'topicalindex_index'...
collected 2809 docs, 0.1 MB
sorted 0.0 Mhits, 100.0% done
total 2809 docs, 75007 bytes
total 0.067 sec, 1117456 bytes/sec, 41848.54 docs/sec
total 3 reads, 0.000 sec, 47.0 kb/call avg, 0.0 msec/call avg
total 7 writes, 0.000 sec, 37.0 kb/call avg, 0.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=79833).

以及显示它们有内容的文件

[myself]:myapp(master)$ ll /path/to/data/
total 160
drwxr-xr-x 10 myself admin   340 Aug 29 08:56 ./
drwxr-xr-x  3 myself admin   102 Jun  1  2012 ../
-rw-r--r--  1 myself admin 33708 Aug 29 08:56 topical_index.spa
-rw-r--r--  1 myself admin 51538 Aug 29 08:56 topical_index.spd
-rw-r--r--  1 myself admin   326 Aug 29 08:56 topical_index.sph
-rw-r--r--  1 myself admin 15721 Aug 29 08:56 topical_index.spi
-rw-r--r--  1 myself admin     0 Aug 29 08:56 topical_index.spk
-rw-------  1 myself admin     0 Aug 29 08:56 topical_index.spl
-rw-r--r--  1 myself admin     0 Aug 29 08:56 topical_index.spm
-rw-r--r--  1 myself admin 52490 Aug 29 08:56 topical_index.spp

然后——我的搜索结果为 0

[myself]:myapp(master)$ search -i topicalindex_index -a "Abraham"
Sphinx 0.9.9-rc2 (r1785)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file '/usr/local/etc/sphinx.conf'...
index 'topicalindex_index': query 'Abraham ': returned 0 matches of 0 total in 0.000 sec

words:
1. 'abraham': 0 documents, 0 hits

为什么我在搜索“Abraham”时得到 0 个结果。(奇怪的是,我在搜索“a”时确实得到了结果)
这是我的 conf 文件的问题吗?是别的吗?

编辑 我注意到,在搜​​索“a”时,它只搜索那些确实包含 see_also_html 字段内容的行。匹配数与每列具有数据的字段数相匹配。

4

2 回答 2

1
 sql_query       = SELECT id, topic, reference, start_ref, end_ref, see_also_html FROM my_topicalindex
 sql_attr_uint   = topic
 sql_attr_uint   = reference

  id  |  topic  |     reference      | start_ref | end_ref | see_also_html 
------+---------+--------------------+-----------+---------+---------------
 2810 | Abraham | Genesis chs. 11–25 |   1011001 | 1025034 | blank

您已经制作了topicreference整数属性。(因此它们不会作为全文字段包含在内)

没有成为属性的列(不包括第一列!)自动成为字段。

所以start_ref,end_refsee_also_html将是全文字段,因此是可搜索的。

于 2013-08-29T15:06:52.217 回答
0

题外话

注意:为了提高文件的可读性,您可以替换

sql_query       = SELECT id, topic, reference, start_ref, end_ref, see_also_html FROM my_topicalindex

经过

sql_query       = SELECT id,             \
                         topic,          \
                         reference,      \
                         start_ref,      \
                         end_ref,        \
                         see_also_html   \
                    FROM my_topicalindex

请注意 \ 将是最后一个字符(不是空格)

我很乐意使用此符号的语句示例

sql_query        =                                                                              \
    SELECT        /* sphinx index article Video  */                                             \
    `article`.id                                    AS id,                                      \
    UNIX_TIMESTAMP(`article`.fromDate)              AS ressource_date,                          \
    unix_timestamp(now())                           AS indexing_date,                           \
    `programs`.id                                   AS emission_id,                             \
    IFnull(cat.parent_id, cat.id)                   AS genre_id,                                \
    `article`.`title`                               AS `title_str`,                             \
    `article`.`title`                               AS `title`,                                 \
    `article`.`feed`                                AS `feed_ordinal`,                          \
    `article`.`feed`                                AS `feed`,                                  \
    `article`.`category`                            AS `category`,                              \
    `article`.`dossierId`                           AS `dossierId`,                             \
    `article`.`mainImage`                           AS `mainImage`,                             \
    group_concat(`keywords`.`translation`)          AS `tags`,                                  \
    group_concat(o.id)                              AS `video_id_list`,                         \
    concat(' summary:',                                                                         \
            `article`.summary,                                                                  \
            ' synopsis',                                                                        \
            `article`.synopsis,                                                                 \
            ' Summary Title :',                                                                 \
            `article`.summaryTitle,                                                             \
            ' Url',                                                                             \
            `article`.title_url,                                                                \
            ' Main',                                                                            \
            `article`.mainParagraph)                AS content,                                 \
    concat( ' Signature:',                                                                      \
            `article`.signature)                    AS subcontent,                              \
    UNIX_TIMESTAMP(article.fromDate)                AS online_from_date,                        \
    if ( UNIX_TIMESTAMP(article.toDate)<2000000000,                                             \
         UNIX_TIMESTAMP(article.toDate),                                                        \
         2000000000)                                AS online_to_date                           \
FROM                                                                                            \
    `article`.`article`                                                                         \
LEFT JOIN                                                                                       \
    `media`.`programs`                                                                          \
ON                                                                                              \
    `article`.`category` = `programs`.`articleReferenceCategory`                                \
LEFT JOIN                                                                                       \
    `media`.`category` AS cat                                                                   \
ON `programs`.mainCategoryId = cat.id                                                           \
LEFT JOIN                                                                                       \
    article.article_keyword                         AS ak                                       \
ON                                                                                              \
    ak.articleId = article.id                                                                   \
LEFT JOIN                                                                                       \
    article.keyword                                 AS keywords                                 \
ON                                                                                              \
    ak.keywordId = keywords.id                                                                  \
AND `keywords`.`visible`   = 1                                                                  \
AND `keywords`.`translation` !=''                                                               \
LEFT JOIN                                                                                       \
        article.embed                                          AS ae                            \
ON                                                                                              \
    ae.articleId = article.id                                                                   \
INNER JOIN                                                                                      \
    media.`objects`                                        AS o                                 \
ON                                                                                              \
    o.id = SUBSTRING_INDEX( SUBSTRING(ae.code, 5+LOCATE('rel="',ae.code)), '"', 1)              \
    AND  o.type='video'                                                                         \
    AND o.status='complete'                                                                   \
      AND o.active=1                                                                            \
      AND ( o.part_type IS NULL OR o.part_type = 'extract')                                     \
      AND o.wildcard not like 'www.%.be/presse%'                                             \
                                                                                                \
WHERE                                                                                           \
    `article`.`validated` = 1                                                                   \
AND `article`.`published` = 1                                                                   \
AND `article`.`deleted` = 0                                                                     \
AND `article`.`displayDate` < Now()                                                             \
AND `article`.`fromDate` < Now()                                                                \
AND `article`.`toDate` > Now()                                                                  \
AND `article`.id >= $start                                                                      \
AND `article`.id < $end                                                                         \
GROUP BY `article`.id
于 2013-08-29T17:53:09.087 回答