当然 - 这很容易解决。如果您只需要为 Sphinx 创建自己的 ID,并且不希望它们发生冲突,您可以在 sphinx.conf 中执行类似的操作(MySQL 的示例代码)
source products {
# Use a variable to store a throwaway ID value
sql_query_pre = SELECT @id := 0
# Keep incrementing the throwaway ID.
# "code" is present twice because Sphinx does not full-text index attributes
sql_query = SELECT @id := @id + 1, code AS code_attr, code, description FROM products
# Return the code so that your app will know which records were matched
# this will only work in Sphinx 0.9.10 and higher!
sql_attr_string = code_attr
}
唯一的问题是您仍然需要一种方法来了解您的搜索匹配了哪些记录。Sphinx 将返回 id(现在没有意义)以及您标记为“属性”的任何列。
Sphinx 0.9.10 及更高版本将能够将您的产品代码作为搜索结果的一部分返回给您,因为它支持字符串属性。
0.9.10 尚未正式发布,但看起来很棒。看起来Zawodny 正在 Craig's List 上运行它,所以我不会对依赖此功能感到太紧张。