简体   繁体   English

PHP MYSQLI搜索查询,使用数组作为参考

[英]PHP MYSQLI Search query using array as reference

I know my logic here is going to be atrocious so bear with me. 我知道我的逻辑会很残酷,所以请耐心等待。 In essence, when a user fills out a form consisting of 3 entry boxes(representing 3 different columns in the database), I want to execute a search that takes keywords from the filled boxes and looks for all other user profiles (constituting of a first name, experience, dreams and profile picture) within the database table containing at least X% of the keywords from the initial user's input boxes. 本质上,当用户填写由3个输入框组成的表单(代表数据库中3个不同的列)时,我想执行一个搜索,该搜索从填充的框中获取关键字并查找所有其他用户个人资料(由第一个用户构成)名称,经历,梦想和个人资料图片),该数据库表至少包含来自初始用户输入框的X%的关键字。

I've decided to represent the keywords in an array since that is what I am most familar with in terms of element organization. 我决定在数组中表示关键字,因为这是我最熟悉的元素组织方式。 Using this array as a reference, the search will scan the users table for any users whose profile information contain X% of the keywords in the reference array. 使用此数组作为参考,搜索将扫描users表中的配置文件信息包含参考数组中X%关键字的所有用户。

The array has already been prepared, but now I need guidance as to whether or not the manner in which I want to finish the task is appropriate/valid. 阵列已经准备好了,但是现在我需要有关完成任务的方式是否适当/有效的指导。

EDIT 1: Forgive me if I am unclear, let me try a more disjointed way of portraying the task. 编辑1:如果我不清楚,请原谅我,让我尝试以更分离的方式描述任务。

  1. User fills out 3 unique textarea boxes. 用户填写3个唯一的textarea框。
  2. User saves inputted data, in which that data is stored in database ( users table to be specific) 用户保存输入的数据,该数据存储在数据库中(特定于users表)
  3. User goes to "Find Others" page 用户转到“查找其他人”页面
  4. User clicks on "Find" button 用户点击“查找”按钮
  5. Query takes user information of the 3 textareas, filters them individually, then compresses them into a single array of keywords. 查询获取3个文本区域的用户信息,分别对其进行过滤,然后将其压缩为单个关键字数组。

    1. Another query will search the entire database and display the profiles of other users whose profiles contain X% of words that match the keywords in the array. 另一个查询将搜索整个数据库,并显示其他用户的配置文件,这些用户的配置文件包含与数组中的关键字匹配的X%的单词。
    2. User sees the profiles of other users with similar words within the information of their profiles. 用户可以在其他用户的个人资料信息中看到具有相似单词的其他用户的个人资料。

The array that will contain the keywords: 包含关键字的数组:

$compressed_array = array_merge($filtered1, $filtered2, $filtered3);

You may want to try a slightly different approach. 您可能想尝试一种稍微不同的方法。
When a user creates their entries, find the keywords and in a matching table store the relation of keywords to users. 用户创建条目时,找到关键字,然后在匹配表中存储关键字与用户的关系。
This way, you can query the matching table, which should me much faster and easier to query. 这样,您可以查询匹配表,查询该表应该更快,更容易。
Or you use a full-scale search platform, like Solr , which does more or less the same. 或者,您可以使用像Solr这样的全面搜索平台,该平台大致相同。

Any attempt to search your users table in real time will have huge performance problems as soon as you are handling a substantial amount of records. 一旦您要处理大量记录,任何实时搜索用户表的尝试都会带来巨大的性能问题。

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

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