php中多对多字段的标签搜索
我正在尝试为简报系统做一个搜索引擎。
我正在使用多对多关系样式设置,其中 3 个数据库代表关系。
comms_briefings 是简报数据的存储位置 search_tags 是存储标签的位置 Briefings_tags 是建立关系的地方,
我已经有此代码,但是几乎已经完美,由于某种原因,如果一个标签在简报中出现多次,它会多次返回数据库中的同一行。
例如,如果用户搜索
$“复杂查询”
系统将返回任何具有标签 complx 的行,并且查询两次,因为有两个匹配的标签。我希望结果按降序排列,首先获得最多结果的行并且仅出现一次。
有什么想法吗? :)
i'm trying to do a search engine for a briefing system.
I'm using a many to many relationship style setup with 3 databases representing the relationships.
comms_briefings is where the data is stored for the briefings
search_tags is where the tags are stored
briefings_tags is where the relationship is formed
i have this code already which ALMOST perfect however, for some reason it returns the same row in the database multiple times if a tag appears more than once in the briefing.
eg if user searchs for
$ "complx enquiries"
the system will return any row that has the tag complx and enquiries twice as there are two matching tags. I want the results to be ordered desc with the row that gets the most results first and only to appear once.
any ideas? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该这样做:
首先将所有 tagId 拉入一个数组,然后对简报执行单个查询,按 id 分组。
Something like this should do:
All the tagIds are pulled into an array first, then you do a single query on the briefings, grouping by id.