package Ġcom . nit in . web . con git ive search . controllers Ċ Ċ import Ġorg . springframework . beans . factory . annotation . Value Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġorg . springframework . stereotype . Controller Ċ import Ġorg . springframework . web . bind . annotation . PostMapping Ċ import Ġorg . springframework . web . bind . annotation . Delete Mapping Ċ import Ġorg . springframework . web . bind . annotation . RequestMapping Ċ import Ġcom . azure . search . documents . indexes . Search Index Client Ċ import Ġcom . azure . search . documents . indexes . Search Index Client Builder Ċ import Ġcom . azure . search . documents . indexes . models . FieldBuilder Options Ċ import Ġcom . azure . search . documents . indexes . models . Search Index Ċ import Ġcom . azure . search . documents . indexes . models . Syn onym Map Ċ import Ġcom . azure . search . documents . indexes . models . BM 2 5 Similarity Algorithm Ċ import Ġcom . azure . search . documents . indexes . models . Sc oring Profile Ċ import Ġcom . azure . search . documents . indexes . models . Text Weights Ċ import Ġcom . azure . core . credential . Azure Key Credential Ċ import Ġcom . nit in . web . con git ive search . models . Dataset Ċ Ċ @ Controller Ċ @ RequestMapping ("/ api / index ") Ċ class ĠIndex ing Controller (@ Value ("\ ${ cognitive search . url }") Ġprivate Ġval Ġendpoint : ĠString ,@ Value ("\ ${ cognitive search . apikey }") Ġprivate Ġval Ġ ĠapiKey : ĠString ){ ĊĊĠĠĠĠĠĠĠ Ġprivate Ġ Ġval Ġclient : ĠSearch Index Client Ġ= ĠSearch Index Client Builder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. endpoint ( endpoint ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. credential ( Azure Key Credential ( apiKey )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build Client () ĊĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġindex Name Ġ= Ġ" dataset " ĊĊĠĠĠ Ġ@ PostMapping ĊĠĠĠ Ġfun Ġindex (): ĠResponseEntity < String > Ġ{ ĊĠĠĠĠĠĠĠĊĠĠĠĠĠĠĠ Ġ// ĠUse Ġthe ĠSearch Index Client Ġto Ġcreate ĠSearch Fields Ġfrom Ġyour Ġown Ġmodel Ġthat Ġhas Ġfields Ġor Ġmethods Ġannotated ĊĠĠĠĠĠĠĠ Ġ// Ġwith Ġ@ Simple Field Ġor Ġ@ Search able Field . ĊĠĠĠĠĠĠ Ġval Ġindex Fields Ġ= ĠSearch Index Client . build Search Fields ( Dataset :: class . java , Ġ ĠField Builder Options ()) ĊĠĠĠĠĠĠĠ Ġval Ġnew Index Ġ= Ġ ĠSearch Index ( index Name , Ġindex Fields ) ĊĠĠĠĠĠĠĠ Ġnew Index . similarity Ġ= ĠBM 2 5 Similarity Algorithm (). set B ( 1 . 0 ) ĊĠĠĠĠĠĠĠ Ġnew Index . sc oring Profiles Ġ= ĠlistOf ( sc oring Profile (" default Profile ")) ĊĠĠĠĠĠĠĠ Ġnew Index . default Sc oring Profile Ġ= Ġ" default Profile " ĊĠĠĠĠĠĠĠ Ġclient . create Index ( new Index ); ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity . ok (" ok ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġscoring Profile ( profile Name : ĠString ): ĠS cor ing Profile { ĊĊĠĠĠĠĠĠ Ġval Ġprofile = ĠS cor ing Profile ( profile Name ) ĊĠĠĠĠĠĠ Ġprofile . text Weights = ĠText Weights ( map Of ( Pair (" name ", 8 . 0 ), Pair (" st ew ard Name ", 5 . 0 ))) ĊĠĠĠĠĠĠĠ Ġreturn Ġprofile ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Delete Mapping ĊĠĠĠ Ġfun Ġdelete Index (): ĠResponseEntity < String > Ġ{ ĊĠĠĠĠĠĠĠ Ġclient . delete Index ( index Name ) ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity . ok (" deleted ") ĊĠĠĠ Ġ} ĊĊ Ċ }