Firebase "like" search on string [duplicate] - firebase

This question already has answers here:
How to perform sql "LIKE" operation on firebase?
(5 answers)
Closed 5 years ago.
I am trying to search the user on the basis of name . It search perfectly if the name is given from first name but didn't search on the string the second name. Where first and second both are saved in one value separated by space for example
"John Smith". If search on "john" or "jo" etc it retrieve the record but if its smith it retrieve nothing.
Code
var ref = firebase.database().ref().child('User').orderByChild("name").startAt(searchString).endAt(searchString + "\uf8ff");
$scope.usercollection = $firebaseArray(ref);

With your query it is normal that you only get results starting with j, jo, joh, john, etc... The startAt method "creates a Query with the specified starting point". So it looks at how your searchString variable starts.
There is no full text search mechanism in Firebse for the moment. You will find on the web several possibilities to implement such a mechanism, e.g.:
https://firebase.googleblog.com/2014/01/queries-part-2-advanced-searches-with.html
https://github.com/FirebaseExtended/flashlight

Related

Netsuite Saved Search formula to extract text string

For a Netsuite account, I have noticed the entityid for a customer (the customer ID on the UI) appears as an alphanumeric value using the organisation's customer number format.
However, in a saved search, it appears in the following format,'ACC12345 Parent entity name: ACC67895 Child entity name'. I am trying to use a formula to get the child entity's customer ID number from this text string.
The following formula mostly works in a saved search to extract the child entity's customer ID number (i.e. the 'ACC67895 ' in the above example
SUBSTR({entityid},INSTR({entityid},'ACC',1,2),8)
Is there a way to replace the 8 in this formula with another formula so that it extracts everything from the second 'ACC' onwards until the first blank ' '?
The number of characters of the customer ID varies so I don't want to use 8 as a hard coded value in the formula.
Thanks
I would suggest having your first SUBSTR return everything from the start of the child customer's ID to the end, then nest that inside a second SUBSTR which would use an INSTR to find the space after the ID and cut off everything after that:
SUBSTR(SUBSTR({entityid},INSTR({entityid},'ACC',1,2)),1,INSTR(SUBSTR({entityid},INSTR({entityid},'ACC',1,2)),' '))
Ugly, but it works.

Firebase: If a value includes a specific text in database [duplicate]

This question already has answers here:
How to perform sql "LIKE" operation on firebase?
(5 answers)
Closed 3 years ago.
I try to filter the list for items that contain a certain text.
database:
{"123":{"cities":"sss"},"445":{"cities":"hello hi dd"}}
And I want to get the items that contains "hi" within the cities value:
{"445":{"cities":"hello hi dd"}}
I tryd this:
https://xxxxx.firebaseio.com/allitems.json?orderBy="cities"&startAt="hi"
But it's not working... It only shows the items that starts with "hi"...
thanks.
At the time of writing, there is no built-in full-text search capability in the Firebase Realtime Database.
The official Cloud Functions samples include an example of full-text search with the Algolia hosted search service.
Note that there is a workaround if you search for a string that starts with some specific characters (which is different than a string which contains some specific characters).
Have a look at the "Range Queries" section of the REST API documentation:
We can combine startAt and endAt to limit both ends of our query. The
following example finds all dinosaurs whose name starts with the
letter "b":
curl
'https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy="$key"&startAt="b"&endAt="b\uf8ff"&print=pretty'
The \uf8ff character used in the query above is a very high code point
in the Unicode range. Because it is after most regular characters in
Unicode, the query matches all values that start with a b.
So in your case you would do as follows:
https://xxxxx.firebaseio.com/allitems.json?orderBy="cities"&startAt="hi"&endAt="hi\uf8ff"

Compare two Firestore Timestamps by "greater than" [duplicate]

This question already has an answer here:
Filter including field in formula
(1 answer)
Closed 3 years ago.
I'm trying to compare two timestamps inside a cloud function.
Not by "equality" (as described here) but by "greater than".
I do not know where is the problem, but I can't get it working.
This is my code, quite simple:
const lastDayUnread = await admin.firestore()
.collection('/unread')
.where('last_message', '>', 'last_seen')
.get()
I also tried using .seconds property but still nothing:
.where('last_message.seconds', '>', 'last_seen.seconds')
If I execute the same query from a JS client, it works, and teh console shows me that there is a Timestamp object inside my documents last_seen and last_message properties.
The right-hand side of a where clause in Cloud Firestore must be a literal value. There is no support for looking up the value of another field.
The typical workaround would be to store an additional field with last_message.seconds - last_seen.seconds and then:
.where('delta_seconds', '>', 0)

Google App Maker Query Builder

Created a simple app to keep track of the company fax numbers. In my header I have a search box where I want user's to search either by First Name, Last Name or both First and Last Name. I added the below to Query Builder
firstName contains? :SearchText or
lastName contains? :SearchText
Searching by first name or last name works just fine. How can I search by both first and last name? Right now when I search by both I get no results. Thanks.
"User Picker" widget should be a good fit for your case.
If you want to keep custom employees model please consider the following options:
Add Name field ("FirstName LastName") so contains operator would give expected result
Switch datasource to Query Script and process search query
(https://developers.google.com/appmaker/models/datasources#query_script)

How do I show "NEXT" x items to the user? [duplicate]

This question already has answers here:
Paging & Sorting grids with ASP.Net MVC
(5 answers)
Closed 9 years ago.
I am learning MVC. I'm creating a simple website for demo, which stores products in Database and shows them to the user 10 per page. Now, how do I fetch "NEXT" 10/20 items from the database? I thought of adding auto-increment column to table and then fetching items on its basis. Is it the right way? Also I am keeping record of how many items have been shown to the user by getting an int value as parameter to the Controller function, Products(int id). Is it the right way? I mean will it work if user is on 5th page(hence id==5) and refreshes the page?(or will it set id back to 0?).
you can use linq queries to fetch number of items in a table. you can pass number of item, start index. then the query will be like this
var nextProduct = myProducts.Skip(100).Take(10);
it will return 10 items from 101 to 110.
Fetching data based on id is not a good idea. because if u delete any record there will be a difference in the count and id. so you can take using the above code concept

Resources