需要为非整数主键配置 sphinx

发布于 2024-12-08 10:14:32 字数 2181 浏览 0 评论 0原文

我想为以下表结构创建 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;

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

我有 author 的依赖关系表> 和 Brands

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;

请提供 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
}

如果我按 productName 搜索,但不是 authorbrand 搜索,我会

得到结果 我的目标是,如果用户通过 搜索任何内容, 我都会得到结果>productNameauthorbrand

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

谢谢..

i want to create sphinx search for following table structure:

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;

I can't alter the productID column in above table..

i have dependency tables for author and Brands

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;

please some one provide configuration for sphinx search.

i am using following config.

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
}

I am getting results if i search by productName but not for author and brand

My aim is to get the results if user search any by productName or author or brand

Please somebody provide me suitable configuration..

thanks..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呆° 2024-12-15 10:14:33

一种方法是仅生成一个整数键,

sql_query = SELECT CRC32(productID) AS id,...

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

您可能会与 CRC32 发生冲突,

可以快速查询以检查

CREATE TABLE test (id INT UNSIGNED NOT NULL PRIMARY KEY) SELECT CRC32(productID) FROM books;

是否有效,那么您就可以继续操作,

如果不能,则必须使用更好的散列。另请参阅

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,...

One way would be to just generate a integer key

sql_query = SELECT CRC32(productID) AS id,...

because you can't now relate that back to the real productID, you could store prodctID in a attribute so you get it back in query results.

Its possible you might get collisions with CRC32,

A quick query to check

CREATE TABLE test (id INT UNSIGNED NOT NULL PRIMARY KEY) SELECT CRC32(productID) FROM books;

If that works, you good to go,

if not, will have to use a better hashing. See also

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


Alternativly

sql_query_pre = SET @id := 1;
sql_query = SELECT @id := @id + 1 AS id,...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文