I'm trying to implement a filtering query parameter for my collection resource but I'm not sure on the best way to handle the query parameter. If I have a request like:
http://test.app/users?created_at>=2016-10-01
The resulting query parameter is:
{"created_at>":"2016-10-01"}
And if the request is:
http://test.app/users?created_at>2016-10-01
The resulting query parameter is:
{"created_at>2016-10-01":""}
Are there any existing solutions to handle these types of query parameters?
It's a bad practice to pass these type of operators via query string.
Use this format in your query string (citate from http://www.tldp.org/LDP/abs/html/comparison-ops.html):
gt (greater than)
ge (greater than or equal to)
lt (less than)
le (less than or equal to)
In your case, it should be like this: http://test.app/users?created_at[ge]=2016-10-01 or this: http://test.app/users?created_at=2016-10-01&comparison=ge
Related
I have a DynamoDB table with animals and I'm interacting with it using Dynamoose. My table has a 'UserId' attribute, that indicates the user that registered that animal. I want to write a query that finds all the animals registered by the same user, i.e., gets all the items that have the attribute 'UserId' matching the input string.
I'm trying to use Dynamoose's queries like this MyModel.query('UserId').eq(user.id).using('UserId-index').exec();, but it always gives this error Index can't be found for query. I imagine that this is caused because it is not finding the index for the attribute 'UserId', but I have an index 'UserId-index' on my table.
I also tried specifying the index that should be used on the query with the using() method, like this MyModel.query('UserId').eq(user.id).using('UserId-index').exec();, but it gave me this other error: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request, which I don't get at all.
Note that I don't wanna use scan(), as the official documentation highly encourages the developers to use query() instead.
I need the result of the first query to pass it as an input parameter to my second query. and also want to know to write multi queries.
In my use case, the second query can be traversed only using the result of the first query and that too using loop(which is similar to for loop)
const query1 =g.V().hasLabel('Province').has('code',market').inE('partOf').outV().has('type',state).values('code').as('state')
After executing query1,the result is
res=[{id1},{id2},........]
query2 = select('state').repeat(has('code',res[0]).inE('partOf').outV().has('type',city).value('name')).times(${res.length-1}).as('city')
I made the assumptions that your first query tries to finds "states by market" where the market is a variable you intend to pass to your query. If that is correct then your first query simplifies to:
g.V().hasLabel('Province').has('code',market).
in('partOf').
has('type','state').values('code')
so, prefer in() to inE().outV() when no filtering on edge properties is needed.
Your second query doesn't look like valid Gremlin, but maybe you were just trying to provide an example of what you wanted to do. You wrote:
select('state').
repeat(has('code',res[0]).
inE('partOf').outV().
has('type',city).value('name')).
times(${res.length-1}).as('city')
and I assume that means you want to use the states found in the first query to find their cities. If that's what you're after you can simplify this to a single query of:
g.V().hasLabel('Province').has('code',market).
in('partOf').has('type','state').
in('partOf').has('type','city').
values('name')
If you need data about the state and the city as part of the result then consider project():
g.V().hasLabel('Province').has('code',market).
in('partOf').has('type','state').
project('state','cities').
by('code').
by(__.in('partOf').has('type','city').
values('name').
fold())
I have a Lucene index where one of the indexed fields contains a string that identifies the type of content.
For simplicity, say this field is called _type and will only ever contain typeone or typetwo.
I am using Lucene query parser syntax to query this index. Say my query is:
(+fieldone:term^3.0 +classname:term^2.0)
Is it possible to extend this to boost any results that have typeone in their _type field, whilst still returning typetwo records (albeit with a lower relevancy score)?
UPDATE
I've found a syntax which works but it uses the wildcard 'all documents' syntax which I suspect is not efficient. Advice appreciated.
(+fieldone:term^3.0 +classname:term^2.0) +(*:* _type:typeone^1.1)
Using just Lucene syntax you can simply keep the _type boost as SHOULD in the following way:
+fieldone:term^3.0 +classname:term^2.0 (_type:typeone)^2
you don't need wildcards.
Another solution would be using eDismax query parser then you can use the bq or bf parameter in order to boost a particular value for a field. You can use one of the following solutions:
Solution 1: you can boost your term in the following way:
defType=edismax&bq=_type:"typeone"^3
or
Solution 2: you can use a query function in the following way:
defType=edismax&bf=if(termfreq(_type,"typeone"),3,if(termfreq(_type,"typetwo"),2,1))
where the results having _type=typeone are boosted by 3, the ones having typetwo are boosted by 2, otherwise it will be 1. You can modify that query according your needs.
Variation 1:
file.jsp?parameter1=¶meter2=abc
Variation 2:
file.jsp?parameter1¶meter2=abc
I know Variation 1 is considered valid, but is variation 2 considered valid? Specifically, there is no value for the parameter, is the equals sign required in this case?
I think it is valid to have query parameter with just the parameter name.
If you are familiar with Java, Look at the #see UriComponentsBuilder QueryParam function, by default it does this for any query parameter with null.
If no values are given, the resulting URI will contain the query
parameter name only (i.e. ?foo instead of ?foo=bar.
See this answer for more info.
Is a url query parameter valid if it has no value?
I am trying to perform queries using the OR operator as following:
MapReduceResult result = riakClient.
mapReduce("some_bucket", "Name:c1 OR c2").
addMapPhase(new NamedJSFunction("Riak.mapValuesJson"), true).
execute();
I only get the 1st object in the query (where name='c1').
If I change the order of the query (i.e. Name:c2 OR c1) again I get only the first object in query (where name='c2').
is the OR operator (and other query operators) supported in the java client?
I got this answer from Basho engeneer, Sean C.:
You either need to group the terms or qualify both of them. Without a field identifier, the search query assumes that the default field is being searched. You can determine how the query will be interpreted by using the 'search-cmd explain' command. Here's two alternate ways to express your query:
Name:c1 OR Name:c2
Name:(c1 OR c2)
both options worked for me!