Select to view content in your preferred language

QueryTask - Max Records returned by Server

2586
4
Jump to solution
10-11-2012 05:48 AM
BrianLord1
Deactivated User
I have an app with an autocomplete box that I need to populate with every address in my county (around 30,000) so that the user can easily type in a valid address and my app can use it to query multiple other layers.  The box worked great when the max number of records returned by the server was 1000, but when I change this to allow all 30,000 addresses to be returned it slows down the application quite a bit.

I figured this would happen, but I am not sure what other ways I could achieve the same result will not decreasing performance.  If I created a text document or spreadsheet containing a list of addresses would that be faster since I would not have to perform a querytask on the feature class?

Any suggestions would be greatly appreciated.

Thanks,
Mark
0 Kudos
1 Solution

Accepted Solutions
HyrumErnstrom
Regular Contributor
Do you need to return all values or just the ones matching what is being typed in. So when the user types a new letter run a query return only the matching address.

View solution in original post

0 Kudos
4 Replies
HyrumErnstrom
Regular Contributor
Do you need to return all values or just the ones matching what is being typed in. So when the user types a new letter run a query return only the matching address.
0 Kudos
BrianLord1
Deactivated User
Do you need to return all values or just the ones matching what is being typed in. So when the user types a new letter run a query return only the matching address.


Good idea, I implemented your idea and it does seem to improve performance.  I have included the code in case anyone was wondering what I did.

I decided not to run the query until the user typed in more than 2 characters.
    Private Sub AutotbSearch_KeyUp(sender As System.Object, e As System.Windows.Input.KeyEventArgs) Handles AutotbSearch.KeyUp

        If AutotbSearch.Text.Length > 2 Then
            LoadGISData()
        Else
            Return
        End If

    End Sub


Then the query searchs the address field for anything that is "LIKE" the text property of the autocomplete box.
Public Sub LoadGISData()

        Dim queryTaskAddress As New QueryTask("http://xxxxxxxx/xxxxxxxx/rest/services/ElectionData/MapServer/0")
        AddHandler queryTaskAddress.ExecuteCompleted, AddressOf QueryTaskAddress_ExecuteCompleted
        AddHandler queryTaskAddress.Failed, AddressOf QueryTaskAddress_Failed

        Dim searchText As String = AutotbSearch.Text

        Dim Addressquery As Query = New Query()
        Addressquery.ReturnGeometry = True
        Addressquery.OutFields.Add("PHYADDR1")
        Addressquery.Where = String.Format("PHYADDR1 LIKE '%{0}%'", searchText)

        queryTaskAddress.ExecuteAsync(Addressquery)

    End Sub


Then, then a list is populated with each record that was returned from the query and the itemsource property of the autocomplete box is set to the list.
Private Sub QueryTaskAddress_ExecuteCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)
        AddressfeatureSet = args.FeatureSet
        AddressList.Clear()

        Dim AddressValue As String

        For Each Feature As Graphic In AddressfeatureSet
            AddressValue = Feature.Attributes.Item("PHYADDR1").ToString
            AddressList.Add(AddressValue)
        Next
        AutotbSearch.ItemsSource = AddressList

    End Sub


Thanks,
Mark
0 Kudos
LanceCrumbliss
Frequent Contributor
Because of the nature of asyncronous calls, it means it is possible they can be returned to the client in any order.  Here is a tip:

In addition to what you're doing, take advantage of the optional UserState argument of the asyncronous query method and an instance variable to hold references to the most recent query sent so that you can be sure what is being returned is in sync with what has most recently been searched for.

Before calling the ExecuteAsync method of queryTaskAddress, set an instance variable to the whereclause string.  Set the UserState property to the same string.  When the async call returns, extract the the string from the args.UserState and see if it matches the instance variable (which is being set before each ExecuteAsync call).  If not, a new query has already been sent, so don't bother processing the current result.

Lance
0 Kudos
BrianLord1
Deactivated User
I am not entirely sure how I would go about setting up what you described.  Could you post a code example showing what you mean?

thanks,
Mark
0 Kudos