I am having trouble figuring out how to Filter a large list twice and display the results in a ListBuilder. Can someone please tell me the best way to go about do this? Here are the details.
First is an example of the data. I would like to first Filter the list by matching the Product Code which is index /element 12. Then I would like to filter the results from the first search to those items that only have a 'N' in the first 11 elements IF the user selected that they don't want that particular feature of the item. Then display the results in a list.
So, in other words. Filter first by a product category code number 1-12 and second by the product characteristics Y or N. Then display each of the items in a List.
It sounded easy when I started but either I'm missing something or I just don't get it. I did have items displaying the search results but they were not matching the search criteria. Now, I have it all messed up so I'm really just looking to understand the best approach for doing this. So, the user first picks their Category and then on the next screen selects the characteristics to exclude from the final results.
Here is an example of the data.
'''
class CatIngBrain {
final List<CatIng> catIngBank = [
CatIng( "N", "Y", "Y", "Y", "Y", "Y",
"Y", "Y", "Y", "Y","Y", "Y", "1", ‘MAYNARD’, ‘’, ''),
CatIng( "N", "Y", "N", "N", "Y", "N",
"Y", "N", "N", "N","Y", "N", "2", ‘BLESSED EVENT’, '', ‘’, ),
CatIng( "N", "Y", "Y", "Y", "N", "N",
"Y","N", "N", "N", "Y", "N", "3", "GLOBE", '', ''),
The Constructor is setup to match the fields since it is not in Key:Value pairs like alot of the examples I see.
class CatIng {
String ingAcr; //0
String ingBen; //1
String ingCar; //2
String ingFor; //3
String ingFra; //4
String ingPab; //5
String ingPar; //6
String ingPet; //7
String ingPht; //8
String ingSil; //9
String ingSul; //10
String ingTol; //11
String ingCatCode; //12
String prodName; //13
CatIng(
this.ingAcr, //0
this.ingBen,//1
this.ingCar,//2
this.ingFor,//3
this.ingFra,//4
this.ingPab,//5
this.ingPar,//6
this.ingPet,//7
this.ingPht,//8
this.ingSil,//9
this.ingSul,//10
this.ingTol,//11
'''
Edit, just focusing on the first filter, which I think is my problem:
The Filter I am using on the above for the Product Category is
''' final Iterable<dynamic> ingsToFilterList =
catIngBrain.catIngBank.where((e) => e.ingCatCode ==
passedIngCatCode).toList();'''
This is just to filter the Category. It returns [Instance of 'CatIng', Instance of 'CatIng'] but when I display the return in the list, it does not display the correct index for the two index items that do contain the correct category code.
Thanks for any suggestions
U can check this sort
List.sort() example
same question in StackOverFlow kinda
I was able to get the Product Category to search correctly by using this:
''''
'''
final ingsToFilterList = catIngBrain.catIngBank.where((catIngs) =>
catIngs.ingCatCode == passedIngCatCode).toList();
setState(() => catIngs = ingsToFilterList);
'''
Unfortunately, I have not been able to get the next filter level to work yet.
Related
I have two lookups within an Until activity in ADF. The first lookup (BookList) is a list of books that look like the JSON listed below.
[
{
"BookID": 1,
"BookName": "Book A"
},
{
"BookID": 2,
"BookName": "Book B"
}
]
The second lookup is a list of books that I want to exclude from the first list (ExcludedBooks) which is listed below.
[
{
"BookID": 2,
"BookName": "Book B"
}
]
After these two lookups, I have a Filter activity whose items are the values from BookList lookup. I would like the filter condition to be based on the BookID value not being listed in the ExcludedBooks values, but I'm not sure how to write this condition based on the collection functions in ADF. What I have is listed below which does not work.
#not(contains(activity('ExcludedBooks').output.value, item().BookID))
I realize one way to solve this is to loop through each record of the ExcludedBooks and use a SetVariable
activity to build an array of BookIDs which WOULD work with the collection function Contains(), but ADF does not allow nested activity groups for some reason (ForEach within an Until).
I also cannot set the list of excluded books outside of the Until activtity as it will change with each iteration of the Until activity. I also realize the workaround to the nested group activity restriction is to create a completely different pipeline, but that is not ideal and creates unnecessary complexity when trying to return the results.
Does anyone have any suggestions for how to filter the results of a lookup based on the results of another lookup?
Below expression doesn't work because item of activity('ExcludedBooks').output.value is object,item().BookID is number.
#not(contains(activity('ExcludedBooks').output.value, item().BookID))
If your each item in ExcludedBooks is the same as your item in BookList(like your provide sample),you can use this expression:#not(contains(activity('ExcludedBooks').output.value, item())).
My test result:
For another hand,if your item in ExcludedBooks like this json(BookList is the same as your provided):
[
{
"BookID": 2,
"BookName": "Book B",
"num": 22
}
]
you can only compare their BookID by using this expression:
#not(contains(join(activity('ExcludedBooks').output.value,','),concat('"BookID":',item().BookID,',')))
(cast activity('ExcludedBooks').output.value to string,concat item() in 'BookList' as "BookID":2, and check whether 'ExcludedBooks' string contains 'BookList' item string)
My test result:
Hope this can help you.
I have a json response with a list of strings. I want to check if it contains the same elements as some other list (order of those elements isn't important. How do I do that?
I tried this:
jsonPath("$.country_codes[*]").findAll.sorted.is(List("DE", "CH", "FR", "IE", "IT", "NL", "RS", "UK", "IN").sorted)
but I'm getting error "Cannot resolve symbol sorted". If I don't use 'sorted', it works, but I can't rely on getting the same order of elements from server each time..
Use transform to turn your Seq[String] into a Set[String] or sort it.
I have a question, lets say I have a collection called contact :
[
{"firstName": "Adam", "lastName":"Peter", "email":"adam#peter.com"},
{"firstName": "Adam", "lastName":"John", "email":"adam#john.com"},
{"firstName": "Adam", "lastName":"Petkovic", "email":"adam#petkovic.com"}
]
What I want is to search specifically, for example: I want to search "Adam peter" then I want to have a result of the first one ONLY which has Adam and peter.
I use meteor + mongo + react for my application.
Any suggestion / recommendation would be high appreciated.
Thanks for all the answers, but probably I need to ask more specific in order to get more appropriate answer.
Scenarios:
I only have 1 text box to search all the fields.
So:
when I enter "Adam", I expect to have 3 results. but when I enter "Adam Peter" I expect to have 1 result only.
When I enter "peter.com" it should have 1 result
When I enter "John", it should have 1 result
When I enter "Adam Pet" it should have 2 results.
From the answer here, below query should work fine.
db.contacts.find( { firstName: /^Adam$/i, lastName: /^peter$/i });
The query in MongoDB is case sensitive, if you want to query contact by ignoring case, you should use a regular expression, but it may not efficient.
db.contact.findOne({firstName: /^adam$/i, lastName: /^peter$/i})
it will much better if you always save these name value in lowercase, and query in lowercase
db.contact.findOne({firstName: 'adam', lastName: 'peter'})
Assuming that the rules that you are applying are:
If a single word, then that could match any field
two words mean "firstname surname"
In that case, you can't use text indices, but instead need to do some work before the mongo search.
First, split the words on whitespace, and then determine if there are one or two words. If there is one word, check that against all fields. If there are two, then only check the first word against the first name, and the second against the lastname.
// assuming input is in variable call 'term'
var words = term.trim().split(/\s+/) || [];
if(words.length === 0) {
return;
}
var first = new RegExp(words[0], 'i');
if(words.length === 2) {
var second = new RegExp(words[1], 'i');
return Contact.find({firstName: first, lastName: second});
else if(words.length === 1) {
return Contact.find({$or: [ {firstName: first}, {lastName: first}, {email: first}]})
}
Also, depending on how large your collection is, it might be better to wrap this up into a Meteor method, so that the search takes place on the server. Otherwise, you will have to publish the whole collection on the client to be able to do the search. That might be fine for a small collection though.
UPDATE:
Based on your examples, I think your rules are:
1. Search terms are combined with AND operator (e.g. Adam Pet returns two rows, not three).
2. Search terms use regular expression matching (Pet matches even though it's not any of the words).
Rule 2 means that text indices won't work, so you will need to build up a complex regex query document using $and and $or for each item:
// assuming input is in variable call 'term'
var words = term.trim().split(/\s+/) || [];
var query = {
"$and": []
};
words.forEach(function(token) {
var reg = new RegExp(token);
var innerQ = {"$or": [ {firstName: reg}, {lastName: reg}, {email: reg}]};
query["$and"].push(innerQ);
});
return Contact.find(query);
I have the following list:
List(
(List("vmname"),"myNetwork3",10,"vSwitch0",List(),"192.168.20.2","cisco WS-C3560E-48PD","GigabitEthernet0/43","sky"),
(List("vmname"),"myNetwork",0,"vSwitch0",List("name1", "name2", "name3", "name4"),"192.168.20.2","cisco WS-C3560E-48PD","GigabitEthernet0/43","sky")
)
And I want to find string "name1" in list element of list.
I want following output:
(List("vmname"),"myNetwork",0,"vSwitch0",List("name1", "name2", "name3", "name4"),"192.168.20.2","cisco WS-C3560E-48PD","GigabitEthernet0/43","sky")
How to get above output using scala?
l.filter(._5 contains "name1")
Return all entries with "name1" in the list that is the 5th element of each entry
I am currently thinking about how to structure data for a node.js app i will be developping.
I am thinking of using Mongo as database, but cannot think of a good way to accomplish what I want. All my researches led me to cross-documents references, but this is not what i am looking for, as everything lies in my 'event' document.
My document consists in an event in which people take part that can be represented like that :
{
name: "Some event name",
people: ["A", "B", "C", "D", ... ], // Could be more complex objects, with name, mail for instance
actions : [
{
name: "Some action name"
someAttr: 4.21
leader: "A" // One of people
followers : ["A", "B", "D"] // from people too
},
...
]
}
As you can see, the people are repeated in the document. They can be repeated numerous times as each event will gather lots of actions.
Should I keep my schema this way, or is there something more clever to do such as referencing people from the actions with the index of the global people list with something like that ?
{
name: "Some event name",
people: ["A", "B", "C", "D", ... ],
actions : [
{
name: "Some action name"
someAttr: 4.21
leader: 0
followers : [0, 1, 3]
},
...
]
}
If so, what is the smartest way to accomplish that ?
Thank you very much
Note : This is a theoretical question, and I am a beginner in the Mongo and node.js world
The question "linking or embedding" has been discussed multiple times. A good start for your resaerch can be this question.
EDIT:
If (as you said) people are complex objects, than you should reference them by an id or a name. It makes no sense, to store the (complex) objects twice (or more) in the same document.