lucene .net parser for filter and sorting - lucene

In our lucene .net based search (Lucene 4.8.0-beta00016) we save the generated query, the filter and the sorting in a custom text file.
e.g.:
"Query":"+name:*test*"
"Filter":"BooleanFilter(+type:project)"
"Sort":"<long: \"creationdate\">!"
We built a test tool, similiar to Luke and we want to execute this saved search there and run a programmatic search:
For the query I can use the QueryParser and get the corresponding query object, but there seems to be no parser for the filter and the sort.
var queryParsed = new QueryParser().Parse("+name:*test*");
var filter = ?
var sort = ?
indexSearcher.Search(queryParsed, filter?, 10000, sort?);
Is there any way I can parse the filter and sort strings to a Filter/Sort object ?

Have you ever thought to serialize your custom file in a different way?
I'm guessing your file is generated by calling the toString() method of each object type. Something like the follow
"Query:" + queryObject.toString()
"Filter:" + filterObject.toString()
"Sort:" + sortObject.toString()
If you serialize your original query, filter, and sort .NET objects as binary strings, in your test tool, you should be able to re-create the original .NET objects.
Look at https://learn.microsoft.com/en-us/dotnet/standard/serialization/

Related

How can we write karate code inside karate loop? [duplicate]

I need to loop a string (split by ',') and get each element passed to the feature files automatically. I know there is excellent support for json array data-driven test, but does it support data-driven with normal strings or string array
As I know, I need to get it converted to a json array to support data-driven test at runtime, however, I want to know any existing support for normal array looping directly and automatically.
Here is my string(separated by ',') that needs to get passed as request parameter:
"PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT"
Because my string is dynamically produced at runtime, I want to loop it automatically and pass to other feature files, not manually,
Note that converting arrays into other "shapes" is easy in Karate. And in 0.9.3 we introduced the karate.mapWithKey() API, so you can do this:
* def string = 'PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT'
* def array = string.split(',')
* def list = karate.mapWithKey(array, 'name')
* print list
So you can see, list is ready to use for data-driven features. Also note that you can use this in dynamic scenario outlines !

for the data-driven feature, doest it support an normal array looping, not json array?

I need to loop a string (split by ',') and get each element passed to the feature files automatically. I know there is excellent support for json array data-driven test, but does it support data-driven with normal strings or string array
As I know, I need to get it converted to a json array to support data-driven test at runtime, however, I want to know any existing support for normal array looping directly and automatically.
Here is my string(separated by ',') that needs to get passed as request parameter:
"PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT"
Because my string is dynamically produced at runtime, I want to loop it automatically and pass to other feature files, not manually,
Note that converting arrays into other "shapes" is easy in Karate. And in 0.9.3 we introduced the karate.mapWithKey() API, so you can do this:
* def string = 'PHE,TSH,17_a_OHP,G6PD,MSMS,THALASSEMIA,DGT'
* def array = string.split(',')
* def list = karate.mapWithKey(array, 'name')
* print list
So you can see, list is ready to use for data-driven features. Also note that you can use this in dynamic scenario outlines !

Use encoded object query param for GET request

While designing the API with with the team a suggestion was forwarded in regards to some complex query parameters that we sent which need to be encoded as objects, arrays of objects, etc. Suppose I have a route GET /resource/ and I want to apply a set of filters directly in the query params. The object literal structure of this filter would be something like
filter: {
field1: {
contains: 'value',
notin: ['value2', 'value3']
},
field2: {
greaterThan: 10
}
}
Encoding this in the url, via a query string parser such as the qs node module that express.js uses internally, would be cheap on the backend. However 1) The generated url is very hard to read, if a client wants to connect with the API he would need to use an encoding library and 2) I don't think I ever encountered the use of query params like this, it looks a little bit of overengineered and I'm not sure how used it is and if it is really safe.
The example above would yield query params such as:
GET /resource/?field1%5Bcontains%5D=value&field1%5Bnotin%5D%5B0%5D=value2&field1%5Bnotin%5D%5B1%5D=value3&field2%5BgreaterThan%5D=10
Does this practice of sending url query parameters that happen to be complex objects have some standards or best practices?
We implemented a different solution for filtering, when the list of possible parameters was very long. We ended up doing it in two steps, posting the filter and returning a filter ID. The filter ID could then be used in the GET query.
We had trouble finding any best practices for this.

What's the best way to wrangle path patterns in Restkit

I'd like to be able to specify a string, let's say
NSString * pathPattern = /api/elements/:id/subelement/:type
and call a simple function
[pathPattern build:#{#":id" => id, #"subelement" => subelement}]
to generate the URL path.
Obviously I can build a simple category to do this, but does something exist that handles such things in a generic way, and maybe has additional useful features for this kind of thing that I haven't thought of at this time?
Yes, RestKit already injects parameters into path patterns. Internally it uses SOCKit to perform this parameterisation.
It actually uses exactly the format you have in the question and where the parameter names match keys on the supplied object for mapping.
The path pattern can also be used during response mapping to take values back out of the request URL.

Lucene: build a query by tokenizing a string and pass

I need to extract single terms from a string to build a query using BooleanQuery.
I'm using QueryParser.parse() method for it, this is my code snippet:
booleanQuery.add(
new QueryParser(
org.apache.lucene.util.Version.LUCENE_40,
"tags",
new WhitespaceAnalyzer(org.apache.lucene.util.Version.LUCENE_40)
).parse("tag1 tag2 tag3"),
BooleanClause.Occur.SHOULD);
I'm however wondering if this is correct way to pass single terms to booleanQuery.
QueryParser.parse method returns a SrndQuery object, which I directly pass to booleanQuery.add() method.
Not sure if this is correct. Should I extract single terms instead from SrndQuery... or something like that, and invoke booleanQuery.add() several times ?
Update: printed query
*.*:*.* title:Flickrmeetup_01 description:Michael description:R. description:Ross tags:rochester tags:ny tags:usa tags:flickrmeetup tags:king76 tags:eos350d tags:canon50mmf14 tags:mikros tags:canon tags:ef tags:50mm tags:f14 tags:usm tags:canonef50mmf14 tags:canonef50mmf14usm
I believe you should extract the tokens, wrap each one in a Term, then create a TermQuery for it, then add the TermQuery to the BooleanQuery. SrndQuery is abstract anyway, so I guess your current code would create an instance of a subclass, which is probably not what you mean to do. You may want to create your own custom QueryParser for this.