久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

我將如何使用 php 和 mySQL 實(shí)現(xiàn)簡(jiǎn)單的站點(diǎn)搜索?

How would I implement a simple site search with php and mySQL?(我將如何使用 php 和 mySQL 實(shí)現(xiàn)簡(jiǎn)單的站點(diǎn)搜索?)
本文介紹了我將如何使用 php 和 mySQL 實(shí)現(xiàn)簡(jiǎn)單的站點(diǎn)搜索?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在創(chuàng)建一個(gè)允許用戶提交報(bào)價(jià)的網(wǎng)站.我將如何創(chuàng)建一個(gè)(相對(duì)簡(jiǎn)單?)返回最相關(guān)引號(hào)的搜索?

I'm creating a site that allows users to submit quotes. How would I go about creating a (relatively simple?) search that returns the most relevant quotes?

例如,如果搜索詞是turkey",那么我會(huì)返回turkey"這個(gè)詞出現(xiàn)兩次的引號(hào),然后再返回它只出現(xiàn)一次的引號(hào).

For example, if the search term was "turkey" then I'd return quotes where the word "turkey" appears twice before quotes where it only appears once.

(我會(huì)添加一些其他規(guī)則來幫助過濾掉不相關(guān)的結(jié)果,但我主要關(guān)心的是.)

(I would add a few other rules to help filter out irrelevant results, but my main concern is that.)

推薦答案

每個(gè)人都建議使用 MySQL 全文搜索,但是您應(yīng)該注意一個(gè)巨大的警告.全文搜索引擎僅適用于 MyISAM 引擎(不適用于 InnoDB,后者因其引用完整性和 ACID 合規(guī)性而成為最常用的引擎).

Everyone is suggesting MySQL fulltext search, however you should be aware of a HUGE caveat. The Fulltext search engine is only available for the MyISAM engine (not InnoDB, which is the most commonly used engine due to its referential integrity and ACID compliance).

所以你有幾個(gè)選擇:

1.粒子樹概述了最簡(jiǎn)單的方法.您實(shí)際上可以從純 SQL 中獲得排名搜索(沒有全文,什么也沒有).下面的 SQL 查詢將搜索表并根據(jù)搜索字段中字符串出現(xiàn)的次數(shù)對(duì)結(jié)果進(jìn)行排名:

1. The simplest approach is outlined by Particle Tree. You can actaully get ranked searches off of pure SQL (no fulltext, no nothing). The SQL query below will search a table and rank results based off the number of occurrences of a string in the search fields:

SELECT
    SUM(((LENGTH(p.body) - LENGTH(REPLACE(p.body, 'term', '')))/4) +
        ((LENGTH(p.body) - LENGTH(REPLACE(p.body, 'search', '')))/6))
    AS Occurrences
FROM
    posts AS p
GROUP BY
    p.id
ORDER BY
    Occurrences DESC

編輯了他們的示例以提供更清晰的內(nèi)容

上述 SQL 查詢的變體,添加 WHERE 語句(WHERE p.body LIKE '%whatever%you%want')等可能會(huì)得到您所需要的.

Variations on the above SQL query, adding WHERE statements (WHERE p.body LIKE '%whatever%you%want'), etc. will probably get you exactly what you need.

2. 您可以更改數(shù)據(jù)庫架構(gòu)以支持全文.通常采取什么措施來保持 InnoDB 引用完整性、ACID 合規(guī)性和速度,而無需安裝諸如 Sphinx 全文搜索引擎 for MySQL 是將報(bào)價(jià)數(shù)據(jù)拆分到它自己的表中.基本上你會(huì)有一個(gè)表 Quotes 是一個(gè) InnoDB 表,而不是你的 TEXT 字段數(shù)據(jù)",你有一個(gè)引用quote_data_id",它指向 Quote_Data 表上的 ID,它是一個(gè) MyISAM 表.你可以在 MyISAM 表上做你的全文,加入與你的 InnoDB 表一起返回的 ID,瞧你有你的結(jié)果.

2. You can alter your database schema to support full text. Often what is done to keep the InnoDB referential integrity, ACID compliance, and speed without having to install plugins like Sphinx Fulltext Search Engine for MySQL is to split the quote data into it's own table. Basically you would have a table Quotes that is an InnoDB table that, rather than having your TEXT field "data" you have a reference "quote_data_id" which points to the ID on a Quote_Data table which is a MyISAM table. You can do your fulltext on the MyISAM table, join the IDs returned with your InnoDB tables and voila you have your results.

3. 安裝 Sphinx.祝你好運(yùn).

鑒于您的描述,我強(qiáng)烈建議您采用我介紹的第一種方法,因?yàn)槟幸粋€(gè)簡(jiǎn)單的數(shù)據(jù)庫驅(qū)動(dòng)站點(diǎn).第一個(gè)解決方案很簡(jiǎn)單,可以快速完成工作.Lucene 設(shè)置起來會(huì)很麻煩,特別是如果您想將它與數(shù)據(jù)庫集成,因?yàn)?Lucene 主要用于索引文件而不是數(shù)據(jù)庫.Google 自定義站點(diǎn)搜索只會(huì)讓您的站點(diǎn)名譽(yù)掃地(讓您看起來很業(yè)余和被黑),而 MySQL 全文很可能會(huì)導(dǎo)致您更改數(shù)據(jù)庫架構(gòu).

Given what you described, I would HIGHLY recommend you take the 1st approach I presented since you have a simple database driven site. The 1st solution is simple, gets the job done quickly. Lucene will be a bitch to setup especially if you want to integrate it with the database as Lucene is designed mainly to index files not databases. Google custom site search just makes your site lose tons of reputation (makes you look amateurish and hacked), and MySQL fulltext will most likely cause you to alter your database schema.

這篇關(guān)于我將如何使用 php 和 mySQL 實(shí)現(xiàn)簡(jiǎn)單的站點(diǎn)搜索?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動(dòng)填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 国产精品免费在线 | 国产91丝袜在线18 | 99精品国产一区二区青青牛奶 | 国产网站在线播放 | 日韩图区 | 视频在线一区二区 | 瑟瑟视频在线看 | 国产福利资源在线 | 久久爱黑人激情av摘花 | 成人在线视频免费观看 | 91久久精品视频 | 精品国产精品三级精品av网址 | 精品视频在线观看 | 欧美五月婷婷 | 日本超碰 | 色综合一区二区三区 | 国产乱码精品一区二区三区中文 | 99久久免费精品视频 | 亚洲一区 | 色就干 | 国产一区二区三区在线免费观看 | 中文字幕成人av | 欧美激情精品久久久久 | 日韩国产中文字幕 | 国产在线一区观看 | a级片在线 | 成人黄页在线观看 | 91免费看片 | 成人国产精品久久 | 亚洲精选一区 | 成人国产一区二区三区精品麻豆 | 亚洲区中文字幕 | 亚洲九九色 | 久久综合久色欧美综合狠狠 | 天堂av中文 | 97精品超碰一区二区三区 | 欧美极品在线观看 | 天天干天天干 | 日韩网站免费观看 | 成人激情免费视频 | 亚洲一区二区三区免费在线观看 |