Java serialization of a query to list of strings - java

I stumbled upon a strange issue and cant find quick solution to deal with it. Front side of my application sends query to back-end I added square brackets for readability.
as it should be
http://localhost:3000/?params=[First_value],[Anhui Jantene Hone Textiles Co., Ltd.],[Third_Value]
as it is
http://localhost:3000/?params=[first_value],[Anhui Jantene Hone Textiles Co.], [Ltd.],[Third_Value]
params are serialized to List but there is a problem when given value on a front-side has comma in the name, then instead of one value I get 2 entries. In a given example expected size of a list should be 3 but I get 4 elements.
Any help is appreciated

You can't do this in the query string because of how a comma is treated. You need to use a POST with a request body like this:
["First_value", "Anhui Jantene Hone Textiles Co., Ltd.","Third_Value"]

Related

Google Sheets Java API failing to append values to multiple columns

I can't find a way to append multiple values to multiple rows, like I do with .update method with the same range value.
service.spreadsheets().values()
.append(
spreadsheetId,
"sheet!A2:B300",
new ValueRange().setValues(Arrays.asList(Arrays.asList("1", "2")))
)
.setValueInputOption("USER_ENTERED").execute();
The message I get is:
"Requested writing within range [sheet!A2], but tried writing to column [B]"
If I use all the same arguments with the .update method instead of .append, everything works nicely.
Also, .append will work if the inner list has only 1 item
-
Thanks
EDIT: I was using HH:mm string as a part of sheet name. It was causing the range error. The same worked on .update method so I didn't consider it important at first
Remove the colon from the name of your worksheet, and this apparent bug in the append feature of the Spreadsheet API will go away.
Append works by finding a table within the requested range and then appending data to the end of that table. The table it found appears to only have one column (in 'A'), and append is having trouble adding the new column. You can resolve this by adding a column header in B, most likely.
Admittedly, this isn't super intuitive, so we'll take a look at changing the behavior.

Using Apache Solr's boost query function with Spring in Java

I'm writing a Java application that is using Apache Solr to index and search through a list of articles. A requirement I am dealing with is that when a user searches for something, we are supplying a list of recommended related search terms, and the user has the option to include those extra terms in their search. The problem I'm having, however, is that we want the user's original search term to be prioritized, and results that match that should appear before results that only match related terms.
My research suggests that Solr's boost function is the solution for this, but I'm having some trouble getting it to work with Spring. The code all runs fine and I get my search results as expected, but the boost function doesn't seem to actually be re-ordering my searches at all. For example, I'm trying to do something like this:
Query query = new SimpleQuery();
Criteria searchCriteria = Criteria.where("title").contains("A").boost((float) 2);
Criteria extraCriteria = Criteria.where("title").contains("B").boost((float) 1);
query.addCriteria(searchCriteria.or(extraCriteria));
In this example I would be searching for any document whose title contains "A" or "B", but I want to boost results that match "A" to the top of the list.
I've also tried using the Extended DisMax Query Parser with a different syntax to achieve the same result, with similar lack of success. To follow the same example pattern, I'm trying to use the expression criteria as follows:
Query query = new SimpleQuery();
Criteria searchCriteria = Criteria.where("title").expression("A^2.0 OR B^1.0");
query.setDefType("edismax");
query.addCriteria(searchCriteria);
Again I would expect this to return documents with titles matching "A" or "B" but boost results matching "A", and again it simply doesn't seem to actually affect the ordering of my results at all.
Okay, I figured out the problem here. Elsewhere in the code someone else had added this snippet:
query.setPageRequest(pageable);
This was done to support pagination of the search results, but the pageable object ALSO contained some sort orders that looks like they got added to the query as part of the .setPageRequest method. Something to look out for in the future, it looks like sorts override boosting when working with Spring Solr queries in this scenario.

Setting pseudo fields (fl) in Solrj

I want to use a pseudo field to return the distance from the center of my solr (geo) spatial search, like it's explained here: http://wiki.apache.org/solr/SpatialSearch#geodist_-_The_distance_function when it says:
Returning the distance
Solr4.0
You can use the pseudo-field feature to return the distance along with the stored fields of each document by adding fl=geodist() to the request. Use an alias like fl=dist:geodist() to make the distance come back in the dist pseudo-field instead. Here is an example of sorting by distance ascending and returning the distance for each document in dist.
...&q=:&sfield=store&pt=45.15,-93.85&sort=geodist() asc&fl=dist:geodist()
Now, I'm using solrj (4.5.1) and I can't find a way to set the fl=_dist_:geodist() part properly. I can actually manage to add it to the solrQuery object doing:
solrQuery.setParam('fl', '_dist_:geodist()')
with no compilation errors, but for some reason this is messing up my returned documents.
Any ideas how it should be done?
Ps. code is in groovy language, don't freak out for no semi-colons or string within single quotes :)
* UPDATE *
Setting the fl param as explained above, actually results in returning documents which only contains the _dist_ field!
After a few minutes of search, i found this article: http://solr.pl/en/2011/11/22/solr-4-0-new-fl-parameter-functionalities-first-look/
It explains how to return the new alias field(s) in addition to all other parameters, simply like this (please note the * part):
fl=*,stock:sum(stockMain,stockShop)
So, in my example for solrj, it will be:
solrQuery.setParam('fl', '*,_dist_:geodist()')

Java HTTP Get Request

I need to make one HTTP GET Request to a Java Web Service:
I'm making this request:
http://127.0.0.1:8080/MyService/services/service?method=myMethod&a=&b=test&startDate=2011-03-10 10:00&endDate=2011-03-10 19:00
When I Debug my app the parameters come with the values switched. I already tried to encode the startDate and endDate parameters but the result is the same.
What am i doing wrong?
You should encode your URLs so they don't contain spaces. This could be your problem. See http://download.oracle.com/javase/1.5.0/docs/api/java/net/URLEncoder.html
As #Mirkules says, you should encode the spaces and colons in the parameter values ... even if you don't think it makes any difference!
Apart from that, maybe your servlet code is expecting Request.getParameters() to deliver the parameters in the order that they appear in the URL. This is not the case. If order of the parameters is significant, you need to parse the query string yourself. (Or consider fixing your web API so that the query parameter order is irrelevant.)

Data Structure to represent a DFA

I was wondering, what would be the best data structure to represent a DFA?
I am looking at converting a regular expression to a DFA and make this particular functionality as a library in Java.
The main thing is that, each entity in the regex carries a set of value rather than a single string value like "car" . In my case , each entity would carry many properties like {car, Honda, 4x4, sedan, ... } (Though I am not searching for cars, this is just an example.)
Any suggestions?
If I understand your question correctly you want to have a matching/filtering library for an arbitrary regular language over an alphabet with dynamic types? Going with your car example, I'd imagine you'd want to be able to create an expression in order to match over a List where all Cars (have the color red, have between 2 and 6 Passengers and each Passenger is between 8 and 88 years of age) or (have 1 Passenger).
Coincidentally I've been looking for something like that myself (for document validation) and the closest I could get was Jing; A Java RELAX-NG library. Unfortunately, the alphabet in Jing consists out of XML nodes so it didn't solve my problem. At the moment I'm attempting to write a library myself which does just this (matching against regular languages over an arbitrary type of alphabet), based on the pattern matching in Jing. If you like to help with this, please let me know ;).
A web search will yield some examples of DFAs in Java. However, the best representation depends on your specific application requirements; e.g. how your application is going to use the DFAs. I think you need to work this out for yourself.
I'm sure this answer won't be useful to the original question because of the data, but if anyone happens across this from google...
DFA's and NFA's can be stored as State transition table's, you then perform a parse by moving thought the table following the links as such.

Categories