简体   繁体   English

mysql全文搜索混乱

[英]Confusion on mysql full text search

I m having little confusion using MySQL fulltext. 我在使用MySQL全文时有点困惑。 I have database whose charset is set to utf-8 and collation set to utf8_unicode_ci 我的数据库的字符集设置为utf-8 ,排序规则设置为utf8_unicode_ci

I have following flow of searching products. 我有以下搜索产品的流程。 User chooses from the flow below to search any product 用户从以下流程中选择以搜索任何产品

  • user selects product_type, enum field with value consumable/unconsumable. 用户选择product_type,枚举字段,其值可消耗/不可消耗。
  • Then selects product_nature, enum 0=>finished 1- unfinished. 然后选择product_nature,枚举0 =>完成1-未完成。
  • then user selects location, varchar User may select multiple location. 然后用户选择位置,varchar用户可以选择多个位置。
  • then user specifies price ranges and so on (about 5 more selection) In search page the only thing users types is, location, price ranges. 然后用户指定价格范围,以此类推(大约还有5个选择)。在搜索页面中,用户唯一输入的信息是位置,价格范围。 Rest all they select from combo. 休息所有他们从组合选择。

My confusion is. 我的困惑是。

  1. Does my database supports FULL Text Search? 我的数据库是否支持全文搜索?
  2. What are the fields I need to index for enabling full text search. 我需要索引哪些字段以启用全文本搜索。
  3. As full text is supported in varchar and text datatype field only. 由于全文仅在varchartext数据类型字段中受支持。 How to get relevant results if many fields user selects for filter is in enum 如何获得相关的结果,如果许多领域用户选择的过滤器是在enum
  4. I want to show exact match at top and nearly matching products depending upon the filters user selects like I described above. 我想显示出完全匹配的产品,而最接近匹配的产品则取决于用户选择的过滤器,如我上述。 Does order by fulltext relevancy work here because there are many fields which are of type enum . 在这里按全文相关性排序是否起作用,因为存在许多enum类型的字段。

Edit For better understand for example 编辑例如以更好地理解

This search is for those specially who knows what to buy but doesn't know anything else. 此搜索针对的是那些特别知道什么东西但不知道其他东西的人。 Like I need a Mobile PHone, but I don't know anything else, I just select its type(Wifi/without wifi) from combo, I then select camera (with/without), I then select other few features like this. 就像我需要移动电话一样,但是我什么都不知道,我只是从组合中选择其类型(Wifi /不带wifi),然后选择相机(带/不带),然后选择其他一些功能。 I then specify price range I can afford, I then want phone available in store in particular location. 然后,我指定我可以负担的价格范围,然后在特定位置的商店中购买手机。 For this I type location A, location B, location C . 为此,我输入location A, location B, location C I want results based on either of these location. 我想要基于这些位置的结果。 And I want to order results according to the nearest match of the search parameter specified. 我想根据指定的搜索参数的最接近顺序对结果进行排序。 Exact match to nearest match, then least nearest match. 精确匹配到最接近的匹配,然后是最不匹配的匹配。 Hope this helps 希望这可以帮助

Can anybody throw some light on this? 有人可以对此有所启发吗?

Thanks 谢谢

  1. The documentation on the Full-Text Search Functions page states that FULLTEXT can only be used with MyISAM, however , MySQL 5.6 added support for the FULLTEXT index with InnoDB (see Section 14.2.4.12.3 on the InnoDB Table and Index page). Full-Text Search Functions页面上的文档指出, FULLTEXT只能与MyISAM一起使用, 但是 ,MySQL 5.6通过InnoDB添加了对FULLTEXT索引的支持(​​请参见InnoDB Table and Index页面上的Section 14.2.4.12.3 )。 If your table(s) are setup as MyISAM, then yes - you should have support; 如果您的表设置为MyISAM,则可以-您应该有支持; with InnoDB, potentially - pending on your MySQL version. 可能与InnoDB配合使用-取决于您的MySQL版本。

  2. To enable the full-text search, you should add a FULLTEXT index only on the fields that you're going to use the search on (no point to add it to fields you won't). 要启用全文本搜索,您应该仅在要使用搜索的字段上添加FULLTEXT索引(不要将其添加到不需要的字段中)。 A FULLTEXT index can only be applied to CHAR , VARCHAR , and TEXT column-types, so that may be a start. FULLTEXT索引只能应用于CHARVARCHARTEXT列类型,因此可能只是一个开始。 Your product names may be too short to worry about a FULLTEXT index (consider maybe a HASH index instead), but your product descriptions (if you have them) would be really good for it. 您的产品名称可能太短而不必担心FULLTEXT索引(可以考虑使用HASH索引),但是您的产品描述(如果有)非常适合。

  3. enum data is good to index with a BTREE index, not a FULLTEXT one. enum数据最好使用BTREE索引而不是FULLTEXT索引。

  4. Not sure; 不确定; could you post an example of which fields would be queried and ordered and their data-types to give a better image as to what you need? 您能否发布一个示例,说明将查询和排序哪些字段及其数据类型,以更好地了解您的需求?

  1. MySQL supports full-text on MyISAM table-types, and as of 5.6.x somewhere supports fulltext on InnoDB tables. MySQL支持MyISAM表类型的全文,从5.6.x版本开始,某些地方支持InnoDB表的全文。
  2. add fulltext indexes on any fields you want to do fulltext searching on. 在要进行全文搜索的任何字段上添加全文索引。 fulltext on int/binary/float fields makes no sense, so basically any varchar/text fields you need to do fulltext searches on int / binary / float字段上的全文没有意义,因此,基本上,您需要在其中进行全文搜索的所有varchar / text字段
  3. fulltext on an enum makes no sense, since enums are intended for exact matches only 枚举上的全文没有意义,因为枚举仅用于精确匹配
  4. you can order fulltext results by their internal relevance score . 您可以按其内部相关性得分对全文结果进行排序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM