If I want to capture all Descriptions that have "Dillard s" (with the space being any single alphanumeric wildcard), is it more appropriate to use:
DESCRIPTION iLIKE '%Dillard_s%'
or use
DESCRIPTION Similar To '%Dillard_s%'
Thanks!
I would use like:
DESCRIPTION LIKE '%Dillard_s%'
If you don't want case-insensitivity (and your question suggests you don't), then just use like.
I tend to use either LIKE or go whole-hog and use regular expressions:
DESCRIPTION ~ 'Dillard[a-zA-Z0-9]s%'
Related
I'm using postgres full text search for (amoung other things) to provide autocomplete functionality for usernames and tags. However, I'd like autocomplete to match the column value 'dashed-tag-example' against a ts_query like 'dashedtag:*'.
My understanding is that, to do this without duplicating the column in my table I need to create a dictionary along the lines of the simple dictionary that strips charachters like '-'. Is it possible to create such a dictionary using SQL (i.e. something I could put in a rails migration)?
It seems like it should somehow be possible to define a dictionary (or do I need a parser?) that uses postgres's regexp substition functions but I can't seem to find any examples online of how to create a dictionary (parser?) like that. Is this possible? How?
The dictionary is too late; you would need a different parser, which would require writing C code.
The simple and pragmatic solution is to use replace() to strip the - when you construct the tsvector.
You don't need to create a new column for that, simply search like this:
SELECT ... FROM ...
WHERE to_tsvector('english', replace(col, '-', ''))
## to_tsquery('english', replace('search-string', '-' ''));
I'm trying to use Sphinx to find rows having words in their title column.
The query looks like this:
SELECT * FROM my_table WHERE MATCH ('#title "words"')
But it also returns rows having word (without the s) instead of words in the title.
What am I doing wrong?
Sounds like you have morphology (specifically stemming?) enabled on the index.
Should consider enabling index_exact_words
http://sphinxsearch.com/docs/current.html#conf-index-exact-words
which gives you exact form operator.
MATCH('#title =words')
Also gives you the possibility of the interesting expand_keywords option :)
http://sphinxsearch.com/docs/current.html#conf-expand-keywords
... or if dont ever want these matches, could disable stemming :) Alas there isn't a 'stemming optional' mode. (eg a ~ fuzzy operator to specifically stem)
On our PostgreSQL Database we have a field called Description. As you can guess this Description contains a lot of text and we would like to look inside this descriptions to find a certain word.
We tried contains and Charindex function but both are not working...
Any Idea how we can solve this?
Thank you very much!
Luca
You can use regular expressions with word delimiter markers:
select * from table
where description ~ ('\m' || 'yourword' || '\M');
Use ~* instead of ~ for case insensitive searches.
Note that using description LIKE '%yourword%' as #JNevill suggests will find that your word within other words as well, e.g. 'Jean-Luc Picard' LIKE '%car%' is true.
Hi I'm building a RESTful app and can't find the recommended way to pattern optional fuzzy or LIKE queries. For example a strict query might be,
/place?city=New+York&state=NY
Corresponds to SQL "... WHERE city="New York" AND state="NY"
But what if I wanted to search for the city field for any row with "York" in city name?
"... WHERE city LIKE "%{parameter}%" AND state="{parameter2}"
I'm thinking about just adding some kind of url-valid character to the request like this:
/place?city=*York*&state=NY
Is there an established or recommended pattern I should use? Thanks!
It's fine to use query string for searching, but it's a little bit weird to use macro character like "*" or "?" in query string(unless you decide to build a really powerful search engine like Google). More importantly, search is usually considered in fuzzy mode by default, so it's redundant to append/prepend the keyword with "*". If you do need exact search, you could surround the exact(or strict) keyword with double quotes. Namely, instead of using /place?city=*York*&state=NY, I recommend /place?city=York&state="NY".
In fact, Google uses quotes to search for an exact word or set of words, and I also found this site takes this pattern.
I feel silly for asking this but it isn't like I could google this.
What is the ` character called? In case it doesnt show up, it is the character used for inline code with markdown. Also, on most keyboards, it shares the key with ~.
I like all three answers so I made this a CW instead of accepting
All sorts of things, but in programming mostly the back-quote or backtick,
Grave (pronounced Grahv, not like the synonym for tomb) or Grave accent.
From the Jargon file, the prime nerd reference which really should be an ISO standard :-)
Common: backquote; left quote; left single quote; open quote; ; grave.
Rare: backprime; backspark; unapostrophe; birk; blugle; back tick; back glitch; push; opening single quotation mark; quasiquote.
You can use Unicode table to find name of the symbol. There are utilities which let you search it, like gucharmap. It gives U+0060 GRAVE ACCENT for this symbol.
This answer or this answer provides a good definition.
In laymen's terms "no-shift-tilde" is also useful in PHP for keeping mySQL statements from crashing on single quotes on the table name.
SELECT * from `the_table_name` WHERE id=1 // best practice
For some reason certain PHP servers will choke on this:
SELECT * from 'the_table_name' WHERE id=1 // not preferred method
This normally works, but doesn't pass nice in strings:
SELECT * from "the_table_name" WHERE id=1 // how to escape this string?
Other than that, I don't use it much.