sphinx search:查询使用隐式AND而不返回结果

时间:2015-07-17 08:22:52

标签: sphinx

使用sphinx search v2.2.9,此查询返回特定记录:

((@(author) fstaed) | (@(authsurname) fstaed) | (@(authori) fstaed) )

此查询也会返回相同的记录:

(@(issued) 2007)

但是这个查询(我认为这是上述两个查询的隐含“AND”组合不会返回记录:

(@(issued) 2007) ((@(author) fstaed) | (@(authsurname) fstaed) | (@(authori) fstaed) ) 

为什么?

更新1:

我可以使用mysql命令行重现此问题,下面显示了运行上述3个测试中的每一个。请注意,id:187在两个单独的结果集中,但不在组合结果集中。

$ mysql -h0 -P9306
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 2.2.9-id64-release (rel22-r5006)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT id, weight() FROM `work` WHERE MATCH('(@(issued) 2007)') AND `sphinx_deleted` = 0 LIMIT 0, 1000 OPTION ranker=proximity_bm25
-> ;
+------+----------+
| id   | weight() |
+------+----------+
|  187 |     1604 |
|  200 |     1604 |
|  215 |     1604 |
..i cutoff these results as irrelevant.
+------+----------+
40 rows in set, 1 warning (0.01 sec)

mysql> SELECT id, weight() FROM `work` WHERE MATCH('((@(author) fstaed)  | (@(authsurname) fstaed)  | (@(authori) fstaed) )') AND `sphinx_deleted` = 0 LIMIT 0, 1000 OPTION ranker=proximity_bm25
-> ;
+------+----------+
| id   | weight() |
+------+----------+
|  187 |     1560 |
|  383 |     1560 |
+------+----------+
2 rows in set, 1 warning (0.01 sec)

mysql> SELECT id, weight() FROM `work` WHERE MATCH('(@(issued) 2007) ((@(author) fstaed)  | (@(authsurname) fstaed)  | (@(authori) fstaed) )') AND `sphinx_deleted` = 0 LIMIT 0, 1000 OPTION ranker=proximity_bm25
-> ;
Empty set, 1 warning (0.01 sec)

mysql> 

更新2:

我还应该提到“work”索引是包含“iresrevi1_core”和“iresrevi2_core”的多个索引之间的分布式索引。 iresrevi2_core索引中的“已发布”字段为空(iresrevi1_core索引中不为null),并且正在搜索的authori字段在相反索引iresrevi1_core中为空(在iresrevi2_core索引中不为null)。

我认为这可能与此有关?我可以确认,如果我直接查询2个索引,iresrevi1_core索引将返回已发布的搜索数据,但iresrevi2_core索引将不返回已发布的搜索数据。反之亦然,iresrevi2_core将返回作者搜索数据,但iresrevi1_core将不会。

我分发了多个索引,以便我可以使用“非中缀”方法索引我想要搜索的所有字段(强制“中缀”字段在此索引中为空)以及我想要的所有字段使用“中缀”方法的搜索位于另一个索引上,所有“非中缀”字段都被清空。 2个源/索引看起来像这样:

source srcresrevi1 : srcresrev
{
    sql_query       = \
    select SQL_NO_CACHE `work`.`ID` AS `ID`, '' as authori \
     from work \
     WHERE (`work`.`ID` BETWEEN $start AND $end) \
     and `work`.`ID` <= (select max_id from sphinx_deltas where id = 1)

sql_joined_field = authsurname from ranged-query; \
    SELECT SQL_NO_CACHE wa.work_id AS ID, s.surname \
    from `work_authors` wa, \
         `author_surnames` s \
    where wa.author_surname_id = s.id \
    and wa.work_id >= $start and wa.work_id <= $end \
    and `wa`.`work_ID` <= (select max_id from sphinx_deltas where id = 1) \
    order by wa.work_id ASC; \
    select min(work_id), max(work_id) from `work_authors` \
    where work_id <= (select max_id from sphinx_deltas where id = 1)

sql_joined_field = author from ranged-query; \
    SELECT SQL_NO_CACHE wa.work_id AS ID, CONCAT(f.given,' ',s.surname) \
    from `work_authors` wa, `author_surnames` s, `author_fnames` f \
    where wa.author_surname_id = s.id \
    and wa.author_fname_id = f.id \
    and wa.work_id >= $start and wa.work_id <= $end \
    and `wa`.`work_ID` <= (select max_id from sphinx_deltas where id = 1) \
    order by wa.work_id ASC; \
    select min(work_id), max(work_id) from `work_authors` \
    where work_id <= (select max_id from sphinx_deltas where id = 1)

sql_joined_field = issued from ranged-query; \
    SELECT SQL_NO_CACHE work_id AS ID, `year` \
    from issued \
    where work_id >= $start and work_id <= $end \
    and work_ID <= (select max_id from sphinx_deltas where id = 1) \
    order by work_id ASC; \
    select min(work_id), max(work_id) from `issued` \
    where work_id <= (select max_id from sphinx_deltas where id = 1)
}

source srcresrevi2 : srcresrev
{
    sql_query       = \
    select SQL_NO_CACHE `work`.`ID` AS `ID`, '' as authsurname, '' as author, '' as issued \
            from work \
            WHERE (`work`.`ID` BETWEEN $start AND $end) \
            and `work`.`ID` <= (select max_id from sphinx_deltas where id = 1)

sql_joined_field = authori from ranged-query; \
    SELECT SQL_NO_CACHE wa.work_id, CONCAT(f.given,' ',s.surname) \
    from `work_authors` wa, `author_surnames` s, `author_fnames` f \
    where wa.author_surname_id = s.id \
    and wa.author_fname_id = f.id \
    and work_id >= $start and work_id <= $end \
    and work_ID <= (select max_id from sphinx_deltas where id = 1) \
    order by wa.work_id ASC; \
    select min(work_id), max(work_id) from `work_authors` \
    where work_id <= (select max_id from sphinx_deltas where id = 1)
}

index iresrevi1_core
{
source          = srcresrevi1
path = /home/resrev/pubrevit/db/sphinx/development/iresrevi1
docinfo         = extern
dict            = keywords
mlock           = 0
morphology      = stem_en
charset_table = 0..9, A..Z->a..z, _, a..z, \
        U+410..U+42F->U+430..U+44F, U+430..U+44F
min_word_len        = 3
expand_keywords     = 0
ngram_len       = 1
ngram_chars     = U+3000..U+2FA1F
html_strip      = 1
html_remove_elements    = style, script, head, DOCTYPE, !DOCTYPE
inplace_enable      = 1
index_exact_words   = 0
index_sp        = 0
index_field_lengths = 1
}

index iresrevi2_core
{
source          = srcresrevi2
path = /home/resrev/pubrevit/db/sphinx/development/iresrevi2
docinfo         = extern
dict            = keywords
mlock           = 0
morphology      = stem_en
charset_table = 0..9, A..Z->a..z, _, a..z, \
        U+410..U+42F->U+430..U+44F, U+430..U+44F
min_word_len        = 3
min_infix_len       = 3
expand_keywords     = 1
ngram_len       = 1
ngram_chars     = U+3000..U+2FA1F
html_strip      = 1
html_remove_elements    = style, script, head, DOCTYPE, !DOCTYPE
inplace_enable      = 1
index_exact_words   = 0
index_sp        = 1
index_field_lengths = 1
}

1 个答案:

答案 0 :(得分:1)

所以是的,它是问题的多个不同的索引。 UNION没有加入。

除了你找到的主题之外,这里还有一个更新的主题,提到可能使用@@ relax来解决它。它可能会为分布式索引工作。

http://sphinxsearch.com/forum/view.html?id=13581