query to search for occurance of any word of a search string - couchbase-lite

I have the following documents:
fName : "Samuel",
sName : "Erick Jameson"
I want to return the user if the search is by Samuel, Erick, Jameson, Erick Jameson, Samuel Erick etc.
Basically if any word exist in the fName or sName, I want to return it. For now, I have the following query:
Function.lower(Expression.property("fName")).like(Expression.string("%" + searchTermLC + "%"))))
.or((Expression.property("lName").like(Expression.string("%" + searchTermLC + "%")));
my search results are:
Samuel found
Erick found
Jameson found
Erick Jameson found
the following are not found:
Samuel Erick
Erick Samuel
Samuel Jameson
...
what query would do that?

There are a few mistakes noted in your query above:
The open close brackets don't match
You forgot about Function.lower(Expression.property("lName")).
I assume when you did your own test, the query syntax was right otherwise you would not have gotten any results.
The results you got are as expected for like operator. If you want the query to include:
Samuel Erick
Erick Samuel
Samuel Jameson
in your results, you can try the In Operator.

Related

Google Sheets - Can't find what's wrong with my Query function based on Today() function

I've gone through the many similar questions for the past two days and can't seem to find what's not working.
My function is:
=IFNA(QUERY(A2:I,"select B,C where F = date '"&text(today(),"yyyy-MM-dd")&"'",1),"")
Where I'm trying to query all the first+last names in columns B, C if their corresponding date in F is today.
But instead, it just queries the entire columns, regardless of the corresponding dates.
It's so annoying, please help me fix the function :)
If you want first & last names in different column
Try this: =ArrayFormula(IFERROR(SPLIT(IF(C1:C=TODAY(),A1:A&" "&B1:B,"")," ")))
For you range: =ArrayFormula(IFERROR(SPLIT(IF(F2:F=TODAY(),B2:B&" "&C2:C,"")," ")))
If you want first & last name in same cell
Try this: =ArrayFormula(IF(F2:F=TODAY(),B2:B&" "&C2:C,""))
Arrayformula()
If function

Is there a function to search for partial text in cells

I have a function that searches a spreadsheet for a name I put in cell A1 and returns a column in that row
eg, if I enter Smith in A1 it will return all columns C´s where Column D contains Smith, I would also like it to return columns containing smith so if a cell as john smith it would also be returned,
this is what I have so far but it only returns Total match,
=FILTER(Results!C:C,Results!$D:$D=$A$1)
Hope someone can help,
Thanks in advance
I believe this is what you're trying to do:
=filter(Results!C:C,find(lower($A$1),lower(Results!D:D))>=0)
EDIT: adding the lower() function to make the comparison case insensitive.

Query with sum many columns from same table with laravel query

This seems very easy query but can't translate it into laravel query. I have table orders there are two columns total_usd and total_gbp. I want to sum each column to get total of usd and total of gbp on the page.
This query is working in phpmyadmin and I got correct result
SELECT sum(order_total_usd) as usd, sum(order_total_gbp) as gbp FROM `orders`
In laravel I've tried this
$sumOrders = Order::select('sum(order_total_gbp) as gbp, sum(order_total_usd) as usd');
when I dd($sumOrders) I've one really huge output which almost cause browser to freeze.
Where is my mistake here?
You can try something like this
$sumOrders = Order::select( \DB::raw("sum(order_total_gbp) as gbp"), \DB::raw("sum(order_total_usd) as usd"))->get();
You can use selectRaw
$sumOrders = Order::selectRaw('sum(order_total_gbp) as gbp, sum(order_total_usd) as usd');
Except for one missed word, your code is OK. Add "Raw" after "select" as shown:
$sumOrders =
Order::selectRaw(
'sum(order_total_gbp) as gbp,
sum(order_total_usd) as usd'
);
Just replace "Order::select(...)" with Order::selectRaw(...).
Have a great day!

Select all posts where its title contains 14 digits

I'd like to find all posts where its title meets the critera below in one database call.
title.scan(/\d/).length == 14
Post.where('title ~ ?', '^\D*(\d\D*){14}$')

Oracle full text, the syntax of CONTAINS()

contains(columnname, 'ABC')=0
this means search for the data which doesn't contain word 'ABC'
contains(columnname, 'ABC and XYZ')=0
contains(columnname, 'ABC or XYZ')=0
what do these 2 sql mean? I tested them, there's no syntax error, but they didn't work as I expected, the 'and' seems like an 'or', and 'or' seems like an 'and', could anyone help to explain this?
all doc found in google are for contains()>0, those're not what I need.
thanks in advance.
According to oracle documentation, the contains function :
returns a relevance score for every row selected
If you ask for
contains(columnname, 'ABC')=0
You actually ask for a score of 0 which means: columnname doesn't contain 'ABC'
According to the docs:
In an AND query, the score returned is the score of the lowest query term
In an OR query, the score returned is the score for the highest query term
So if you ask for:
contains(columnname, 'ABC and XYZ')=0
then if either 'ABC' or 'XYZ' has a score of 0 it will have the lowest score and that's what you'll get from the function, so you're actually asking for: columnname doesn't contain 'ABC' or 'XYZ' (at least one of them).
Same thing for the or -
contains(columnname, 'ABC or XYZ')=0
only if both 'ABC' and 'XYZ' have the score of 0 the function will return 0, so you're actually asking for: columnname doesn't contain 'ABC' and 'XYZ' (both of them).
IMHO, this behaviour is correct since it meets De-Moragan's Laws

Resources