I have a table named Employee which contains column title and ID.
id
Title
1
IHR Notification: Myanmar reported
2
Notification1: Moonmar reported with 3 cases
now I want to search for phonetic word Myanmar but soundex function fails because it won't be able to convert some special character into its special code.
can any one suggest any other way to achieve this?
Related
I have a very strange behavior on sql server.
I have a User table with one row having BRAVO as last name.
When I use this simple request:
select * from User u where contains (u.LastName, 'BRAVO')
it finds no result.
If I update User table and set the lastname BRAVO to CRAVO (or any other letter) and call
select * from User u where contains (u.LastName, 'CRAVO')
it will work.
Is BRAVO a reserved word in SQL server? Am I missing something?
Thx
By default when you create a full text index it is associated with a system stoplist.Default stoplist has more than 150 words for english language.You can run below query and see all the stop words for english language for a particular database.
SELECT stopword,language_id FROM sys.fulltext_system_stopwords WHERE language_id = 1033
What is a stop list ? :
Stopwords are managed in databases by using objects called stoplists. A stoplist is a list of stopwords that, when associated with a full-text index, is applied to full-text queries on that index.
What is a stop word ? :
To prevent a full-text index from becoming bloated, SQL Server has a mechanism that discards commonly occurring strings that do not help the search. These discarded strings are called stopwords. During index creation, the Full-Text Engine omits stopwords from the full-text index.
You can use the below query to find the system specified stop words in English Language :
SELECT ssw.stopword, slg.name
FROM sys.fulltext_system_stopwords ssw
JOIN sys.fulltext_languages slg
ON slg.lcid = ssw.language_id
WHERE slg.lcid =1033
So, if you include these words in full text search, including BRAVO (for exact match, match giving in double quotes) it won’t give you the exact result.
I am working with SQL Server full text search. The issue is SQL Server is returning the wrong records.
For example: I am searching for was word in article's table column striptitle
SELECT
TitleStripped
FROM
[pastic_com].[dbo].[Psa_Articles]
WHERE
FREETEXT (TitleStripped, 'was')
With this query, I found 8 records; for reference two of them are pasted below:
Seasonal dynamics and relative abundance of AM fungi in rhizosphere of rice (Oryza sativa L. cv. Basmati supper).
Seasonal dynamics of AM fungi in sugarcane (Saccharum officinarum L.CV.SPF-213) in relation to red rot (Colletotrichum falcatum) disease from Punjab, Pakistan.
You will notice title column does not contain "was" word .
For more reference here's a screenshot:
[1]: https://i.stack.imgur.com/w0gdI.png
The full text search depends on thesaurus files and stoplist objects. Please double check your configuration for entries related to was.
Also, note the difference between FREETEXT and CONTAINS. If you look for exact matches of the word was then try CONTAINS instead of FREETEXT for the reason below.
Snippet from the documentation for FREETEXT, you probably want to avoid these actions.
Is a predicate used in the Transact-SQL WHERE clause of a Transact-SQL
SELECT statement to perform a SQL Server full-text search on full-text
indexed columns containing character-based data types. This predicate
searches for values that match the meaning and not just the exact
wording of the words in the search condition. When FREETEXT is used,
the full-text query engine internally performs the following actions
on the freetext_string, assigns each term a weight, and then finds the
matches:
Separates the string into individual words based on word boundaries
(word-breaking).
Generates inflectional forms of the words (stemming).
Identifies a list of expansions or replacements for the terms based on
matches in the thesaurus.
I am running a simple SQL contains search and the result does not include all expected rows.
All I need is a search that works in the same way as LIKE %word%.
SELECT *
FROM [MyTable] where contains(Name, N'walmart')
By running this select, the rows returned seem to only contains name with "walmart" with either space before or after or some kind of other delimiter like a period ("walmart.com"). No problem here.
But one row was not returned and its value is "mywalmart". Why does this row fail to return with the contains search? If I use name LIKE '%walmart%' it works just fine.
What do I need to fix the contains search to make it work?
Contains doesn't work the way you think, for your purposes LIKE is best.
See the docs on this:
CONTAINS can search for:
A word or phrase.
The prefix of a word or phrase.
A word near another word.
A word inflectionally generated from another (for example, the word drive is the inflectional stem of drives, drove, driving, and driven).
A word that is a synonym of another word using a thesaurus (for example, the word "metal" can have synonyms such as "aluminum" and "steel").
I'm using SQL Server 2012 and have created full-text index for NAME column in COMPANY table. All the searches I've tested are of the following format (with variable number of words to search), matching by beginnings of words in any order:
select id, name from company where contains(name, '"ka*" AND "de*"')
The problem is that there are cases where this query doesn't return any results even though it should be perfect match. For example when company name is "ka de we oy", the example above returns a match but '"ka*" AND "de*" AND "we*"' does not and neither does searching with all the four 'words'.
There are also other cases where, strangely enough, the search does not return results even with exact words. This seems related to very short (two-letter) words. There are also some issues with searching with many (6+) words.
Is there some explicit restriction to the number of words in a single query or how short they can be? How can I fix or work around this?
Edit: it seems to be certain common English words which are entirely excluded from the index (like 'we' in the example). This is an issue since it's a requirement that a few of the common words definitely should be searchable. Is there any way to change which words are not indexed or e.g. change the 'language' of the indexing to apply different set of common words that are left out?
Apparently this is simply a case of defining correct stopwords / stoplist:
https://msdn.microsoft.com/en-us/library/ms142551.aspx
https://msdn.microsoft.com/en-us/library/cc280405.aspx
Or setting the full-text index language for the column to the actual language so that English words don't cause issues.
Edit: actually it was easiest to simply disable the stoplist for the table entirely:
ALTER FULLTEXT INDEX ON company SET STOPLIST = OFF
Hopefully this helps someone else
I am trying to use Full Text Search in SQL Server to search in names. I have two columns indexed for Full Text Search - FirstName and LastName. I want to be able to find matches which are not exact. For example if someone is named "John" I want to find him even if the user searches for "jihn" or "jhn". I also want to search for multiple names and display results matching only one of them but sorted on RANK. I tried using FREETEXTTABLE but it seems like the RANK returned is always 0
SELECT *
FROM FREETEXTTABLE(People, (FirstName, LastName), 'John Smith', 10)
returns people named John Doe, Jane Smith and John Smith but all of them have a RANK of 0 and they are returned in the order they are in the database (by PK or something). I would expect that John Smith is ranked higher than the other names because two terms match while the other two names have one match each. Is there anything else I have to do to make ranking work. Also is there a way to make incorrect spelling work based on how close it is to actual value? Interestingly enough if I replace FREETEXTTABLE with CONTAINSTABLE and put OR between the terms of the query it works and gives some meaningful RANKs. I am trying to work with FREETEXT as I expect (maybe incorrectly) that it will find misspelled or similar names.