需要为非整数主键配置 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;
我无法更改上表中的 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
搜索,但不是 author
和 brand
搜索,我会
得到结果 我的目标是,如果用户通过 搜索任何内容, 我都会得到结果>productName
或 author
或 brand
请有人为我提供合适的配置..
谢谢..
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是仅生成一个整数键,
因为您现在无法将其与真实的 ProductID 关联起来,您可以将 prodctID 存储在属性中,以便在查询结果中取回它。
您可能会与 CRC32 发生冲突,
可以快速查询以检查
是否有效,那么您就可以继续操作,
如果不能,则必须使用更好的散列。另请参阅
http:// greenash.net.au/thoughts/2010/03/generating-unique-integer-ids-from-strings-in-mysql/
或者
One way would be to just generate a integer key
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
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