crossTerm API with JavaScript
Configuration and start
- Copy the extracted file into the Examples folder to the crossTerm API root directory (according to the installation instructions, this is C:\Program Files\across\AcrossServices\crossTerm).
- Open the example in a browser.
URL for default installations: http://localhost/Across/CrossTerm/Examples/JS/crossTermApiExample.html
Change the crossTerm API URL to http://localhost/Across/CrossTerm/ for a default installation.
Used API functions
The search form uses the WildcardSearch API function. Its parameter is a JSON structure, where query text (with or without a wildcard), source and target languages, and stemming flag are defined.
Requirements: Content-Type header should be set to application/json, HTTP method should be POST.
Optional $select parameter allows to define specific result fields. Optional $expand parameter allows to fetch nested objects (Entry and Properties, if function result is Term, for example).
var query ={ Query : $("#query").val(), Parameters:{ SourceLanguage : $("#query_lang").val(), TargetLanguage :0, UseStemming :false}}; $.ajax({ type:"POST", url: baseUrl +"Terms/WildcardSearch?"+ selector, contentType :"application/json", data :"{query: "+ JSON.stringify( query )+" }"})
{"odata.metadata":"http://localhost/Across.Services.CrossTerm/odata/v1/$metadata#Terms","value":[{"Id":570,"Text":"advert","Lcid":1033,"State":"Unreleased","Created":"2013-11-25T15:05:28+07:00","Creator":"Default Supervisor","Modified":"2013-11-25T15:05:28+07:00","Modifier":"Default Supervisor","EntryId":157},{"Id":572,"Text":"advertisement","Lcid":1033,"State":"Unreleased","Created":"2013-11-25T15:05:28+07:00","Creator":"Default Supervisor","Modified":"2013-11-25T15:05:28+07:00","Modifier":"Default Supervisor","EntryId":157},{"Id":571,"Text":"advice","Lcid":1033,"State":"Unreleased","Created":"2013-11-25T15:05:28+07:00","Creator":"Default Supervisor","Modified":"2013-11-25T15:05:28+07:00","Modifier":"Default Supervisor","EntryId":157}]}
Search result (query with $select parameter: $select=Text,Id,EntryId,State):
{"odata.metadata": "http://localhost/Across.Services.CrossTerm/odata/v1/$metadata#Terms&$select=Text, Id,EntryId,State","value":[{"Text":"advert","Id":570,"EntryId":157,"State":"Unreleased"},{"Text":"advertisement","Id":572,"EntryId":157,"State":"Unreleased"},{"Text":"advice","Id":571,"EntryId":157,"State":"Unreleased"}]}
Term details view uses Terms entity set with term ID as a parameter.
$select and $expand parameters are also applicable.
$.ajax({ url: baseUrl +"Terms("+ termId +")?"+ expand, contentType :"application/json"})
Result (query without a $expand parameter):
{"odata.metadata":"http://localhost/Across.Services.CrossTerm/odata/v1/$metadata#Terms/@Element","Id":572,"Text":"advertisement","Lcid":1033,"State":"Unreleased","Created":"2013-11-25T15:05:28+07:00","Creator":"Default Supervisor","Modified":"2013-11-25T15:05:28+07:00","Modifier":"Default Supervisor","EntryId":157}
Result (query with a $expand parameter: $expand=Entry/Instance,Entry):
{"odata.metadata":"http://localhost/Across.Services.CrossTerm/odata/v1/$metadata#Terms/@Element","Entry":{"Instance":{"Id":1,"Name":"Default across Server","Description":"","ServerId":"5d5c79c6-2a09-4be5-a1ab-9a7fd24da123"},"Id":157,"InstanceId":1,"Created":"2013-11-25T15:05:28+07:00","Creator":"Default Supervisor","Modified":"2013-11-25T15:05:28+07:00","Modifier":"Default Supervisor"},"Id":572,"Text":"advertisement","Lcid":1033,"State":"Unreleased","Created":"2013-11-25T15:05:28+07:00","Creator":"Default Supervisor","Modified":"2013-11-25T15:05:28+07:00","Modifier":"Default Supervisor","EntryId":157}