smaller greater comparisions with Solr functions - solr

Comparing dates is of course easy using Solr, but I need to do find a Solr function, where I can do the following:
int value = date2 - date1;
if (value < 0)
do something...
if (value > 0)
do something else...
I know about for example if(exists(myField) ,100, 0), but instead of exists() I want to say if(((date2-date1) < 0), 100, 0).
Is there a way or a function to do this kind of comparison?

Related

What is wrong with this expressions? =CountRows(ReportItems!Textbox58.Value = "Intervene"). I want to count each row which says Intervene

What is wrong with this expression? =CountRows(ReportItems!Textbox58.Value = "Intervene")
I want to count each row which says Intervene.
As Larnu has commented, you cannot use CountRows against the ReportItems collection.
Probably what you need to do is
Look at the expression in Textbox58 and see where it gets it's data from. In this exmaple let's say it comes from Fields!myFieldName.Value.
Now we need to count the rows where Fields!myFieldName.Value = "Intervene" but rather than using count, we can convert these matches to return 1 or 0 where the field is not "Intervene"
So the expression would look something like this
=SUM(IIF(Fields!myFieldName.Value = "Intervene", 1, 0))
This will sum the rows withing the current scope, so if this is contained in a row group for example, then it will only sum those rows in that row group.
If you need to count based on a a different scope (e.g. the entire dataset) then you can specify that in the SUM() function like this
=SUM(IIF(Fields!myFieldName.Value = "Intervene", 1, 0), "DataSet1")
Here we are summing across the entire dataset where the dataset name is DataSet1
Update based on OP comment
As your expression is
=SUM(IIF(Fields!Actual_Duration.Value >= 10, "Intervene", "No Intervention Needed"))
What we actually need to count is instances where Actual_Duration is >= 10.
So the final expression should be
=SUM(IIF(Fields!Actual_Duration.Value >= 10, 1, 0))

TSQL Is it possible to do a NULLIF where a column is less than 15% of another column?

I have a large query that I'm trying to edit to insert 40ish columns into a database at a specific time in the day for trending reasons.
Currently the query is doing a NULLIF(Linespeed, 0) but I'd much rather it work in the way that would be something like
NULLIF(Linespeed > Linespeed_Target * 15)
(I know this doesn't work). I can't quite figure out how I would do a case statement for this. I also don't think I can do it in the where clause because I have another column that looks for where Linespeed is any value.
Code here:
Nullif(Round(Avg(Nullif(Linespeed, 0)) / Avg(LineSpeed_Target), 2), 0) as 'LS OEE'
The reason I can't use a where clause:
NullIF(Round(Cast(count(NULLIF(0 ,LineSpeed)) / Cast(Count(Linespeed) as float) as float), 2), 0) as 'Avail OEE'
Results image
Jeroen actually pointed out the solution to me!
What I ended up using is this:
Nullif(Round(Avg((Case when Linespeed < Linespeed_Target * .10 then NULL Else Linespeed End)) / Avg(LineSpeed_Target), 2), 0) as 'LS OEE',
From the comments:
The column LS AVG should be an AVG of values when value is above 15% of the linespeed target
That would be:
avg(case when linespeed > linespeed_target * 0.15 then linespeed end)
The case expression returns null for values that do not meet the condition, which avg() ignores.

Store Operators like >= OR <= in Microsoft Access

I have certain values that are needed for validation in Forms, either they look like Value X >= 0 but it could also be X <= 0, it depends on what operator should be used. How can I store such a value?
(I use MS SQL Server + Access as Frontend)
I basicly wanna store the Value and if it needs to be bigger than or smaller than.
Store the value, as usual, in a field, and the operator in another field as Short Text.
The you can use Eval:
Result = Eval("" & [ValueField] & [OperatorField] & "0")
You can store your value as it is, and to check if this value is positive or not you have two ways
First one
Create a computed column to check the Value column as
CREATE TABLE YourTable(
YourValue INT,
IsPositive AS CASE WHEN YourValue < 0 THEN 0 ELSE 1 END
);
INSERT INTO YourTable (YourValue) VALUES
(1), (-1);
SELECT *
FROM YourTable;
Second one
Use a CASE expression (or even you can create a view) as
SELECT CASE WHEN YourValue < 0 THEN 0 ELSE 1 END IsPositive,
--...
FROM YourTable;

Solr FunctionQuery: gte, lte, eq functions

Solr FunctionQuery has a DIV(x,y) function. I have such a need if y=0, then y should be equal to x.
In other words, I need to represent the following logic with FunctionQuery:
if y == 0, return 1 /* i.e. DIV(x,x) */
else, return DIV(x,y)
Somehow, from the Solr doc, I cannot find any comparison function, e.g. EQ(x, value), etc. for me to use.
Will anyone be able to give me a hint to construct my desired logic using FunctionQuery?
Thanks!
To clean up this question and log what is my final solution, thanks to Srikanth Venugopalan comment:
actually you need to switch the arguments. exposure_count = 0 is interpreted as false. So your condition would be {!boost b=if(exposure_count,div(1,exposure_count),1)}"
As it seems, Lucid works documentation does have a mistake. The FunctionQuery parser does not take comparison operators such as ==, at least this is what I found by looking into the sourcecode. Also, the field separator for IF() function should be ,(comma) and not ;(semi-colon).
The official Solr wiki is correct.
For string terms this works:
if(termfreq(fieldname,"value"),2,1)
which yields 2 if "value" is contained in "fieldname" (termfreq will be >0)
you can use == for equals and if conditional statement as below :-
e.g. if(y == 0; 1; DIV(x,y))
Check for the example # Documentation
if(color=="red"; 100; if(color=="green"; 50; 25)) :
This function checks the document field "color", and if it is "red" returns 100, if it is "green" returns 50, else returns 25.
Edit :-
Solr if wiki mentions , (comma) as seperator
e.g. if(exists(myField),100,0)

Question about Solr and SolrJ range query?

Suppose that my index has 3 fields: title, x and y.
I know one range(10 < x < 100) can query like this:
http://localhost:8983/solr/select?q=x:[10 TO 100]&fl=title
If I want to two range(10 < x <100 AND 20 < y < 300) query like
SQL(select title where x>10 and x < 100 and y > 20 and y < 300)
by using Solr range query or SolrJ, but I don't know how to implement this. Does anybody else know? Thanks
Email: enzhaohoo#gmail.com
Take a look at the docs for SolrJ. Successive calls to addFilterQuery will continue to build up your query. Alternatively you can have two things in one fq:
http://localhost:8983/solr/select?q=&fq=x:[10+TO+100]+AND+y:[20+TO+300]&fl=title
There is a method in class SolrQuery can solve your problem,
setFilterQueries(String... fq)
You can take a look at this.

Resources