How to add item at top/first? - tom-select

I tried
select.tomselect.addOption({value: '-1', text: 'All', '$score': 99999 })
but that does not work. Is there any other way to do this?

You need tell Tom Select how to sort: https://tom-select.js.org/docs/#sortfield
Also, I don't think supplying a $score field will work since it's already being used and will likely be overwritten by Tom Select. You could supply something else though, say $custom_sort and define your sortField parameter to sortField:[{field:'$custom_sort'},{field:'$score'}]

Related

How to use BY keyword correctly in FOR EACH

I want to go through the records in descending order by Field4, but when I put in the code BY mybuffer.Field4 DESCENDING I get the error
After "Field4 DESCENDING" not understandable (247) [translated].
FOR EACH mybuffer
WHERE mybuffer.Field1 = value1
AND mybuffer.Field2 = value2
AND mybuffer.Field3 >= value3
BY mybuffer.Field4 DESCENDING
USE-INDEX myindex
NO-LOCK:
/* do something */
END.
What I am doing wrong?
Although I'm not sure that the combination of USE-INDEX and BY is smart. But your problem is likely to be the order of options.
Use in this order:
USE-INDEX
NO-LOCK
BY
The error is the placement of USE-INDEX "After field 4 descending". Just like the error message says.
The correct syntax is:
for each customer no-lock use-index cust-num
where sales-rep = "BBB"
by city:
display customer.
end.
FWIW it is unlikely to be a good idea to have both USE-INDEX in a FOR EACH loop and even less likely to be a good idea to be combining it with BY. The compiler will probably choose a better index (or indexes plural) if you allow it to.

Sphinx SetSortMode EXPR

I am trying to sort using Sphinx (PHP) to show in order of price but when I do it will show £10 before £1.75 so I need to use ABS like in mySQL.
I have tried this:
$s->SetSortMode (SPH_SORT_EXPR, "ABS(display_price) ASC" );
It doesnt seem to work though.
Can anybody help?
Check, if display_price attribute treated as a decimal in search index
Probably you have
sql_attr_string = display_price
instead of
sql_attr_float = display_price
or
sql_attr_bigint = display_price
updated
SPH_SORT_EXPR is ALWAYS descending order. the ASC/DESC are for use with EXTENDED mode only.
To 'invert' it to become acsending, can build it into the expression.
$s->SetSortMode (SPH_SORT_EXPR, "1000000-CEIL(ABS(display_price*100.0))" );

Ignore column in WHERE

Can I ignore some columns in WHERE condition?
SELECT name FROM people
WHERE name LIKE 'Honza' AND surname LIKE 'Novak'
(I recieve the WHERE condition as parametr unable to edit it)
I think the answer here is no, you cannot. You got the where condition and if you can't edit it, it will be processed as is. If you can add to the end you could add an AND and an OR to override, but that's about it.
Can you do some string replacement on the WHERE? E.g.
replace($WHERE, "surname like 'Novak'", "surname like '%'")
If not, you can maybe hack something with a ON SELECT INSTEAD... rule:
http://www.postgresql.org/docs/9.1/static/sql-createrule.html

ssrs expression to split string possible?

so in my query i have select columnx from tblz
it returns 001.255556.84546
I want to be able to split this via '.' and put it into three columns.
column1 = 001
column2 = 255556
column3 = 84576
is this possible?
For info, in 2008 these dont work, you have to do the following:
=Split(Fields!returnedValue.Value, ".").GetValue(0)
Create three calculated fields with the following expressions:
=(Split(Fields!columnx.Value, ".")).GetValue(0)
=(Split(Fields!columnx.Value, ".")).GetValue(1)
=(Split(Fields!columnx.Value, ".")).GetValue(2)
I'm not sure it works or not, maybe give it a try. You might need to use IIF() statement to check values before getting them.
In SSRS you reference the field name, tell it the delimiter to use. Since you are not assigning to a variable, per se, you then need to tell it which part of the split string to use. In your example
=Split(Fields!returnedValue.Value,".")(0)
=Split(Fields!returnedValue.Value,".")(1)
=Split(Fields!returnedValue.Value,".")(2)
You would replace returnedValue with whatever the actual field name is, and place each one of those into your columns 1 - 3, respectively.
This answer was originally posted in the question instead of being posted as an answer:
=(Split(Fields!columnx.Value,".")).GetValue(0)
=(Split(Fields!columnx.Value,".")).GetValue(1)
=(Split(Fields!columnx.Value,".")).GetValue(2)

How to get whole index in ZEND Lucene?

Hi I am looking for a way to get the whole index if my query is nothing.
My lucene is a picture of my database without some unwanted content, like expired annonces...
So I would like to use only lucene to get annonces, and for that I need a way to get the whole index.
Any ideas?
thanks!
This is not the answer but something wich works for me:
Using an indexKey like is_indexed, always true.
I am adding "is_indexed:1" to my query and it works...
If you have something else, let me know!
I tend to use a field which is named after the index such as:
$oDoc->addField(
Zend_Search_Lucene_Field::keyword(
'index',
'availability'
)
);
Then the term query will return all fields. It's not pretty but it works fine.