Android Question Using Large & Searchable List with SearchView + B4XSerializator in jRDC

Anser

Well-Known Member
Licensed User
Hi,

From the below given post
https://www.b4x.com/android/forum/threads/large-searchable-list-with-searchview-b4xserializator.61872/

As per Erel, "SearchView is very useful, however it was limited to about 500 items as it takes time to build the index and the UI is frozen until the index is ready (the main thread is busy building the index). Now with B4XSerializator and a small B4J program we can easily load 10,000 items or more to SearchView."

I could find the searchview in most of the modern android apps, but I avoided the use of SearchView in my B4A app because I face the problem stated above ie "The searchView takes time to build the index and the UI is frozen until the index is ready (the main thread is busy building the index)". As a solution to this issue, the new SearchView based on the B4XSerializator was released by B4X team.

There are also few open libraries in github, which I am not sure whether this can be wrapped and used in B4A and whether those libs also has the limitation of slow indexing or not.

Some of them are listed below
https://github.com/MiguelCatalan/MaterialSearchView
https://github.com/lapism/SearchView
https://github.com/Quinny898/PersistentSearch

I would like to use this new faster SearchView in my B4A app along with jRDC2 so that my UI doesn't freeze. According to Erel, this is not a generic requirement in jRDC, so I need to incorporate this myself in the jRDC

As per Erel's advice, "It will be simpler to add another handler in the server that is responsible for building DataToSend and call it with HttpUtils2. The searchview module should also be added along with the jRDC server app"

May be this is going to be useful for all those using jRDC to connect and work with Remote database and wish to use SearchView in their B4A app. If this works well, those who wish to include this SearchView feature in jRDC can include the required additional modules to their existing standard jRDC project supplied by the B4X team, compile it and use it.

I don't have any previous experience with B4J and seriously doesn't know where to start this.

So far I figured out (I guess) that I need the following

  1. May be a new code module named "SearchViewHandler" in the jRDC Project ie something line "RDCHandler" which is supposed to handle the request that comes from the B4A app via httputils.
  2. Add the "SearchView" class module in the jRDC Project
  3. Do I need something like "DBRequestManager" which is already inluded in the B4A Project (client app)?

Any help to move forward will be appreciated.

Regards

Anser
 
Last edited:

Erel

Administrator
Staff member
Licensed User
1. Add a new class to jRDC named SearchHandler with code similar to:
B4X:
Sub Class_Globals
  
End Sub

Public Sub Initialize
  
End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
   Dim sql As SQL = Main.rdcConnector1.pool.GetConnection 'change pool variable to public in RDCConnector
   Try
     'get the items
     Dim list As List
     '...
     Dim sv As SearchView
     sv.Initialize
     Dim res() As Object = sv.SetItems(list)
     Dim ser As B4XSerializator
     Dim b() As Byte = ser.ConvertObjectToBytes(res)
     resp.OutputStream.WriteBytes(b, 0, b.Length)
   Catch
     Log(LastException)
   End Try
   sql.Close
End Sub

It is up to you to implement the code that gets the data from the database.

2. Add srvr.AddHandler("/search", "SearchHandler", False) to the main module.

3. In the client you can now send a http request with HttpJob.Download to this handler and get the already build indices:
B4X:
Sub JobDone(Job As HttpJob)
   If Job.Success = False Then
     Log("Error: " & Job.ErrorMessage)
   Else
     If Job.JobName = "DBRequest" Then
       If Job.Tag = True Then
         reqManager.HandleJobAsync(Job, "ReqManager")
       Else
         Dim result As DBResult = reqManager.HandleJob(Job)
         reqManager.PrintTable(result)
       End If
     Else if Job.JobName = "Search" Then '<---- make sure to set the job name.
       Dim ser As B4XSerializator
       ser.ConvertBytesToObjectAsync(Bit.InputStreamToBytes(Job.GetInputStream), "search")
     End If
   End If
   Job.Release
End Sub

Sub Search_BytesToObject (Success As Boolean, NewObject As Object)
   If Success Then
     Dim all() As Object = NewObject
     Dim FirstIndex As Object = Array (all(0), all(1))
     Dim SecondIndex As Object = all(2)
     sv.LoadFirst(FirstIndex)
     sv.LoadSecond(SecondIndex)
   End If
End Sub
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Else if Job.JobName = "Search" Then '<---- make sure to set the job name.
It will not work as the handler is named serach!
2. Add srvr.AddHandler("/serach", "SearchHandler", False) to the main module.

sorry, i could not resist :D
 
Upvote 0

Anser

Well-Known Member
Licensed User
Thank you, I am getting a better and clear picture now on how this is going to work,

You have already demonstrated how the request is handled in the Client B4A JobDone, just wondering how will be the calling part ? I mean using http request with HttpJob.Download to the handler "SearchHandler"

I mean, How will I make use of the already existing SQL statements in config.properties file for eg sql.SELECT ProductName FROM TableName, when the call is made via http request.

How will be the http request call looks like



Regards

Anser
 
Upvote 0

Anser

Well-Known Member
Licensed User
But in a medium sized project, there is going to be multiple activities and multiple searchviews that is going to display different type of data picked from different tables, hardcoding all these queries, will it be practical ?. I am just wondering whether I am on the right track ?
 
Upvote 0

incendio

Well-Known Member
Licensed User
Not sure what do you want exactly, perhaps you need to build a searchable list with data from remote database.

If it's correct and you have ultimate list view, perhaps, there's a simpler solution.

I used sqlite tables in memory to store data from jRDC, then use this table as a source data for ULV. From there, searching data is just a matter of sql statement. It is very fast, handling thousands of data.

If you don't have ULV, maybe you could modify Search view to use sqlite in memory.
 
Last edited:
Upvote 0

Anser

Well-Known Member
Licensed User
Not sure what do you want exactly, perhaps you need to build a searchable list with data from remote database.
Yes. Your guess is right.
If it's correct and you have ultimate list view, perhaps, there's a simpler solution.
Yes. I have ULV

I used sqlite tables in memory to store data from jRDC, then use this table as a source data for ULV. From there, searching data is just a matter of sql statement. It is very fast, handling thousands of data.
If ULV can be made to work like B4A SearchView than that is fine for me. If you don't mind would you share a sample. I use jRDC.

If you don't have ULV, maybe you could modify Search view to use sqlite in memory.
I would like to try out this option too, but I understand that SearchView takes time to build its index

I am not familiar with sqlite table in memory, haven't used it till now. I am willing to explore it.


Regards
Anser
 
Upvote 0

incendio

Well-Known Member
Licensed User
If ULV can be made to work like B4A SearchView than that is fine for me. If you don't mind would you share a sample. I use jRDC.

There is an Example from ULV, look for its example under folder Search_filter, on this folder there is a file Search.bas.

The file shows how to build a SearchView using ULV.
 
Upvote 0
Top