How to set NOT clause on Date range query in Solr - solr

Have been trying to understand this for a while ...
How can I specify NOT clause in the following query?
{!field f=schedule op=Intersects}[2016-08-26T12:30:00Z TO 2016-08-26T18:30:00Z]
{!field f=schedule op=Contains}[2016-08-26T12:30:00Z TO 2016-08-26T18:30:00Z]
Like, without LocalParams, we can specify -DateField:[2016-08-26T12:30:00Z TO 2016-08-26T18:30:00Z] to get an equivalent NOT clause. But, I need a NOT Contains Date Range query.
I have tried a few options but I end up getting parsing errors. Surely there must be some obvious way I am missing.

Related

How to match a substring exactly in a string in SQL server?

I have a column workId in my table which has values like :
W1/2009/12345, G2/2018/2345
Now a user want to get this particular id G2/2018/2345. I am using like operator in my query as below:
select * from u_table as s where s.workId like '%2345%' .
It is giving me both above mentioned workids. I tried following query:
select * from u_table as s where s.workId like '%2345%' and s.workId not like '_2345'
This query also giving me same result.
If anyone please provide me with the correct query. Thanks!
Why not use the existing delimiters to match with your criteria?
select *
from u_table
where concat('/', workId, '/') like concat('%/', '2345', '/%');
Ideally of course your 3 separate values would be 3 separate columns; delimiting multiple values in a single column goes against first-normal form and prevents the optimizer from performing an efficient index seek, forcing a scan of all rows every time, hurting performance and concurrency.

Solr empty query can't find the data

I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this.
I tried to query the data of status==1 and projectMaintainUserIds!=null and leadsStatus!=null through the following statement, but the result is different from the expectation, and the returned result set is empty.
q=(status:1)&fq=(-projectMaintainUserIds:*) AND (-leadsStatus:12)
If I modify the query statement slightly, it seems to return the correct result:
q=(status:1)&fq=-projectMaintainUserIds:* AND -leadsStatus:12
I don't know why parentheses affect the results of '-filed:*' queries.

Cannot extract year from createdDate in SOQL query

SELECT House__r.Name, House__r.House_Owner__r.person__r.Email__c, (SELECT Name, Total_Balance__c, Total_Expense__c FROM Expenses__r Where Type__c='Yearly' AND AND CALENDAR_YEAR(CreatedDate) = CALENDAR_YEAR(System.today() ) FROM Member__c
Error=> Unknown parsing error.
Kindly suggest what else can I do.
You have two 'AND' in a row. Also, if you are using query editor, you can't use System.today().
(on mobile, formatting will be poor, sorry)
SOQL supports only "field - operator - value_or_function” style for conditions. You try to make it "function - operator - another function", won't work.
For your particular scenario try with WHERE Created date = THIS_YEAR. It's a special literal, see https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
More generic way would be to write what you need as a formula field, you could compare to YEAR(TODAY()). (that could be poor performance to filter by formula, often it results in full table scan, you would have to test, maybe add more filters using indexed columns...).
Or write it as WHERE CreatedDate >= :start AND CreatedDate <= :stop, put right bind variables for your range.

how do we specify Must clause(+) with local params

if my query is using local params e.g like below
q=\field:test11&
fq=+{!frange cost=200 l=NOW/DAY-10DAYS u=NOW/DAY+1DAY incl=true incu=false}date
How to i specify the must clause ?
So adding + at the beginning of the local param syntax is the correct way?
e.g in the first query, is the leading + correct or not?
+{!frange cost=200 l=NOW/DAY-10DAYS u=NOW/DAY+1DAY incl=true incu=false}date
If not then how do we specify must clause or do we even need must clause here ?
The intent of my query is to find all the documents which have value test11 in field and also the date is within last 10 days.
The query will work as its written if you remove the +. A filter query is always used to filter the current set of returned documents, so it has to match (i.e. it'll always work logically as an AND clause to the original query).
You can probably rewrite that query to just be a range as well:
fq=start_date:[NOW/DAY-10DAYS TO NOW]

MS SQL Excel Query wildcards

I'm trying to introduce LIKE clause with wildcards in SQL query that runs within Excel 2007, where parameters are taken from specific Excel cells:
SELECT Elen_SalesData_View.ItemCode, Elen_SalesData_View.ItemDescription,
Elen_SalesData_View.ItemValue, Elen_SalesData_View.Quantity,
Elen_SalesData_View.CustomerId, Elen_SalesData_View.CustomerName,
Elen_SalesData_View.SalesInvoiceId, Elen_SalesData_View.EffectiveDate,
Elen_SalesData_View.CountryId
FROM SM_Live.dbo.Elen_SalesData_View Elen_SalesData_View
WHERE (Elen_SalesData_View.EffectiveDate>=? And Elen_SalesData_View.EffectiveDate<=?)
AND (Elen_SalesData_View.CustomerName<>'PROMO')
AND (Elen_SalesData_View.ItemDescription LIKE '%'+?+'%')
The EffectiveDate parameters are running fine and bringing back data as expected. But since I introduced LIKE - query runs, but returns nothing.
It doesn't return any results without wildcards either (full description entered):
(Elen_SalesData_View.ItemDescription LIKE ?)
Is there a restriction to wildcards or LIKE clause? If so, is there a way around it? (I cannot use CONTAINS, as the ItemDescription field is not FULLTEXT)
Have a look at this reference which suggests that % itself is the wildcard character, although it may depend on the dialect of SQL you are using. If this is the case then your LIKE clause will simply be LIKE '%' but untested.
I've just got this to work by using the (Elen_SalesData_View.ItemDescription LIKE ?) syntax then having the cell that contains the parameter value include the wildcard characters. If you don't/can't include the wildcards then create a formula in a separate cell to wrap the value in % characters and use this cell for the parameter value.
Rhys
My query was correct. There was something wrong with the actual spreadsheet. After redoing all from scratch - it worked!
SELECT Elen_SalesData_View.ItemCode, Elen_SalesData_View.ItemDescription,
Elen_SalesData_View.ItemValue, Elen_SalesData_View.Quantity,
Elen_SalesData_View.CustomerId, Elen_SalesData_View.CustomerName,
Elen_SalesData_View.SalesInvoiceId, Elen_SalesData_View.EffectiveDate,
Elen_SalesData_View.CountryId
FROM SM_Live.dbo.Elen_SalesData_View Elen_SalesData_View
WHERE (Elen_SalesData_View.ItemDescription Like '%'+?+'%')
AND (Elen_SalesData_View.EffectiveDate>=?) AND (Elen_SalesData_View.EffectiveDate<=?)
AND (Elen_SalesData_View.CustomerName<>'PROMO')

Resources