Natural sort using DPL on MediaWiki - mediawiki

Using the DPL extension, with ordermethod = title, is there a way to trigger natural sorting, such that for a series of pages with titles with numberic dismabiguations, the result gives B below, rather than A below? By default, you get A.
A:
PageName (something 1)
PageName (something 10)
PageName (something 2)
..
PageName (something 9)
B:
PageName (something 1)
PageName (something 2)
..
PageName (something 9)
PageName (something 10)

Related

Is there a way to transform the data before I could query it?

MySQL column:
phone = '(999)-666-333'
String to search '999666333'
Is there a way I could search by transforming the value '(999)-666-333' within WHERE command?
I want to strip all non-digits and leave only digits.
something like:
select * from users where regex(phone, '[0-9]') = '999666333';
Something like this works in my case:
SELECT * FROM users WHERE REGEXP_REPLACE(phone, '[^0-9]', '') = '999666333';

search database id field with string manipulated id

We will get id from user in this form:
"A-123456-14"
and want to search in database with simple id in this form :
123456
I have tried
select * from orders where id = '%' + searchId + '%';
here id = 123456 in database and searchId = 'A-123456-14' which get from user.
but its not working as its not properly
(A : is prefix, - is delimiter and 14 is postFix)
Please help me to solve this problem.
you can use:
SELECT * FROM orders WHERE WHERE 'A-123456-14' REGEXP '[:punct:]' + id + '[:punct:]';
in above you can replace 'A-123456-14' with user input searchId
i have tried its work fine
SELECT
*
FROM
orders
WHERE
id = SUBSTRING_INDEX(
SUBSTRING_INDEX(searchId, '-', 2),
'-',- 1)
EDIT:
If you want to make everything dynamic then you can try this (You should post delimiter as a parameter also, if it is dynamic).
SELECT
*
FROM
orders
WHERE
id = SUBSTRING_INDEX(
SUBSTRING_INDEX(searchId, delimiter, 2),
delimiter, - 1)
Try this:
SELECT * FROM orders WHERE searchId LIKE CONCAT('%-', Id, '-%')
I would definitely remove the bits of the string you don't need using your programming language of choice (e.g. Java or PHP or whatever you are using), not in SQL. Then just use select * from orders where id = ? and set the parameter to be "%"+id+"%" in your programming language.
Programming languages are for programming, logic, parsing etc., SQL is for defining what you'd like to get from your data
Don't forget to use parameters like ? otherwise you could open yourself up to SQL injection.

MySQL - Search CSV in CSV Column

I have a table with a column that has CSV.
TableA:
field_id | matches
---------------------
1 1,2,4,6,8,11,14,56
Now I need to get the field_id that matches a user given csv. So for instance, user string is 1,4,11, then it should return some value may be just true.
1.) Find_in_set does not work. Because it takes only one element and searches that in a SET/CSV column.
2.) Cannot use like concat('%,', user_input , ',%'). Because user input may not be in order.
Any other ideas? I guess this is a very common scenario.
Note: I dont need to search all records. I need to search a specific record. So in the above table, I just need to search one record that has field_id = 1. i.e. (where field_id = 1). (May not matter, but just an info)
Well, this is a good argument for having data in a proper relational form. But, you can try:
select t.*
from t
where (find_in_set($user_input, 1) = 0 or
find_in_set(substring_index(substring_index($user_input, ',', find_in_set($user_input, 1)), ',', -1), matches) > 0) and
(find_in_set($user_input, 2) = 0 or
find_in_set(substring_index(substring_index($user_input, ',', find_in_set($user_input, 2)), ',', -1), matches) > 0) and
. . .
Do this for however many values you might have in the userinput set.
I presume there is no straight solution with MySQL query like Find_In_Set. So I guess I will have to handle this with multiple queries or with Looping.

MySQL User() return only so many characters

I am using the User() to populate a table which returns something like (admin#localhost).
How would I return
1) only the items to the left of the # (if possible)
and
2) only the first 10 characters (if something like AnnaMariaSmith#localhost, just return AnnaMariaS)
Thanks
Something like this perhaps?
SELECT LEFT(USER(), LOCATE('#',USER()) - 1)
See it in action
If you want only the first 10 characters of the result above, just another LEFT function:
SELECT LEFT(LEFT(USER(), LOCATE('#',USER()) - 1), 10)

ORDER BY word starts or inside field

I have an ajax-search on a mysql-db. Example: Search for "man" which I query with:
SELECT id FROM table WHERE name LIKE '%man%;
I now want to sort the result to have all results starting with the search in alphabetical order:
man
mankind
after that I want to have all results width the search INSIDE in alphabetical order, like:
iron man
woman
How can I do that?
You can order by the position of your search term in the string:
SELECT id
FROM table
WHERE name LIKE '%man%'
ORDER BY INSTR(name, 'man'), name
See also: INSTR(), LOCATE()
You could also change the expression to only distinguish between start of the string or anywhere else:
ORDER BY IF(INSTR(name, 'man'), 1, 0)
You can construct your ORDER BY using a CASE statement to verify the substrings. Note: I am using UPPER() here to convert both the search value and the column value to uppercase, for a case-insensitive match. If that is not your need, remove the UPPER().
ORDER BY
CASE
/* Matches the start of the string */
WHEN UPPER(LEFT(name, 3)) = 'MAN' THEN 1
/* Doesn't match the end or the start (in the middle) */
WHEN UPPER(RIGHT(name, 3)) <> 'MAN' THEN 2
/* Matches the end of the string */
WHEN UPPER(RIGHT(name, 3)) = 'MAN' THEN 3
ELSE 4
END,
/* Then order by the name column */
name
This method should be fairly portable, but I like the INSTR() answer below better.
Try this
SELECT id FROM table WHERE name LIKE 'man%';
UNION
SELECT id FROM table WHERE name LIKE '%man%';