Indexing and search by dynamic fields and values in solr - search

I need help indexing this data in solr.
Assume that i have this kind of a students database. I want to index this data in solr and want to be able to search by tested subjects and their percentile. The subjects that the student has taken might differ among students and its not a fixed schema. So, i cant have the subject name as a field name.
I tried exploring dynamic fields but cant seem to be figure out how will i query by the percentile scored.
E.g. i want to filter by all students who have been tested for Math, but only have fared 90 percentil or higher. I also independently want to search by City, name or a combined query between name, address and the tested subjects and their percentil.
{
Name: Max Junior,
Address: Twin peaks
City : ,San francisco,
Grade: 1,
Subjects: ["Math", "Science", "English"]
Tested Subjects:
[
{name: Math, percentile: 95},
{name: Science, percentile: 85}
]
},
{
Name: Alicia Alex,
Address: Nob Hill,
City: San Mateo,
Grade: 1,
Subjects: ["Math", "English", "Craft"]
Tested Subjects:
[
{name: Math, percentile: 65},
{name: Science, percentile: 78}
]
}
Any help is greatly appreciated.
Thanks a lot

I assume you have some unique ID to identify different subjects. For instance Maths subject as 1234, science as 2345. In that case you can index the Math percentile against subject1234_i (assuming percentile in integer value). You can then query for this field as
subject1234_i:[90 TO *]
Refer to Solr query syntax
Other fields like Name, City can be defined as static as those seems common for each student.

Related

is there a way to pull only the name of the fields in a document in mongodb using mongoose

my website takes a dataset and the dataset contains data about a students or employees..etc, so I want to display the column names to the user.
Is there a way to pull the fields name?
ex:
Name, Age, Country
String, Number, String
Fahad, 13, riyadh
Jane, 27, United Kingdom
Andrew, 29 , United States
Mary, 19 , France
I want to display "Name" "Age" "Country" to the user
I'm using node.js mongoose.
If your documents have similar structure, why not just
Object.keys(db.your_collection.findOne())
for more accurate u need use the lean() method because it will
POJO values else it will return mongodb instance keys instead of document keys.
Object.keys(db.your_collection.findOne().lean())

Joining multiple Table using sequelize

I have 4 table t1,t2,t3,t4 in a POSTGRESQL database. Each of the table contains 3 common field, "currency" eg INR DOLLAR etc, "debt" eg 12006 , "credit" eg 1000. Credit and debt are integers.
Each table contains multiple entries of every currency possible
I want the sum of debt and credit of each currency across all the 4 tables
currency
debt
credit
INR
12006
1000
DOLLAR
50002
3012
yen
1234
12546
I'm using sequelize, there's no realtion between any 4 tables, I'm only able to add credit and debt of 1 table at a time using this
var a = await asset.findAll({
attributes: ['currency',[sequelize.fn('SUM', sequelize.col('credit')),
'credit'],
[sequelize.fn('SUM', sequelize.col('debt')), 'debt']
],
group: ['currency'],
});
can someone please guide me how can I make a complete outer join using sequelize preferably else raw query would also work

Referencing Documents between 2 MongoDB Collections

I'm building an app where employees can be added to the database and each employee belongs to a particular company, which can be chosen from a select field on the form. The form to add employees also contains a salary field and I would like to be able to display the companies with their total salary expense (based on the sum of salaries of its employees).
At first, I imagined I would use a single "employees" collection. Then, for example, choose "Apple" as the company, and finally, in the end, I would end up with a list of employee objects where I can loop through all the employees where "Apple" was the company and sum all the salary fields. This ended up being a poor approach. Next, I decided to create a separate collection of "companies". Then, before saving an employee, I look up the company object ID, and save that as the company.
For instance,
{ firstName: "Bob", lastName, "Smith", company: "5b62a456e7179a07334478a5", salary: 7}
Where "5b62a456e7179a07334478a5" is the "_id" field of Apple.
How do I continue to define this relationship in MongoDB?
Do I add an employees field to each company and try to save each employee to a company upon saving them to the employee's collection? In this way, I can try to access the sum of all employees within each company to obtain a total salary expense.
But I would then have to write to two different collections each time a new employee is saved. Also, what would the flow of that even look like? I would need to use the company _id field to look up the company and then save the employee to the company. So, would I have to perform a query and two writes on each new employee save?
You can use the lookup feature to do a "join"
db.table1.aggregate([{
$lookup: {
from: "table2",
localField: "table2column",
foreignField: "table1key",
as: "alias"
},
{
$project:{
//columns you want
}
}
}])
That being said...if your data is relational and not obscenely huge, a relational database might be a better choice.

How would I use HashTable or HashMap to count?

For example, given the data
Name: 1234, Qty: 100
Name: 1234, Qty: 100
Name: 1234, Qty: 100
Name: 1234, Qty: 200
Name: 1234, Qty: 200
The expectation is:
Name: 1234, Qty: 700
The basic idea is that you repeatedly find the name-specific cumulative sum in the hashtable, adding the next value to it. In pseudo-code:
for name, qty in input
hashtable[name] += qty
Depending on your language, you may have to explicitly check whether there's an existing hashtable entry for "name" and create one with the initial "qty" value.
In a HashMap, a key can only be associated with one value, so you will need to use a HashMap<Integer, List<Integer>> or a MultiMap to achieve this.

How to normalize this table inventory

I have this excel sheet and I want to migrate it to Access (in the near future some other DB manager) And I don't know how to normalize it exactly, I know this might be very opinion base. Currently they use this table for inventory
This is the original Table (sheet)
"TableName: Parts", Fields:"Id_Part", "No_Part", "No_Mold", "No_Lot", "Rev", "Description", "Area", "No_Job", No_Batch,"OrderDate","RecivedDate"
Explanation of problem:
ok the idea is to create a DB that stores all the part numbers the "x" company has, these part numbers have the corresponding field:
1.- Id_Part : is the unique number for each part.
2.- No_Part: Number part of each part that the company uses for there products.
3.- No_Mold: Each Part Number uses a Molding Item, some part numbers use the same Molding Item.
4.- No_Lot: The Lot Number is to keep track of the part numbers in case the client has some issues with the final product. (Its like a tracking number).
5.- Rev: is for Revision control example: A, B or C.
6.- Description: Describes the part number.
7.- Area: name of the department in with the part number is used ( like a type of Part Number).
8.-No_Batch: Its similar to the Lot number, but its an internal number for the company.
9.- Order Date: Date in witch we ordered a part number form a provider.
10.- Received Date: Date when we get that part number from the provider.
This is how I tried to Normalize it
Table1 Name: Parts
Fields: Id_Part, No_Part, Id_Mold, Id_Lot, Id_Rev, Id_Description, Id_Area, Id_job,
Id_Batch, Date_Order, Date_Recived.
Table2 Name: Areas
Fields: Id_Area, Name
Table3: Molds
Fields: Id_Mold, No_Mold, Id_Part
Table4:Jobs
Fields: Id_Job, No_Job
Tablr5:Batchs
Fields: Id_Batch, No_Batch
Table6 Name: descriptions
Fields:Id_Description,Description,Id_Part
Table7 Name:Rev
Fields: Id_Rev,Rev,Id_Part
Any help is useful.
It seems like the PartRevision is the main table here rather than the part. You don't order a Honda Accord, you order a 2013 Honda Accord.
You purchase a PartRevision and it goes into a batch and a lot. You sell a part revision and it pulls from a batch and a lot. Here's how I'd set it up.

Resources