my problem is amazon cloudSearch with location ..
when i use rank expression for search product with location found this error
["info"]=>
object(stdClass)#16 (4) {
["rid"]=>
string(80) "ee6c7090a20a654dbfd52a5f2ce0eeb96e766f609a8889bc1af02ab95e4065a6ce8ed690aa624373"
["time-ms"]=>
int(4)
["cpu-time-ms"]=>
int(0)
["messages"]=>
array(2) {
[0]=>
object(stdClass)#17 (3) {
["severity"]=>
string(7) "warning"
["code"]=>
string(27) "CS-RankExpressionParseError"
["message"]=>
string(328) "Could not parse rank expression (rank-geo=Math.sqrt(Math.pow(Math.abs(22345345-534534),2) Math.pow(Math.abs(934593495-34534534),2))): The ANTLR parser returned: -memory-(1) : error 10 : Missing token, at offset 47
near [Index: 0 (Start: 0-Stop: 0) ='', type<7> Line: 1 LinePos:47]
: Missing RPAREN
"
}
[1]=>
object(stdClass)#18 (3) {
["severity"]=>
string(7) "warning"
["code"]=>
string(41) "CS-InvalidFieldOrRankAliasInRankParameter"
["message"]=>
string(47) "Unable to create score object for rank 'bineet'"
}
}
}
while my search request url is
htp://www.search_endpoint."/search?bq=".urlencode($term)."&rank=geo&rank-geo=Math.sqrt(Math.pow(Math.abs(22345345 - 534534),2)+Math.pow(Math.abs(934593495 - 34534534),2))&size=$size&start=$start&return-fields=".implode(',',$return_fields
where i am doing wrong ?
without rank expression it is working fine .
i think error is in define expression for location but could not found any other solution
Please help me.
Thanks
I found solution for this by using
&rank-geo=urlencode('Math.sqrt(Math.pow(Math.abs(22345345 - doc.latitude),2)+Math.pow(Math.abs(934593495 - doc.longitude),2))')
this is rank-expression example
you can use custom rank expression in amazon cloud-search with two way
Make a new rank expression in amazon cloud-search console admin panel and define expression
ie mathematical expression and in search url simply append that rank expression name only like bellow
&rank=geo // geo rank expression should be define on cloud-search console admin panel
Second way is include rank name and expession in dynamic way like that in search url
&rank=distancesearch&rank-distancesearch=urlencode('Math.sqrt(Math.pow(Math.abs(22345345 - doc.latitude),2)+Math.pow(Math.abs(934593495 - doc.longitude),2))')
in this way no need to make a rank expression on amazon cloudSearch console admin panel
Related
I have a query deinged in hyperledger composer queries.qry file.
query checkOwnerUniqueness{
description: "Select owner with given identifier"
statement:
SELECT org.acme.participant.Owner
WHERE (idNum == _$idNum)
}
Now My query works if id number is abc123 and user search for abc123 but it fails if user pass on value as ABC123. However I would like query to respond with owner whether characters are entered in lower case or upper case.
I have already tried general SQL API's i.e. LOWER() and UPPER() but seems they doesn't work in the Hyperleger composer Query language. SO some can please help me understand on how to do this in Hyperledger Composer query file.
I would first suggest that IDs are inserted in the first place (ie programatically) with the same case. Composer simply passes on the query to CouchDB's query language FYI and honours the case sensitivity at which the data was entered.
Are you aware that you can use regex to validate the ID field (see Modeling language docs here ? - seems quite an important field to me (as opposed to say a surname field).
You can use otherwise buildQuery function (eg. with one parameter still) in your function - or if you insist in keeping the QUERY in queries.qry then supply two (lower and upper):
query checkOwnerUniqueness{
description: "Select owner with given identifier"
statement:
SELECT org.acme.participant.Owner
WHERE (idNum == _$upper ID idNum == _$lower )
}
var str = "joe123";
var lower = str.toLowerCase();
var upper = str.toUpperCase();
return query('checkOwnerUniqueness', {idNum: str} ) // ID passed in lower case
// OR
// return query('checkOwnerUniqueness', {idNum: lower, idNum: upper}) // upper or lower two parms
.then(function (results) {
for (var n = 0; n < results.length; n++) { // blah
// process all objects returned in the query
}
});
Giving you alternatives anyway - I think I would make sure the ID field is always entered in the same case, just saying.
I have a xpages booking application, there is a view for search officer's booking record. Due to search values may contains "(" or ")" or other symbols so I would use wild card search in the code. Also I need to ensure the search result returns properly so I created extra fields to connect two fields together (e.g. Fieldname1+++Fieldname2). I put the search code in view (In Properties -> Data -> Search in view results)
Here is the code for the search
var qstring= "";
if (
(sessionScope.officerSearch != null && sessionScope.officerSearch != "")||
(sessionScope.startDateSearch != null && sessionScope.startDateSearch != "")||
(sessionScope.returnDateSearch != null && sessionScope.returnDateSearch !=""))
{
qstring = " ( FIELD location+++group contains " + sessionScope.locationSearch +"+++"+ sessionScope.groupSearch +
" | FIELD location+++officer contains " + sessionScope.locationSearch +"+++"+ sessionScope.officerSearch +")" +
" & FIELD dateYYYYMM >=" + sessionScope.startDateSearch +
"& FIELD dateYYYYMM <=" + sessionScope.returnDateSearch;
}
return qstring;
When I run the application, I have two problems. If I search only one officer, I get an exception (Notes error: Query is not understandable). If I search more than one officer, I don't get the exception but the result does not return anything. So I use a computed field, paste the search code in there and run the program again. The computed field shows what I searched.
Due to I put the code in the computed field, I can read the whole query for the search
Problem 1: If I search one officer, although it occurs exception, I can imagine the query is like this
( FIELD location+++group contains "WEST+++GP AM(OSO)" | FIELD location+++officer contains "WEST+++John Freeman") & FIELD CompYMNUM >=201001& FIELD dateYYYYMM <=201712
If I put this query in Lotus Notes Client, and cick Search button, it returns the result properly
Problem 2: If I search multiple officers, although the result does not return anything, the computed field shows the query like this
( FIELD location+++group contains "WEST+++GP AM(OSO)" | FIELD location+++officer contains "WEST+++John Freeman, Kevin Sims, Sally Johnson, Tom Chan, William Ross") & FIELD dateYYYYMM >=201001& FIELD dateYYYYMM <=201712
I put this query in Lotus Notes Client, and cick Search button, it returns the result properly too.
I feel so strange that the Lotus Notes Client can return the proper result but the xpages cannot. Also I don't understand why if I search one officer, it causes exception (Query not understandable) and if I search more than one officer, it does not exception and not result return.
I think the reason I get the exception or the review does not the the result is I have "(" and ")" in the search value? However, I used wild card search to bound the search criteria (Or I misunderstand the wild card search?)
Also another reason I think is the field location+++officer. If search multiple officers, the field only recognize one officer e.g. "WEST+++John Freeman, Kevin Sims, Sally Johnson, Tom Chan, William Ross"?
Last but not least, maybe there is coding mistake in the code? But there is mistake in the code, I guess Lotus Notes Client will not return the result.
I try to solve the problems, but every time when I run the application, those problems still occurs.
Is my query has mistake?
Grateful if someone let me know my mistakes please? Thank you.
I'm trying to create index which using import data tool.
The datasource is from azure sql's view.
SELECT
b.Name,
b.ID
(SELECT
'[' + STUFF((
SELECT
',{"name":"' + p.Name + '"}'
FROM Product p WHERE p.Brand = b.ID
FOR XML PATH (''), TYPE)
.value('.', 'nvarchar(max)'), 1, 1, '') + ']') AS TAry,
b.IsDelete,
b.ModifyDatetime
from Brand b
Column with TAry will return JSon format string like:
[{"name":"Test1"},{"name":"Test2"}]
In Indexder properties with field TAry Chose the type Collection(Edm.String)
After create , It's return error , the message below:
"The data field 'TAry' has an invalid value. The expected type was 'Collection(Edm.String)'."
Thank for your reply.
I have try this kind format :[Test1","Test2"] still not work.
To do this, you need to use Azure Search REST API to set up a field mapping with jsonArrayToStringCollection function. Take a look at this article for detailed instructions.
I'm using Alfresco 5.0.d
I see in the search json result (with firebug console panel) that in addition to result items , 2 other properties are returned : numberFound and totalRecords. It seems that Alfresco search engine considers numberFound as total items found.
So it display "numberFound results founded" to user.
The problem is that numberFound is not equals to totalRecords.
I see that totalRecords is the correct number of search result (in fact search always return totalRecords number of items).
So i decided to see in the webscript that performs search (alfresco-remote-api-5.0.d.jar\alfresco\templates\webscripts\org\alfresco\slingshot\search\search.lib.js).
We can easly see that the numberFound property comes from this statement
var rs = search.queryResultSet(queryDef);
var numberFound = rs.meta.numberFound ;
About totalRecords property, it comes from the same statement but a little bit different:
var totalRecords = rs.nodes.length
which is the correct value of number of item really found.
So is it an Alfresco api bug?
If no , is it possible that error comes from my query parameters?
Can someone explains me what does mean the numberFound property?
Thank you.
Below is the URL of java file which is getting called when you are executing search.queryResultSet(queryDef) code.
you can refer below method in the java file.It is adding all the things.
https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/repository/source/java/org/alfresco/repo/jscript/Search.java
public Scriptable queryResultSet() //This is java method which is getting called.
Below is the code which is written for what you are getting in result.
meta:
{
numberFound: long, // total number found in index, or -1 if not known or not supported by this resultset
facets:
{ // facets are returned for each field as requested in the SearchParameters fieldfacets
field:
{ // each field contains a map of facet to value
facet: value,
},
}
}
I am using flickr api in order to count the how many times a tag occur. I want this information in order to calculate the Normalized Google Distance. I am using this query in my java code:
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&tags=bank
But i don't get good results. For example when i search "bank" the count value is 357439, when i search "credit" the count value is 59288, but when i am search for "bank credit" the count value is only 2. When i searching with the search box at flickr.com for "bank credit" i get a lot of results. But as far as i can see the query it uses is
http://www.flickr.com/search/?q=bank%20credit
which i am not able to use through my java code. I am trying to pass this
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&q=bank
and it says
Parameterless searches have been disabled. Please use flickr.photos.getRecent instead
How can i solve this problem?
Your generated url is incorrect
http://api.flickr.com/services/rest/method=flickr.photos.search&api_key=XXXXXXX&format=json&q=bank
is missing the question mark
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&q=bank
UPDATE based on OP comments:
I didn't see you had the question mark on the top url string. Looking at it again, I did realize you are not passing in any valid parameters. "q" isn't one of the listed parameters on the search api page. Try something like below to search photos with "bank" tag
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&tags=bank
or one with bank in description/title
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&text=bank
I got the same error. but when I added media = photos in the parameters, it got resolved.
e.g. :
baseurl = "https://api.flickr.com/services/rest/"
params_d['api_key'] = 'XXXXXXX'
params_d['method'] = 'flickr.photos.search'
params_d['tag'] = "river,mountains"
params_d['tag_mode'] = 'all'
params_d['per_page'] = 5
params_d['media'] = "photos"
params_d['nojsoncallback'] = 1
params_d['format'] = 'json'
resp = requests.get(baseurl, params = params_d)