Qualcosa da aggiungere a questo è l'idea di full text searching
con Rails. Se si sta eseguendo ricerche, è necessario essere consapevoli del fatto che si sta effettivamente eseguendo un testo completo "cercare" query in vostro DB, che è diverso a seconda del motore SQL si utilizza
MYSQL testo completo Ricerca
Il meccanismo LIKE %{search}%
è la funzione di ricerca di testo completo di base di MYSQL e cerca fondamentalmente la query di destinazione nell'intero record nel DB. Questo significa che se la query è questa:
SELECT * FROM `products` WHERE `name` LIKE '%alligator%'
MYSQL sarà essenzialmente guardare attraverso l'intero record "nome" per ogni riferimento alla tua richiesta. I risultati saranno basati sul fatto che il tuo record abbia la parola "alligatore" in qualsiasi parte di esso. This reference spiega un po 'di più su questo
PostgreSQL ricerca full-text
La ragione per cui ho scritto questo post è perché PSQL realmente fa in modo diverso, e quindi la query v'è stato fornito funziona solo per MySQL .PSQL ha un sacco di diverse funzioni per gestire la ricerca full text, ma dato che usiamo Heroku, siamo riusciti a usare il Textacular gem per ottenere tutto funziona correttamente
Qui sono some ways PSQL handles full text searching:
Full text searching in PostgreSQL is based on the match operator @@, which returns true if a tsvector (document) matches a tsquery (query). It doesn't matter which data type is written first:
SELECT 'a fat cat sat on a mat and ate a fat rat'::tsvector @@ 'cat &
rat'::tsquery; ?column?
---------- t
SELECT 'fat & cow'::tsquery @@ 'a fat cat sat on a mat and ate a fat
rat'::tsvector; ?column?
---------- f
As the above example suggests, a tsquery is not just raw text, any more than a tsvector > is. A tsquery contains search terms, which must be already-normalized lexemes, and may combine multiple terms using AND, OR, and NOT operators. (For details see Section 8.11.) There are functions to_tsquery and plainto_tsquery that are helpful in converting user-written text into a proper tsquery, for example by normalizing words appearing in the text. Similarly, to_tsvector is used to parse and normalize a document string. So in practice a text search match would look more like this:
SELECT to_tsvector('fat cats ate fat rats') @@ to_tsquery('fat & rat'); ?column?
---------- t Observe that this match would not succeed if written as
SELECT 'fat cats ate fat rats'::tsvector @@ to_tsquery('fat & rat'); ?column? ---------- f
Software di ricerca testo completo
La ricerca di testo completo è intrinsecamente piuttosto costosa sul DB, soprattutto se si dispone di molti dati da cercare. Ecco perché esistono soluzioni come sunspot solr o sphinx - per fornire un modo per entrambi indice & cercare i dati che avete
Se l'applicazione diventa abbastanza popolare, si potrebbe desiderare di investire in uno dei sistemi di ricerca full-text, come ad esempio these demonstrated by Heroku:
avete bisogno della la ricerca per parole chiave corrispondere esattamente al profilo soggetto? – Teddy
non esattamente, se il nome del soggetto ha una corrispondenza di parole rispetto a quelle dei profili di ricerca nei risultati di ricerca. – Murtza