0

我只是在寻找构建此代码以进行搜索查询的最佳方法。

假设我有一个必须搜索 6 列的搜索和一个查看 14 列的高级搜索。我正在考虑将其压缩以搜索大量的 1 列。

例如,假设我有类别“城市、价格、日期、类型、区域”,然后大约有 8 个“是”或“否”(或 1/0)列。我只是想知道哪种搜索会更好/更快。

SELECT * FROM table WHERE city=$city AND price BETWEEN ($price) AND other_searchables = [3-9][2-9]__1_1_110110_____1_1

使用此代码,自定义字段被放入一个字段并给出 0=no 或 1=yes 并且开始搜索以查看前 2 个数字是否等于 3+ 和 2+,然后 _ 是否为任何字符。因此,例如 other_searchables 字段看起来像“2300111011011100000101”

或者对每列使用 WHERE?

SELECT * FROM table WHERE city=$city AND price BETWEEN ($price) AND type = $types AND area = $areas AND customfield = 1 AND customfield = 0 AND customfield = 1 AND customfield = 1 AND customfield = 0 AND customfield = 1 AND customfield = 0 AND customfield = 1

我将索引城市,因为每次都会搜索它......只是寻找关于哪种方式去这里的任何建议,只要哪个查询会更好。

谢谢

4

0 回答 0