firestore finding nested object that contain some properties accross different collections - database

https://stackoverflow.com/a/54857966/10964992 works only for a collection( because it only works for a given collection )
how to get a list of doc across differentt collecion (let say, contain a name attribute and type attribute equal to some value)?
let say we have 2 document in post collection. Each has an apply collection, which have a number of doc (applicants). I want to find that doc that have a specific applicationID.
collection doc collection doc properties
Jobposts ID1 apply APPLICANT1 {"applicationID":XXXXXX}
APPLICANT2 {"applicationID":XXXXXX}
ID2 apply APPLICANT5 {"applicationID":XXXXXX}
APPLICANT7 {"applicationID":XXXXXX}
I dont care about performance.

If you want to search across all apply collections, you can use a collection group query. This will read/query across all collections named apply.
Be sure to study the documentation first, as there are some requirements across your security rules and indexes to make this possible.

Related

Solr function query filter improvementss

I'm trying to filter documents based on all values in a field.
For this I had used a function query in a filterquery.
To explain it.
I have exclusion rules on regions and on countries.
Each document contains the values for which it is excluded.
If exclusion rules exist on regions, do nothing.(the region filter query is a separate one)
If exclusion rules don't exist for region, use the country.
For this requirement I had the filter query below.
fq="!{!df=excluded_region v=$user.region}"
fq={!frange l=0 u=0}and(not(docfreq(excluded_region,$user.region)),termfreq(excluded_country,$user.country))
It works fine except when a region is deleted from the index entirely.(none of the documents still have that value)
The docFrequency is not changed.
I know I could resolve this by segment merging, but this is not possible due to the size of the index.
Also possible by dynamically adding filter statements, but I'd prefer to have these blocking rules in the appends section of the request handlers.
Is there a better way to write this function query?
Is it possible to do a subquery across all documents to check whether a region exists?
Example(s) of how the data is supposed to work:
DocId
excluded_region
excluded_country
Doc A
A1
BE
Doc B
A2
BE
Doc C
A3,A1
BE
Doc D
A3,A1,A4
BE
If for example the user has country BE and region A5(not existing in any document), nothing is returned.
If he has region A1, document B is the only returned document.

Solr query multiple collections

I have multiple collections with different fields in the schema, I would like to perform a search across multiple collections and perform default rank for results across all the collections .
Example - I have a document with ‘mustang’ word occurring 3 times in collection A and also 2 times in Collection B , then I would like the results to show both the documents with the document from collection A first and document from collection B as second result.
Scoring doesn't only take the number of occurrences into factor, so by default it'll also depend on the number of documents containing that term in the collection as well. If we're talking about a single term, you can sort by the tf function or something like that - for more complex queries, using collection wide term frequencies may be the only option (but may be costly).
To create one common collection that queries both, use the CREATEALIAS command in the Collections API. The collections parameter takes a comma separated list of collections that is represented by the alias, allowing you to query both A and B through the alias C.

Solr : Boost Results from a specific collection

We have solr index which has multiple collections i.e. collection_data_sales and collection_data_marketing. So when the user performs a search query, both the collections are queried upon using collection alias. Both collections have same solr schema.
Is there a way to boost the result from a specific collection ?
i.e. Suppose user specifies collection sales data, then search should happen on both collection_data_sales and collection_data_marketing but boost should be given for documents from collection_data_sales.
If you are able to differentiate both collections using data from it it will be enough. Lets imagine that in schema you have field type so for collection_data_marketing you have type:marketing and for collection_data_sales you have type:sales.
The only thing now you have to do is to use boost function like for example this:
bf=sum(product(query($q1),10), product(query($q2,3)))&q1=type:sales&q2=type:marketing
In this example sales will have weight 10 and marketing will have weight 3

MongoDB - get all documents with a property that is saved in a list in a document of another collection

I have documents in a collection that have an array of properties (1-400 different numeric values).
Now i want to get all documents of another collection that have one of these properties (these documents only have one property).
How can i do that, preferably in one call?
As MongoDB is no relational DBMS this isn't possible to achieve with only one call.
What you need to do is to first retrieve your document your want to use for your search. Upon you retrieved it, you're using that array stored in the document todo a $in query on the field for the other collection. So for the mongo shell this could be something like this:
var ar = db.coll1.findOne().numArray
db.coll2.find({b: { $in : ar }})

SOLR: Is it it possible to index multiple timestamp:value pairs per document?

Is it possible in solr to index key-value pairs for a single document, like:
Document ID: 100
2011-05-01,20
2011-08-23,200
2011-08-30,1000
Document ID: 200
2011-04-23,10
2011-04-24,100
and then querying for documents with a specific value aggregation in a specific time range, i.e. "give me documents with sum(value) > 0 between 2011-08-01 and 2011-09-01" would return the document with id 100 in the example data above.
Here is a post from the Solr User Mailing List where a couple of approaches for dealing with fields as key/value pairs are discussed.
1) encode the "id" and the "label" in the field value; facet on it;
require clients to know how to decode. This works really well for simple
things where the the id=>label mappings don't ever change, and are
easy to encode (ie "01234:Chris Hostetter"). This is a horrible approach
when id=>label mappings do change with any frequency.
2) have a seperate type of "metadata" document, one per "thing" that you
are faceting on containing fields for id and the label (and probably a
doc_type field so you can tell it apart from your main docs) then once
you've done your main query and gotten the results back facetied on id,
you can query for those ids to get the corrisponding labels. this works
realy well if the labels ever change (just reindex the corrisponding
metadata document) and has the added bonus that you can store additional
metadata in each of those docs, and in many use cases for presenting an
initial "browse" interface, you can sometimes get away with a cheap
search for all metadata docs (or all metadata docs meeting a certain
criteria) instead of an expensive facet query across all of your main
documents.

Resources