See below error:
"error": {
"msg": "org.apache.solr.search.SyntaxError: Cannot parse 'sku_str:VFY:A5440M35A5ME': Encountered \" \":\" \": \"\" at line 1,
column 11.
code": 400 }
Escape solr query string , See below function
SolrUtils::escapeQueryChars — Escapes a lucene query string
http://php.net/manual/en/solrutils.escapequerychars.php
Related
I'm getting following error while escaping special character '&' after running http://localhost:8983/solr/amazon_products/select?q=*:*&fq=Category:"Toys \& Games "
this query in Solr
{
"responseHeader": {
"zkConnected": true,
"status": 400,
"QTime": 0,
"params": {
"q": "*:*",
"Games \"": "",
"fq": "Category:\"Toys \\",
"rows": "70"
}
},
"error": {
"metadata": [
"error-class", "org.apache.solr.common.SolrException",
"root-error-class", "org.apache.solr.parser.TokenMgrError"
],
"msg": "org.apache.solr.search.SyntaxError: Cannot parse 'Category:\"Toys \\': Lexical error at line 1, column 17. Encountered: <EOF> after : \"\\\"Toys \\\\\"",
"code": 400
}}
Category field contains values like below
"Category":["Toys & Games "," Learning & Education "," Science Kits & Toys"]
"Category":["Home & Kitchen "," Home Décor "," Window Treatments "," Window Stickers & Films ", " Window Films"],
And category field is of type string with multivalued=true
{
"name":"Category",
"type":"string",
"multiValued":true,
"stored":true},
How to search properly for Category:"Toys & Games "
NOTE: I tried http://localhost:8983/solr/amazon_products/select?q=*:*&fq=Category:Toys* AND *"Games "&rows=70 this query and it worked fine, but If I excatly want to serach for string 'Toys & Games ' how to do that by properly escaping special character '&'
You'll need to encode some of the characters. For example the following command:
$ curl 'http://localhost:8983/solr/puldata/select?fq=title_t%3A%22Woody%20Herman%20%26%20His%20Orchestra%22&q=*&start=0'
will query fq=title_t:"Woody Herman & His Orchestra". Notice how the :, ", spaces, and the & characters are encoded.
I've been doing this for a couple of days, and I'm having this problem:
Whenever I try to encode a map into query string, I get the error "syntax error before: chat_id"
form = %{
"chat_id" => 237799109,
"text" => "OMG a message"
}
{status, body} = URI.encode_query(form)
#=> (SyntaxError) lib/elixir.ex:20: syntax error before: chat_id
But as far as I know this is the map syntax, isn't it? As seen here, where this example is presented:
iex> hd = %{"foo" => 1, "bar" => 2}
iex> URI.encode_query(hd)
"bar=2&foo=1
What is happening here?
Full error message:
== Compilation error on file lib/elixir.ex ==
** (SyntaxError) lib/elixir.ex:20: syntax error before: chat_id
(elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.Paral
lelCompiler.spawn_compilers/1
I don't know why you would get the error you listed, but URI.encode_query/1 only returns a single binary argument. You are trying to pattern match it against a tuple.
Can you paste more of the code instead of just those 2 lines?
iex(2)> URI.encode_query(form)
"chat_id=237&text=OMG+a+message"
Getting this error:
Illegal character in query at index 61:
https://cs4.salesforce.com/services/data/v32.0/query?q=Select +AppId__c,Technical_Review_Approved__c +From Application__c + Where + AppId__c+= '1793poiuyt'
Even tried this:
String url = "/query?q=";
String getRecords = url + "Select AppId__c,Technical_Review_Approved__c From Application__c Where AppId__c= '1793poiuyt' " ;
Caused by: java.net.URISyntaxException: Illegal character in query at
index 61:
https://cs4.salesforce.com/services/data/v32.0/query?q=Select AppId__c,Technical_Review_Approved__c From Application__c Where AppId__c= '1793poiuyt'
You can't have spaces in a URL. Check the REST Developer Guide: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_query.htm.
An example: https://na1.salesforce.com/services/data/v20.0/query/?q=SELECT+name+from+Account -H "Authorization: Bearer token"
I am attempting to convert the following MongoDB JSON command into valid BSON using the Mongo C driver:
db.test.update({
"_id" : ObjectId("5624200d4bacd3940b8b2d62"),
"folders.folder_id": "3_root",
"folders.files": { $elemMatch: { "file": "5BD252AD-10C9-4DCE-A59C-5E3223BDDC60"}} },
{$inc : { "folders.0.files.$.favorites.0.like": 1} }
);
I have attempted to create it using:
query = BCON_NEW ("_id", BCON_OID(&oid));
BSON_APPEND_UTF8 (query, "folders.folder_id", folderPositionRaw);
BSON_APPEND_UTF8 (query, "folders.files", "{" , "$elemMatch","{","file","5BD252AD-10C9-4DCE-A59C-5E3223BDDC60","}","}");
update = BCON_NEW ("$inc",
"{",
"folders.0.files.$.favorites.0.like", 1,
"}");
mongoc_collection_update (collection, MONGOC_UPDATE_NONE, query, update, NULL, &error);
But it is way wrong.
When I compile I get:
/current/set_fav.c: In function ‘main’:
/current/set_fav.c:102: warning: initialization discards qualifiers from pointer target type
/current/set_fav.c:168:122: error: macro "BSON_APPEND_UTF8" passed 9 arguments, but takes just 3
/current/set_fav.c:168: error: ‘BSON_APPEND_UTF8’ undeclared (first use in this function)
/current/set_fav.c:168: error: (Each undeclared identifier is reported only once
/current/set_fav.c:168: error: for each function it appears in.)
FYI: folderPositionRaw has the value of 3_root set higher up in the codes.
To add a little more information: Originally I had the wrong Mongo syntax, but C was happy. I was using the following:
query = bson_new ();
bson_oid_init_from_string (&oid, tribe_id);
query = BCON_NEW ("_id", BCON_OID(&oid));
BSON_APPEND_UTF8 (query, "folders.folder_id", folderPositionRaw);
BSON_APPEND_UTF8 (query, "folders.folder_id.$.files.file", file);
I received help from my DB team giving me the correct Mongo syntax (top of post) and in my attempt to structure that into the C BSON I did something wrong.
Some progress:
I have updated my codes and they NO longer crash which is a good sign, but the output JSON that is sent to Mongo is not fully structured correctly. I think the issue is the value 1 that is sent in the mongo $inc command is being sent as a scalar 1 not an int 1. I have tried both with and without quotes around the 1. With quotes the code runs, but does not preform the update (no errors returned). If I remove the quotes the app crashes.
query = bson_new ();
bson_oid_init_from_string (&oid, tribe_id);
query = BCON_NEW ("_id", BCON_OID(&oid), "folders.folder_id", folderPositionRaw,"folders.files",
"{",
"$elemMatch",
"{",
"file", file,
"}",
"}");
// Find the document
cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);
// update document
update = BCON_NEW ("$inc",
"{",
"folders.0.files.$.favorites.0.like","1",
"}");
str = bson_as_json (update, NULL);
printf ("***-> %s <-***\n\n",str);
mongoc_collection_update (collection, MONGOC_UPDATE_NONE, query, update, NULL, &error);
Found the issue!
You cannot use a standard int it must be a BCON_INT
update = BCON_NEW ("$inc",
"{",
"folders.0.files.$.favorites.0.like",BCON_INT32 (1),
"}");
:)
How does one search for specific punctuation in Solr, such as :)? I have tried URL encoding the text but I still get this message:
org.apache.solr.search.SyntaxError: Cannot parse ':': Encountered " ":" ": "" at line 1, column 0.
Was expecting one of:
<NOT> ...
"+" ...
"-" ...
<BAREOPER> ...
"(" ...
"*" ...
<QUOTED> ...
<TERM> ...
<PREFIXTERM> ...
<WILDTERM> ...
<REGEXPTERM> ...
"[" ...
"{" ...
<LPARAMS> ...
<NUMBER> ...
<TERM> ...
"*" ...
Additionally, I need to perform this search on a text field, not on a string field. How should I configure the analyser to save punctuation?
Note that searching google for the subject is impossible due to two prolific Solr contributors with the name "Smiley"!
What configurations you have for the text field?
You should take care the splitting is not happening on the puntuations e.g. if using StandardTokenizerFactory or word delimiter filter.
You can define a custom field with WhitespaceTokenizerFactory or KeywordTokenizerFactory and have further filters like lower case on it.
Also, There are some characters which Solr/Lucene uses for some operation e.g. + - ! ( ) { } [ ] ^ " ~ * ? :
You would need to escape the special characters with backslash. Check Escape Special Characters
instead of :) search for "\:\ )" , both chars :,) have special meaning in SOLR.
for all special operatos you need to escape by prefixing with '\' char .