Function for `fq` field of SOLR in SOLR-node-client - node.js

For various fields such as q , start , row etc in SOLR we have corresponding functions in SOLR-node-client.
So if I want to construct a query for the following:
http://host:port/solr/eposro/select?q=cats.0%3A1&start=0&rows=4&wt=json&indent=true
I can use something like this:
var query = client.createQuery()
.q({cats.0 : 1})
.start(0)
.rows(4);
However, there is a filter query field in SOLR, fq. I don't seem to find a corresponding function for this in SOLR-node-client.
Following gives me error:
var query = client.createQuery()
.q({cats.0 : 1})
.fq({'brand':'real'})
.start(0)
.rows(4);
I get an error saying that fq function doesn't exist.
Am I doing anything wrong or is there any other way to achieve filter query using SOLR-node-client?

createQuery() returns a Query object and it has a matchFilter method.
Example:
var query = client.createQuery()
.q({cats.0 : 1})
.matchFilter('brand', 'real')
.start(0)
.rows(4);
HTH

I have checked a bit the source code and found out:
So, the usage should be like,
let searchQuery = solrClient.query()
searchQuery = searchQuery.fq({field:"tags",value: this.filterTag});
If anyone can update the doc, that would be great.

Related

Get multiple documents from collection using nodejs and mongodb

Hi I have two mongodb collections. The first one returns json data (array) and with the output of this, I want to return documents that match.
When I run Console.log (req.bidder.myBids) I get the following output:
[{"productId":"3798b537-9c7b-4395-9e41-fd0ba39aa984","price":3010},{"productId":"3798b537-9c7b-4395-9e41-fd0ba39aa984","price":3020},{"productId":"4c4bd71c-6664-4d56-b5d3-6428fe1bed19","price":1040},{"productId":"4c4bd71c-6664-4d56-b5d3-6428fe1bed19","price":1050},{"productId":"4c4bd71c-6664-4d56-b5d3-6428fe1bed19","price":1060},{"productId":"4c4bd71c-6664-4d56-b5d3-6428fe1bed19","price":1070},{"productId":"4c4bd71c-6664-4d56-b5d3-6428fe1bed19","price":1090},{"productId":"4c4bd71c-6664-4d56-b5d3-6428fe1bed19","price":1100}]
The productId has duplicates, I want to remove duplicates and then call a routine that finds all the products that match and output as json.
So far I have this code that only outputs one document, but cant figure out how to add the array of productId's and then fetch all corresponding products.
var agencyId = req.body.agencyId;
var productId = req.body.productId;
if (!validate.STRING(agencyId)) {
res.apiError(messages.server.invalid_request);
} else {
dbProduct.find({productId:{$in:['3798b537-9c7b-4395-9e41-fd0ba39aa984','4c4bd71c-6664-4d56-b5d3-6428fe1bed19']}
}).then(dbRes => {
console.log(dbRes);
Updated code and works with hard-wired productId and updated above code. Looking at how to get the array data and transpose replacing the hard-wired productId's
The $in operator is what you want. See the docs here: https://docs.mongodb.com/manual/reference/operator/query/in/

ArangoDB Dynamic AQL String Handler

Is it possible to use the aql string handler in ArangoDB to perform a dynamic query? I've tried a number of different ways but it always errors out. For example, I'd like to do something like this:
let sortExpression = sortByDate ? 'SORT ${date}' : `SORT ${name}`
const result = db._query(aql`
FOR doc IN tickets
${sortExpression}
RETURN doc
`)
This example is very simplified, but I have a more complex situation where something like this would be really handy. Is there a way to make something like this work?
If the query was more complex, and I had real variables to embed, I'd write this like the following:
let sortProp = sortByDate ? 'date' : 'name';
var query = aql`
FOR doc IN tickets
SORT #SORT_PROP#
RETURN doc`;
query.query = query.query.replace('#SORT_PROP#', sortProp);
var result = db._query(query);
Maybe this works for your use case, too.
After looking more closely at how the aql string handler works, it turns out what I'm trying to do is just not feasible with it. So I decided to use the regular bind var syntax:
let sortExpression = 'SORT #sortField'
const result = db._query(`
FOR doc IN ##coll
${sortExpression}
RETURN doc
`, {
'#coll': module.context.collectionName('tickets'),
'sortField': sortByDate ? 'date' : 'name'
})
Again this is overkill for the simple example above, but my real world query is much more complex.

Highlighter.net returns no matches

I am using lucene.net 2.9.4 and lucene.net contrib 2.9.4 my lucene query looks like:
+contents:umbraco*
I get results for this query. My highlighter code to get fragments looks like:
public string GetHighlight(string value, string highlightField, IndexSearcher searcher, string luceneRawQuery)
{
var query = GetQueryParser(highlightField).Parse(luceneRawQuery);
var scorer = new QueryScorer(searcher.Rewrite(query));
var highlighter = new Highlighter(HighlightFormatter, scorer);
var tokenStream = HighlightAnalyzer.TokenStream(highlightField, new StringReader(value));
return highlighter.GetBestFragments(tokenStream, value, MaxNumHighlights, Separator);
}
In my scorer object the property termsToFind is 0 I would expect that to at least be one? Anyone any ideas or suggestions on how to fix / debug?
Regards
Ismail
Ok figured this out I was passing in the wrong values to the highlighter function. I was passing the query search term and field name. What i needed to pass in was the content of the contents field for each document match and the query term. All working now.

firebase equalTo database query command

var ref = db.ref("main")
var usersRef = ref.child("users");
var accountIdVal = 56473;
What datatype is the equalTo query commmand using when I try to search with a variable, like below it does not return the desired result.
usersRef.orderByChild("accountID").equalTo(accountIdVal).once("value",function(snapshot){
//returns all the values in users
});
when the same thing is tried with non referenced value like below it works fine
usersRef.orderByChild("accountID").equalTo(56473).once("value",function(snapshot){
//returns the exact user
});
even when I use accountIdVal.toString() it does not seem to work, am I missing something here?
Hi thanks for the help I figured out the answer it was because I was getting the value of the variable as a Long, it was checking for a Integer and not a string so the datatypes were not matching up.

What is wrong in this LINQ Query, getting compile error

I have a list AllIDs:
List<IAddress> AllIDs = new List<IAddress>();
I want to do substring operation on a member field AddressId based on a character "_".
I am using below LINQ query but getting compilation error:
AllIDs= AllIDs.Where(s => s.AddressId.Length >= s.AddressId.IndexOf("_"))
.Select(s => s.AddressId.Substring(s.AddressId.IndexOf("_")))
.ToList();
Error:
Cannot implicitly convert type 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.List<MyCompany.Common.Users.IAddress>'
AllIDs is a list of IAddress but you are selecting a string. The compiler is complaining it cannot convert a List<string> to a List<IAddress>. Did you mean the following instead?
var substrings = AllIDs.Where(...).Select(...).ToList();
If you want to put them back into Address objects (assuming you have an Address class in addition to your IAddress interface), you can do something like this (assuming the constructor for Address is in place):
AllIDs = AllIDs.Where(...).Select(new Address(s.AddressID.Substring(s.AddressID.IndexOf("_")))).ToList();
You should also look at using query syntax for LINQ instead of method syntax, it can clean up and improve the readability of a lot of queries like this. Your original (unmodified) query is roughly equivalent to this:
var substrings = from a in AllIDs
let id = a.AddressId
let idx = id.IndexOf("_")
where id.Length >= idx
select id.Substring(idx);
Though this is really just a style thing, and this compiles to the same thing as the original. One slight difference is that you only have to call String.IndexOf() one per entry, instead of twice per entry. let is your friend.
Maybe this?
var boundable =
from s id in AllIDs
where s.AddressId.Length >= s.AddressId.IndexOf("_")
select new { AddressId = s.AddressId.Substring(s.AddressId.IndexOf("_")) };
boundable = boundable.ToList();

Resources