# Predictive search simulation - as User types in Search term, Browser sends search requests repeatedly

**URL:** <https://community.gatling.io/t/predictive-search-simulation-as-user-types-in-search-term-browser-sends-search-requests-repeatedly/2361>\
**Category:** Gatling (Open-Source)\
**Created:** [June 15, 2015, 5:34pm UTC](https://community.gatling.io/t/predictive-search-simulation-as-user-types-in-search-term-browser-sends-search-requests-repeatedly/2361 "2015-06-15T17:34:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guest](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@Guest](https://community.gatling.io/u/Guest)\
**Post date:** [June 15, 2015, 5:34pm UTC](https://community.gatling.io/t/predictive-search-simulation-as-user-types-in-search-term-browser-sends-search-requests-repeatedly/2361/1 "2015-06-15T17:34:55Z")

</div>

Hello Gatling experts,

Could you please advise how to perform following simulation.

As user types in search word, Browser Sends search request and shows possible search terms.  
eg: when user tries to type housing, following search requests are sent to the server

1. /service/search/ac?q=hou
2. /service/search/ac?q=hous
3. /service/search/ac?q=housi
4. /service/search/ac?q=housin
5. /service/search/ac?q=housing

I am trying to create simulation for this scenario.

.feed(feeder)  
.group(“Search from home page”){

exec(http(“request\_28”)  
//.get("/service/search/ac?q=hou")  
.get("/service/search/ac")  
.**queryParam( “”“q”"", “${searchCriterion}.dropRight(2)”)** ===\> My intention is to perform search using Search term with last 2 chars truncated. This is not working. Instead search performed with “SearchCritera + dropRight(2)” string"  
// .**queryParam( “”“q”"", "${searchCriterion}"dropRight(2))** ====\> This approach giving compile error  
.headers(headers\_28)  
.resources(  
http(“request\_29”)  
//.get(uri4 + “/service/search/ac?q=housi”)  
.get(uri4 + “/service/search/ac”)  
**.queryParam( “”“q”"", “${searchCriterion}.dropRight(1)”)**  
.headers(headers\_28),  
http(“request\_30”)  
// .get(uri4 + “/service/search/ac?q=housing”)  
.get(uri4 + “/service/search/ac”)  
**.queryParam(""“q”"", “${searchCriterion}”)**  
.headers(headers\_28),  
http(“request\_32”)

**.get(uri4 + “/search?q=${searchCriterion}&cat=sitesearch”) ==\> This is working**  
.headers(headers\_0)  
**.check(regex("""**

- **\*\*\*\*\<a href="([^"]+)"\>${searchResult}""").saveAs(“computerURL”)))** // This is not working.  
}

Please could you also advise how to select first search result, using regular expression. search results listed for following search results

1.   
[  
   
 
**### Apply for housing**
  
 

 

**Find a place to live with a council or registered social landlord.**

 

   
   
 ](https://community.gatling.io/apply-for-housing/ "Apply for housing")  

2.   
[  
   
 
**### Emergency housing if you’re homeless**
  
 

 

**Find out your options if you’re homeless and don’t have anywhere to stay tonight.**

 

   
   
 ](https://community.gatling.io/emergency-housing-if-youre-homeless/ "Emergency housing if you're homeless")  

**Thanks in advance.**

**Regards,**  
**Raja**

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [June 18, 2015, 12:05pm UTC](https://community.gatling.io/t/predictive-search-simulation-as-user-types-in-search-term-browser-sends-search-requests-repeatedly/2361/2 "2015-06-18T12:05:00Z")

</div>

You can’t write any code you want in Gatling EL.  
You’ll have to write a function so you can use dropRight or substring: [gatling.io/docs/2.1.6/session/expression\_el.html#expression](http://gatling.io/docs/2.1.6/session/expression_el.html#expression)
