非整数主键需要 sphinx 配置

san*_*uda 5 sphinx

我想sphinx为以下表结构创建搜索:

CREATE TABLE IF NOT EXISTS `books` (
  `productID` varchar(20) NOT NULL,
  `productName` varchar(256) NOT NULL,
  `ISBN` varchar(20) NOT NULL,
  `author` varchar(256) DEFAULT NULL,
  `productPrice` float(10,2) NOT NULL,
  `discount` float(10,2) NOT NULL,
  `brandID` int(11) NOT NULL,
  `qty` int(11) NOT NULL,
  `status` tinyint(1) NOT NULL,
  PRIMARY KEY (`productID`),
  KEY `status` (`status`),
  KEY `ISBN` (`ISBN`),
  KEY `author` (`author`),
  KEY `brandID` (`brandID`),
  KEY `books_index` (`productName`)
) ENGINE=innodb DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)

我无法更改productID上表中的列..

我有依赖的表authorBrands

CREATE TABLE IF NOT EXISTS `authors` (
      `authorID` ini(11) NOT NULL,
      `author_name` varchar(256) NOT NULL
      PRIMARY KEY (`authorID`)
    ) ENGINE=innodb DEFAULT CHARSET=latin1;


CREATE TABLE IF NOT EXISTS `brands` (
      `brandID` ini(11) NOT NULL,
      `brandName` varchar(256) NOT NULL
      PRIMARY KEY (`brandID`)
    ) ENGINE=innodb DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)

请有人提供sphinx搜索配置。

我正在使用以下配置。

source src1
{
        type                    = mysql


        sql_query               = SELECT CRC32(productID) as productid,productID,productName,ISBN,brandID,author FROM sapna_ecom_products

        sql_attr_uint           = productID
        sql_field_string        = ISBN
        sql_field_string        = productName
        sql_field_string        = brandID
        sql_attr_multi         = uint brandID from field; SELECT brandID,brandName FROM sapna_ecom_brands
        sql_attr_multi         = uint author from field; SELECT authorID,author_name FROM sapna_ecom_authors

        sql_query_info          = SELECT productID,productName,ISBN,brandID,author  FROM sapna_ecom_products  WHERE CRC32(productID)=$id
}
Run Code Online (Sandbox Code Playgroud)

如果我搜索productName但不搜索author和,我会得到结果brand

我的目标是在用户通过productNameauthorbrand

请有人为我提供合适的配置..

谢谢..

bar*_*ter 3

一种方法是只生成一个整数密钥

sql_query = SELECT CRC32(productID) AS id,...
Run Code Online (Sandbox Code Playgroud)

因为您现在无法将其与真实的 ProductID 关联起来,所以您可以将 prodctID 存储在属性中,以便在查询结果中取回它。

您可能会与 CRC32 发生冲突,

快速查询以检查

CREATE TABLE test (id INT UNSIGNED NOT NULL PRIMARY KEY) SELECT CRC32(productID) FROM books;
Run Code Online (Sandbox Code Playgroud)

如果有效的话,你就可以出发了

如果没有,则必须使用更好的散列。也可以看看

http://greenash.net.au/thoughts/2010/03/generating-unique-integer-ids-from-strings-in-mysql/


或者

sql_query_pre = SET @id := 1;
sql_query = SELECT @id := @id + 1 AS id,...
Run Code Online (Sandbox Code Playgroud)