Full Text Search always returns empty result set - mysql

I have a table named 'fact' with title column, that should be full text index.
Firstly, I add a full text index:
ALTER TABLE fact ADD FULLTEXT title_fts (title)
So, I insert row:
INSERT INTO fact (id, title) VALUES ('1', 'red blue yellow ok green grey ten first wise form');
And then I perform search:
select * from fact f where contains (f.title, '"red" or "blue"')
When I perform the following query, or any other query with 'contains' statement, I get emtpy result set:
I have to use this statement, not against-match or like.
Does anyone happen to have an idea why is this happening?
Thank you.

There are two really important concepts when using full text search. The first is the minimum work length (see here). By default, the value is 4, meaning that words shorter than this are ignored. Bye-bye "red", "ok", "ten" and other short words.
The second important concept is the stop words list (see here). This would also get rid of "ok" and "first".
Your text doesn't have "blue" and "red" is ignored, so your query doesn't return anything.
You will need to re-build your index after you decide on the words that you really need to include.

Related

Google Sheets - Combine multiple IF Functions into one cell

I'm trying to produce a SKU in Google Sheets for a product using the values of three variants (Title, Colour and Size)
The product is 'Lightweight trainers' with colour variants of 'Red' and 'Blue', and the sizes range from 5 - 12.
Link to spreadsheet
https://docs.google.com/spreadsheets/d/1trq0X3MjR-n2THFnT8gYYlwKscnQavCeeZ8L-ifYaHw/edit?usp=sharing
Aim
I'm hoping to have a SKU that displays the product, the colour variant and the shoes size.
Example: LW-1-8 (Lightweight trainer, colour Red, size 8)
Product is Lightweight Trainers with a value of LW.
Colour variant 'Red' with a value of 1 and 'Blue' with a value of 2.
Shoe size variant = number ranging from 5 to 12.
Here's what I have so far, joining the colour and size variants.
=IFS(I2="Red",1,I2="Blue",2)&"-"& IFS(K2="5",5,K2="6",6,K2="7",7,K2="8",8,K2="9",9,K2="10",10,K2="11",11,K2="12",12)
However, I'm getting stuck in joining the data in column B with this function.
Any help with combining this data from multiple cells into one would be greatly appreciated.
TL;DR
=ARRAYFORMULA(IF(B2:B<>"", IFS(B2:B="Lightweight Trainers", "LW")&"-"&IFS(I2:I="Blue", 1, I2:I="Red", 2)&"-"&K2:K,))
Answer
What you want is basically:
<title>-<color number>-<shoe size>
To convert this to a function we can split it into each part and take it step by step:
Step 1: Title
For the first part -the title- we need to match the value with the shorthand. A simple list in an IFS is enough.
IFS(B2="Lightweight Trainers", "LW")
Obviously for now it only has a single value (Lightweight Trainers) but you could add more:
IFS(B2="Lightweight Trainers", "LW", B2="Heavyweight Trainers", "HW")
Step 2: color number
Similar to the previous step, it’s a mapping using ifs:
IFS(I2="Blue", "-1", I2="Red", "-2")
The dash is added so when adding everything it will only have it if
Step 3: shoe size
In this case we can simply get the value:
K2
Step 4: Adding everything together
We only need to add it with the dashes in between:
=IFS(B2="Lightweight Trainers", "LW")&"-"&IFS(I2="Blue", 1, I2="Red", 2)&"-"&K2
Step 5: Extending for the entire column automatically
We will use ARRAYFORMULA to add a single formula to the first cell and get it automatically extended to the entire column. We first add it to the formula we already have, and then extend the ranges to the entire column:
=ARRAYFORMULA(IFS(B2:B="Lightweight Trainers", "LW")&"-"&IFS(I2:I="Blue", 1, I2:I="Red", 2)&"-"&K2:K)
Remember to remove all the values in the column so array formula doesn’t override them (it would generate an error).
As you can see the formula generates errors for the rows that have no values. A good way of handling this case is to filter the rows without a title. In a single row would be:
=IF(B2<>"", [the entire formula],)
Notice the last comma.
So putting everything together and extending its range to the column, is:
=ARRAYFORMULA(IF(B2:B<>"", IFS(B2:B="Lightweight Trainers", "LW")&"-"&IFS(I2:I="Blue", 1, I2:I="Red", 2)&"-"&K2:K,))
Adding this to N2 should work.
Final notes
It seems that you use 150 when the size it’s not a whole number. If you want to keep that functionality you may use:
IF(K2-int(K2)=0, K2, 150)
On the last component and expand it the same way.
You may also want to prevent having two dashes when a value is missing (LW-5 instead of LW--5). To do so, I’d recommend adding it to each component instead of the formula that adds them together.
References
IFS (Docs Editors Help)
IF (Docs Editors Help)
ARRAYFORMULA (Docs Editors Help)
try in N2:
=IFS(I2="Red",1,I2="Blue",2)&"-"&
IFS(K2=5,5,K2=6,6,K2=7,7,K2=8,8,K2=9,9,K2=10,10,K2=11,11,K2=12,12)
or use:
=IF(I2="red", 1, IF(I2="blue", 2, )&IF((K5>=5)*(K5<=12), "-"&K5, )

Indenting entire field value in visual studios

I'm trying to create a report that returns it's value indented if it meets a certain criteria in an iif expression. Is there anyway to do this?
I'm not sure if you mean to have the data itself indented or if you want the row to indent for a certain value, but I have a solution for the former issue. There is a set of properties associated with textboxes that deal with indenting text. There is HangingIndent, LeftIndent, and RightIndent. If your data is aligned to the left, you can use either HangingIndent or LeftIndent.
You'll need to put the following expression in whichever indent you require based on the alignment of your data.
=IIF([your Condition here], "10pt", "0pt")
This will indent the data by 10pt if true and leave the data unindented if false. I tested it with a simple dataset that pulled an ID from 1-9 and set the HangingIndent property to indent if the ID was equal to 5.
=IIF(Fields!id.Value = "5", "10pt", "0pt")
Which yielded these results:

Unusual behavior with the Text widget indexing? (Tcl/Tk)

I am trying to create bindings for the Tk Text widget to limit the User so s/he can't delete the first character in the line (the character serves as a sort of prompt like in a terminal.)
Here's how I'm almost accomplishing this:
bind .text <BackSpace> {
if{[.text index insert] == [.text index {insert linestart+1c}]} {
break;
}
}
It works in terms of not letting the user delete the first character in the line, but for whatever reason, it also stops the user from deleting the ninth character in the line as well! For example:
>hello world!
Pressing backspace now from the end of that line will delete until
hello wor
and then stop! I can press the left-arrow to move to the next character after 'r' and keep deleting, and then as it should, it doesn't delete the carrot. I see no reason why this should be happening. If someone could either point out my mistake or let me know of a better way to achieve what I'd like that would be great.
At the point where it stops, [.text index insert] gives an index of 1.10 and [.text index {insert linestart+1c}] gives an index of 1.1.
These are numerically equal, and == likes to use numeric equality if at all possible.
The fix is to use the compare method of the text widget, perhaps like this:
bind .text <BackSpace> {
if {[.text compare insert == {insert linestart+1c}]} {
break
}
}
(I think you might actually be better off doing your overall goal a different way, perhaps by setting a tag on the text you want to preserve and checking before deletion whether any of the text to be deleted has the tag. But that's a very different approach.)

How do I get conditional output in a report?

I have a table that with a cell that may contain one of several defined words (such as "piping" or "containment"). I want to display a phrase specific to the word based on the word in my table. So if the table says piping, want the section of my report to say "...the piping in this area..." a null value would return specific text as well.
What about a CASE statement? Something like this:
CASE {column}
WHEN 'Piping' THEN 'Piping in this area'
WHEN 'Containment' THEN 'Etc....'
END AS "Project status?"

SQL query - Replace/Move some parts of content

I need to update about 2000 records in MySQL
I have a column 'my_content' from table 'my_table' with the folowing value
Title: some title here<br />Author: John Smith<br />Size: 2MB<br />
I have created 3 new columns (my_title, my_author and my_size) and now I need to separate the content of 'my_content' like this
'my_title'
some title here
'my_author'
John Smith
'my_size'
2MB
As you can imagine the title, author and size are always different for each row.
What I'm thinking is to query the following, but I'm not great at SQL queries and I'm not sure what the actually query would look like.
This is what I'm trying to do:
Within 'my_content' find everything that starts with "title:..." and ends with "...<br />au" and move it to 'my_title'
Within 'my_content' find everything that starts with "thor:..." and ends with "...<br />s" and move it to 'my_author'
Within 'my_content' find everything that starts with "ize:..." and ends with "...<br />" and move it to 'my_size'
I just don't know how to write a query to do this.
Once all the content is in the new columns, I can just find and delete the content that's not needed any more, for example 'thor:' , etc.
You can use INSTR to find the index of your delimiters and SUBSTRING to select out the part you want. So, for instance, the author would be
SUBSTR(my_content,
INSTR(my_content, "Author: ") + 8,
INSTR(my_content, "Size: ") - INSTR(my_content, "Author: ") - 8)
You'd need a bit more work to trim the <br/> and any surrounding whitespace.
Please try the below:
SELECT SUBSTRING(SUBSTRING_INDEX(mycontent,'<br />',1),LOCATE('Title: ',mycontent)+7) as mytitle,
SUBSTRING(SUBSTRING_INDEX(mycontent,'<br />',2),LOCATE('Author: ',mycontent)+8) as myauthor,
SUBSTRING(SUBSTRING_INDEX(mycontent,'<br />',3),LOCATE('Size: ',mycontent)+6) as mysize
FROM mytable;