I have a database of around 10,000 records. Each record have a text of aprx 40 pages each. I need to implement full-text search in my database coz like query is taking lot of time.
I created the index, following these instructions and tried searching using full-text search.Although it increased the speed of showing results. But I am not able to search phrases in my table.
I am using following query for my exact phrase search
select * from ptcsoftcitation
WHERE CONTAINS(Judgment,'"said contention raised by the counsel"');
It's giving all those results which contains all the words but not exact phrase. It's behaving like ' "said" and "contention" and "raised" and "counsel" '
Please help me..
Assume I have 3 record:
bc
abc
bcd
Search exactly:
= 'bc' will return bc
Search closely:
LIKE 'bc' will return bc
Search contains:
LIKE '%bc' will return bc and abc
LIKE 'bc%' will return bc and bcd
LIKE '%bc%' will return bc, abc and bcd
I think your code should:
SELECT * FROM ptcsoftcitation
WHERE Judgment LIKE '%said contention raised by the counsel%'
Related
Product name:
AMOXICILLIN SUSP 250MG/5ML 100ML
AMOXIN SUSP 500MG/5ML 100ML
Client requirement is when they search the product like
"amoxi" or "amo susp" or "amox susp" or "amo sus 250 100"
100 250 sus amo or amox susp**
Result when I send parameter amox susp to the stored procedure will be the above two products as both contain this data.
We need to display all similar product names like "amoxilin 10mg" or "amoxilin 30mg". Basically if the product name is too lengthy he is going to search the word using few characters from the different words in same product. Sometimes even reverse too should work like mentioned in point b. Looking for inputs to achieve this.
Without using full-text search and index would like to achieve this.
The simplest and effective way of performing this search without using full text search is to (1) use the logic on the procedure to split the parameter into "words" and then (2) perform the search using LIKE and OR.
For example, if you have the parameter 100 250 sus amo you can split it into:
100
250
sus
amo
Then the query is:
select *
from t
where lower(description) like lower('%100%')
or lower(description) like lower('%250%')
or lower(description) like lower('%sus%')
or lower(description) like lower('%amo%')
I am relearning MS-SQL for a project.
I have a table with a field where the data includes the special character |.
Most times the field does not have it, sometimes once, sometimes 4 times.
I have been able to get it filtered to when present, but I would like to try to show only the times it appears more than once.
This is what I have come up so far:
SELECT UID, OBJ_UID, DESCRIPTION
FROM SPECIFICS
WHERE (NAMED LIKE '%[|]%')
Is there an easy way?
You can replace | with blank and compare length of strings
SELECT
UID, OBJ_UID, DESCRIPTION
FROM
SPECIFICS
WHERE
LEN(NAMED) - LEN(REPLACE(NAMED, '|', '')) > 1
Query returns rows where | appears more than one time
I'm trying to create a simple search page on my site but finding it difficult to get full text search working as I would expect it to word.
Example search:
select *
from Movies
where contains(Name, '"Movie*" and "2*"')
Example data:
Id Name
------------------
1 MyMovie
2 MyMovie Part 2
3 MyMovie Part 3
4 MyMovie X2
5 Other Movie
Searches like "movie*" return no results since the term is in the middle of a work.
Searches like "MyMovie*" and "2*" only return MyMovie Part 2 and not MyMovie Part X2
It seems like I could just hack together a dynamic SQL query that will just
and name like '%movie%' and name like '%x2%' and it would work better than full text search which seems odd since it's a large part of SQL but doesn't seem to work as good as a simple like usage.
I've turned off my stop list so the number and single character results appear but it just doesn't seem to work well for what I'm doing which seems rather basic.
select
*
from Movies
where
name like ('%Movie%')
or name like ('%2%')
;
select * from Movies where freetext(Name, ' "Movie*" or "2*" ')
I wish do searches using fuzzy search. Using Luke to help me, if I search for a word that has aliases (eg similar words) it all works as expected:
However if I enter a search term that doesn't have any similar words (eg a serial code), the search fails and I get no results, even though it should be valid:
Do I need to structure my search in a different way? Why don't I get the same in the second search as the first, but with only one "term"?
You have not specified Lucene version so I would assume you are using 6.x.x.
The behavior that you are seeing is a correct behavior of Lucene Fuzzy Search.
Refer this and I quote ,
At most, this query will match terms up to 2 edits.
Which roughly but not very accurately means that two texts varying with maximum of two characters at any positions would be a returned as match if using FuzzyQuery.
Below is a sample output from one of my simple Java programs that I illustrate here,
Lets say three Indexed Docs have a field with values like -
"123456787" , "123456788" , "123456789" ( Appended 7 , 8 and 9 to
– 12345678 )
Results :
No Hits Found for search string -> 123456 ( Edit distance = 3 , last
3 digits are missing)
3 Docs found !! for Search String -> 1234567 ( Edit distance = 2 )
3 Docs found !! for Search String -> 12345678 ( Edit distance = 1 )
1 Docs found !! for Search String -> 1236787 ( Edit distance = 2 for
found one, missing 4 , 5 and last digit for remaining two documents)
No Hits Found for search string -> 123678789 ( Edit distance = 4 ,
missing 4 , 5 and last two digits)
So you should read more about Edit Distance.
If your requirement is to match N-Continuous characters without worrying about edit distance , then N-Gram Indexing using NGramTokenizer is the way to go.
See this too for more about N-Gram
I do not get any results for the following query:
"SELECT * FROM test2 WHERE MATCH(txt) AGAINST('hello' IN BOOLEAN MODE)"
while test2 looks like:
id | txt
1 | ...
2 | ...
3 | ...
4 | ...
.. | ...
txt is 30 characters long (TEXT) and fulltext. I have about 16 records (tiny db) and the word hello is placed almost in every record in txt along with other words. I just wanted to know how full-text search works. So i get zero results and I can't understand why.
there are two reasons that you are not getting any results:
Reason 1: your search word 'hello' occurs in too many rows.
A natural language search interprets
the search string as a phrase in
natural human language (a phrase in
free text). There are no special
operators. The stopword list applies.
In addition, words that are present in
50% or more of the rows are considered
common and do not match. Full-text
searches are natural language searches
if no modifier is given.
Source: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
Reason 2: your search word 'hello' is on the stop-word list.
Any word on the stopword list will never match!
Source: http://dev.mysql.com/doc/refman/5.1/en/fulltext-stopwords.html