full-text-search

Postgres full-text search with synonyms

半世苍凉 提交于 2020-01-23 06:07:07
问题 I have a database of restaurants which I do a full-text search on. The code looks something like this: SELECT * FROM restaurant WHERE restaurant.search_vector @@ plainto_tsquery(:terms); And search_vector is defined like this: alter table restaurant add column search_vector tsvector; create index restaurant_search_index on restaurant using gin(search_vector); create trigger restaurant_search_update before update or insert on restaurant for each row execute procedure tsvector_update_trigger(

SQLite FTS4 search with special characters

纵然是瞬间 提交于 2020-01-23 00:05:25
问题 I have an Android app which searches for data in an SQLite database with FTS4 virtual tables. It works fine, but when the data inside the tables contain special characters (like 'á', 'é', 'í', 'ó', 'ú' or 'ñ') the SQLite MATCH function gives no results. I'm lost at this point. Thanks. 回答1: Attention: default tokenizer is really poor. To get good results you should implement a custom tokenizer. The path isn't so simple: find the tokenizer (with stemmer?) that should fit your need, or develop

Set default limit for pg_trgm

我怕爱的太早我们不能终老 提交于 2020-01-22 19:42:47
问题 This seems like a really basic question, but how do I change the default limit for the pg_trgm extension? Which is currently 0.3. I have done: select set_limit(0.5) select show_limit() => 0.5 Close the connection, reconnect: select show_limit() => 0.3 Thanks for your help. 回答1: This is probably not a solution, but rather a contribution to a potential solution... (I am assuming that you want the pg_trgm parameter for all connections to the DB, not just interactive ones?) It seems that the

Set default limit for pg_trgm

淺唱寂寞╮ 提交于 2020-01-22 19:41:08
问题 This seems like a really basic question, but how do I change the default limit for the pg_trgm extension? Which is currently 0.3. I have done: select set_limit(0.5) select show_limit() => 0.5 Close the connection, reconnect: select show_limit() => 0.3 Thanks for your help. 回答1: This is probably not a solution, but rather a contribution to a potential solution... (I am assuming that you want the pg_trgm parameter for all connections to the DB, not just interactive ones?) It seems that the

Searching for text inside nested object (Backbone.js collection as example)

人盡茶涼 提交于 2020-01-22 15:42:26
问题 I have a backbone.js collection where I need to do a fulltextsearch on. The tools I have at hand are the following: Backbone.js, underscore.js, jQuery For those not familiar with backbone: A backbones collection is just an object. Inside the collection there is an array with models. Each model has an array with attributes. I have to search each attribute for a string. The code I am using for this is: query = 'some user input'; query = $.trim(query); query = query.replace(/ /gi, '|'); var

Escape string for use in MySQL fulltext search

若如初见. 提交于 2020-01-22 07:11:48
问题 I am using Laravel 4 and have set up the following query: if(Input::get('keyword')) { $keyword = Input::get('keyword'); $search = DB::connection()->getPdo()->quote($keyword); $query->whereRaw("MATCH(resources.name, resources.description, resources.website, resources.additional_info) AGAINST(? IN BOOLEAN MODE)", array($search) ); } This query runs fine under normal use, however, if the user enters a string such as ++ , an error is thrown. Looking at the MySQl docs, there are some keywords,

Escape string for use in MySQL fulltext search

回眸只為那壹抹淺笑 提交于 2020-01-22 07:11:13
问题 I am using Laravel 4 and have set up the following query: if(Input::get('keyword')) { $keyword = Input::get('keyword'); $search = DB::connection()->getPdo()->quote($keyword); $query->whereRaw("MATCH(resources.name, resources.description, resources.website, resources.additional_info) AGAINST(? IN BOOLEAN MODE)", array($search) ); } This query runs fine under normal use, however, if the user enters a string such as ++ , an error is thrown. Looking at the MySQl docs, there are some keywords,

Using a Combination of Wildcards and Stemming

时光怂恿深爱的人放手 提交于 2020-01-21 01:50:07
问题 I'm using a snowball analyzer to stem the titles of multiple documents. Everything works well, but their are some quirks. Example: A search for "valv", "valve", or "valves" returns the same number of results. This makes sense since the snowball analyzer reduces everything down to "valv". I run into problems when using a wildcard. A search for "valve*" or "valves*" does not return any results. Searching for "valv*" works as expected. I understand why this is happening, but I don't know how to

Postgresql ILIKE versus TSEARCH

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-20 04:13:07
问题 I have a query with a number of test fields something like this: SELECT * FROM some-table WHERE field1 ILIKE "%thing%" OR field2 ILIKE "%thing" OR field3 ILIKE "%thing"; The columns are pretty much all varchar(50) or thereabouts. Now I understand to improve performance I should index the fields upon which the search operates. Should I be considering replacing ILIKE with TSEARCH completely? 回答1: A full text search setup is not identical to a "contains" like query. It stems words etc so you can

Full-text search not finding results by removing characters at the font of the string

泪湿孤枕 提交于 2020-01-17 09:11:14
问题 I have an full-text catalog on my table when I remove the first couple of characters of the search string it can't find my products anymore but when I remove the last couple it finds the right products. When I found out I tested the behavior on a other site/server, and there it is fully working, doesn't matter if I remove some characters at the front or back it still finds my products. Working: SELECT ProductId FROM Product WHERE CONTAINS((FreeTextSearchString),'"*ij2001AR*"') SELECT