Select to view content in your preferred language

MiniSearch widget doesnt work execSearch()

4304
44
07-05-2010 05:40 AM
NatashaManzuiga
Regular Contributor
http://forums.esri.com/Thread.asp?c=158&f=2421&t=295623#953276

I have the same problem...execSearch()..in MiniSearch widget.
If I add a search term and press Return nothing happens. I also added a button to the widget with the "execSearch()" statement and nothing happens with this either.

Thx

Naty
Tags (2)
0 Kudos
44 Replies
NatashaManzuiga
Regular Contributor
Naty,

   Here is your MiniSearch updated to a Flex Viewer 2.4 actual widget.

Also I forgot to mention in the readme.txt that the widget has to go in the UI section at the top of the config.xml like the NavigationWidget.


Hi Robert, thank u so much.
I see that I can open SearchWidget like I wanted. I added the public function querybmpid with the sParam I pass from the autocomplete of the MiniSearchWidget...but I got the Error#1009..
This is the function...

   public function querybmpid(sParam:String):void
   {
    //hide infowindow if any
    hideInfoWindow();
   
    var i:int = 0;
    queryLayer = configSearchText.layer;
    showMessage(queryLayer.name, false);
    if (queryLayer && !queryLayer.loaded)
    {
     queryLayer.addEventListener(LayerEvent.LOAD, queryLayer_loadHandler);
     function queryLayer_loadHandler(event:LayerEvent):void
     {
      querybmpid(sParam)
     }
     return;
    }
   
    queryExpr = configSearchText.expr;
    queryFields = configSearchText.fields;
    queryTitleField = configSearchText.titlefield;
    queryLinkField = configSearchText.linkfield;
   
    if (queryLayer && sParam)
    {
     var query:Query = new Query();
     var expr:String = queryExpr.replace(/\[value\]/g, sParam);
    
     query.where = expr;
     query.outSpatialReference = map.spatialReference;
     queryLayer.queryFeatures(query, new AsyncResponder(onResult, onFault, queryFields));
     showMessage(loadingLabel, true);
     showStateResults();
    
     function onResult(featureSet:FeatureSet, token:XMLList = null):void
     {
      try
      {
       searchResultAC = createSearchResults(featureSet, token);
      
       // share data
       addSharedData(widgetTitle, searchResultAC);
       if (featureSet.features.length < 1)
       {
        showMessage(noResultLabel, false);
       }
       else
       {
        showMessage(selectionLabel + " " + featureSet.features.length, false);
       }
      }
      catch (error:Error)
      {
       showMessage(error.message, false);
      }
     }
    
     function onFault(info:Object, token:Object = null):void
     {
      showMessage(info.toString(), false);
     }
    }
   }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Naty,

   OK, it's fixed.
0 Kudos
NatashaManzuiga
Regular Contributor
Naty,

   OK, it's fixed.


Robert u are great!!
When I will have time (I hope soon) I compare the old SearchWidget with the new...so I can see the difference and maybe I will better understand what u did and how it works..thank u sooooo much.

Naty
0 Kudos
NatashaManzuiga
Regular Contributor
Robert u are great!!
When I will have time (I hope soon) I compare the old SearchWidget with the new...so I can see the difference and maybe I will better understand what u did and how it works..thank u sooooo much.

Naty


Robert it works very well..maybe  I understand how it works and what u changed :DDD
...and one more question...can I call this function u added "querybmpid" passing an URL code....like "/index.html?Building=1"  ?
and then with 1.3 SFV I used this "this.showInfoWindow" to immediately show "infoWindow" after search exec...

Naty
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Naty,

   In your querybmpid function add the red lines below:

            public function querybmpid(sParam:String):void
            {                
                //hide infowindow if any
                hideInfoWindow();
                
                var i:int = 0;
                queryLayer = configSearchText.layer;
                showMessage(queryLayer.name, false);
                if (queryLayer && !queryLayer.loaded)
                {
                    queryLayer.addEventListener(LayerEvent.LOAD, queryLayer_loadHandler);
                    function queryLayer_loadHandler(event:LayerEvent):void
                    {
                        querybmpid(sParam)
                    }
                    return;
                }
                
                queryExpr = configSearchText.expr;
                queryFields = configSearchText.fields;
                queryTitleField = configSearchText.titlefield;
                queryLinkField = configSearchText.linkfield;
                
                if (queryLayer && sParam)
                {
                    var query:Query = new Query();
                    var expr:String = queryExpr.replace(/\[value\]/g, sParam);
                    
                    query.where = expr;
                    query.outSpatialReference = map.spatialReference;
                    queryLayer.queryFeatures(query, new AsyncResponder(onResult, onFault, queryFields));
                    showMessage(loadingLabel, true);
                    showStateResults();
                    
                    function onResult(featureSet:FeatureSet, token:XMLList = null):void
                    {
                        try
                        {
                            searchResultAC = createSearchResults(featureSet, token);
                            
                            // share data
                            addSharedData(widgetTitle, searchResultAC);
                            if (featureSet.features.length < 1)
                            {
                                showMessage(noResultLabel, false);
                            }
                            else
                            {
                                showMessage(selectionLabel + " " + featureSet.features.length, false);
                                var searchResult:SearchResult = searchResultAC[0] as SearchResult;
                                showHighlight([searchResult]);
                            }
                        }
                        catch (error:Error)
                        {
                            showMessage(error.message, false);
                        }
                    }
                    
                    function onFault(info:Object, token:Object = null):void
                    {
                        showMessage(info.toString(), false);
                    }
                }
            }
0 Kudos
NatashaManzuiga
Regular Contributor
Naty,

   In your querybmpid function add the red lines below:

            public function querybmpid(sParam:String):void
            {                
                //hide infowindow if any
                hideInfoWindow();
                
                var i:int = 0;
                queryLayer = configSearchText.layer;
                showMessage(queryLayer.name, false);
                if (queryLayer && !queryLayer.loaded)
                {
                    queryLayer.addEventListener(LayerEvent.LOAD, queryLayer_loadHandler);
                    function queryLayer_loadHandler(event:LayerEvent):void
                    {
                        querybmpid(sParam)
                    }
                    return;
                }
                
                queryExpr = configSearchText.expr;
                queryFields = configSearchText.fields;
                queryTitleField = configSearchText.titlefield;
                queryLinkField = configSearchText.linkfield;
                
                if (queryLayer && sParam)
                {
                    var query:Query = new Query();
                    var expr:String = queryExpr.replace(/\[value\]/g, sParam);
                    
                    query.where = expr;
                    query.outSpatialReference = map.spatialReference;
                    queryLayer.queryFeatures(query, new AsyncResponder(onResult, onFault, queryFields));
                    showMessage(loadingLabel, true);
                    showStateResults();
                    
                    function onResult(featureSet:FeatureSet, token:XMLList = null):void
                    {
                        try
                        {
                            searchResultAC = createSearchResults(featureSet, token);
                            
                            // share data
                            addSharedData(widgetTitle, searchResultAC);
                            if (featureSet.features.length < 1)
                            {
                                showMessage(noResultLabel, false);
                            }
                            else
                            {
                                showMessage(selectionLabel + " " + featureSet.features.length, false);
                                var searchResult:SearchResult = searchResultAC[0] as SearchResult;
                                showHighlight([searchResult]);
                            }
                        }
                        catch (error:Error)
                        {
                            showMessage(error.message, false);
                        }
                    }
                    
                    function onFault(info:Object, token:Object = null):void
                    {
                        showMessage(info.toString(), false);
                    }
                }
            }


GREAT Robert!! 🙂
and to call this function u added "querybmpid" passing an URL code....like "/index.html?Building=1" ?
Naty
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Naty,

   That has never been an option in the search widget only the eSearch widget.
0 Kudos
NatashaManzuiga
Regular Contributor
Naty,

   That has never been an option in the search widget only the eSearch widget.


So I can do the same with eSearch Widget?
Naty
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Naty,

   Sure the url portion of the search would not use the minisearch at all just the built in capability of the eSearch to query based on the URL. The URL would look like this

index.html?search=1&slayer=0&exprnum=0

you need to look at the documentation that comes with the eSearch to see what each of these are doing.

Here is the code changes you need to use in the MiniSearch to use the eSearch instead:

            private function execSearch():void
            {
                if(advancedAutoComplete.selectedItem){
                    try{
                        var aaa:String=advancedAutoComplete.selectedItem.@code;
                        var msArr:ArrayCollection = new ArrayCollection();
                        msArr.addItem(aaa);
                        addSharedData("MiniSearch_Search", msArr);
                        
                        var id:Number = ViewerContainer.getInstance().widgetManager.getWidgetId("Enhanced Search");
                        var bWidget:IBaseWidget = ViewerContainer.getInstance().widgetManager.getWidget(id, true) as IBaseWidget;
                        if (bWidget){
                            var vSW:* = bWidget;
                            vSW.queryFromURL(aaa,0,0);
                        }
                    }catch (error:Error){
                        AppEvent.showError( error.message );
                    }
                }
            }

And add the same commented areas I had in the original SearchWidget.mxml
0 Kudos
NatashaManzuiga
Regular Contributor
Robert I missed to say thank u for this code!!
It fixed my problem.

Now as u can see in image attached I almost dont see the text inside the AutoComplete Search. I put inside the minisearch widget.

I wish I could change the style for it...but it's hard... I dont know how to change it. 😞
Can u help me?

Thanks Robert!

Naty

Naty,

   Sure the url portion of the search would not use the minisearch at all just the built in capability of the eSearch to query based on the URL. The URL would look like this

index.html?search=1&slayer=0&exprnum=0

you need to look at the documentation that comes with the eSearch to see what each of these are doing.

Here is the code changes you need to use in the MiniSearch to use the eSearch instead:

            private function execSearch():void
            {
                if(advancedAutoComplete.selectedItem){
                    try{
                        var aaa:String=advancedAutoComplete.selectedItem.@code;
                        var msArr:ArrayCollection = new ArrayCollection();
                        msArr.addItem(aaa);
                        addSharedData("MiniSearch_Search", msArr);
                        
                        var id:Number = ViewerContainer.getInstance().widgetManager.getWidgetId("Enhanced Search");
                        var bWidget:IBaseWidget = ViewerContainer.getInstance().widgetManager.getWidget(id, true) as IBaseWidget;
                        if (bWidget){
                            var vSW:* = bWidget;
                            vSW.queryFromURL(aaa,0,0);
                        }
                    }catch (error:Error){
                        AppEvent.showError( error.message );
                    }
                }
            }

And add the same commented areas I had in the original SearchWidget.mxml
0 Kudos