Sphinx alphabetical pagination / navigation menu - pagination

I need to do a pagination / navigation menu in Sphinx
*(for signs) 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
And to filter the results.
In the "A" page - just the results starting with "A"
Thanks

But if you do mean sphinxsearch, something like this
sql_query = SELECT id, name, ORD(IF(ORD(name) BETWEEN 48 AND 57 OR ORD(UPPER(name)) BETWEEN 65 AND 90, UPPER(SUBSTRING(name,0,1)), '*')) AS ord, ...
sql_attr_uint = ord
Would give you a numeric attribute representing the first letter of the name. Can be used with setFilter to only return results matching that value.
Can even be used with setGroupBy to get the number of results matching each ordinal.
REF: http://www.asciitable.com/
--
Edit to add: Using a Integer Attribute - having got an integer via the mysql ORD function, because attr str2ordinal (nor string attributes for that matter!) allow filtering. Converting yourself to an integer like this allows filtering.
Eg to get only 'A' results, could do
$cl->setFilter('ord',array(ord('A')));
This works because php's ord function works the same way as mysql.

Related

DAX lookup index column by filtered max formula to create relationship looking for more elegant solution

I have data such that manytable rows are always recorded at x before the onetable rows they correspond to are recorded at Z.
This is the loaded manytable
A
B
C
x
Compositekey
1
X
P
5.5
1_X_P
6
Q
R
1
6_Q_R
1
X
P
4
1_X_P
6
Q
R
2.5
6_Q_R
This is the loaded onetable
A
B
C
Z
Compositekey
FullCompositeKey
1
X
P
3
1_X_P
1_X_P_3
6
Q
R
6
6_Q_R
6_Q_R _6
I load these into the data model with composite keys using A_B_C.
I enforce many to 1 by removing duplicates in the Compositekey column in the onetable.
I then create a calculated column identifying the relevant Z value for each row of the many table.
MatchedZ =MINX(
FILTER(onetable,
EARLIER(manytable[Compositekey]) = onetable[Compositekey] &&
EARLIER(manytable[x]) < [Z]
),
[Z])
Is there a more efficient way to do this?
Goal manytable format:
A
B
C
x
Zid
1
X
P
5.5
2
6
Q
R
1
1
1
X
P
4
2
6
Q
R
2.5
1
Create a surrogate key in PQ. You can just use an index.

Replace values of unmatched index with 'Other' python3

This is the original series. I'm trying to replace values of the non top 2 in the series with 'Other'.
Original Series(ser3):
b 8
c 6
a 5
h 4
g 2
d 2
f 2
e 1
This is my extracted top 2.
Top 2:
t2 = ((ser3.value_counts().head(2)))
b 8
c 6
Expected Output:
b 8
c 6
a Other
h Other
g Other
d Other
f Other
e Other
How can I do that? I do not want to convert to dictionary and replace the values by indexing. I prefer to do it by Series. I tried using .isin, but my code gives me an error.
a[a[~a.isin(t2)].index]='Other'
The above gives me an error.
You are close, need select t2.index and remove outer ser3[]:
ser3[~ser3.isin(t2.index)]='Other'

Algorithm to find number of possible string variations

For a password related project, I'm looking for an algorithm that calculates the number of possible variations a certain string can have based on a few options. For now the string variation options are upper/lowercase and character to number replacements (like E=3)
For example, lets take the string 'abc#def'
With just upper/lower variations, there are 6 characters that can vary, and the total number of possible variations is 2^6 = 64.
With just character to number replacements, there are 2 characters that qualify (A=4,E=3). That makes the number of variations 2^2 = 4.
I'm struggeling with calculating the number of variations when both methods are enabled.
I've tried (2^6 * 2^4), but obviously this doesn't consider the overlap that occurs when applying both.
For example, the variations 'abc#def' and 'abc#dEf' both result in 'abc#d3f' with number substitution on de character E and should be counted as one.
Somehow I can't figure this out :)
Just count all possibilities for each letter within the password and multiply them together:
letter options count
a a A 4 3
b b B 2
c c C 2
# # 1
d d D 2
e e E 3 3
f f F 2
Finally we have 3 * 2 * 2 * 1 * 2 * 3 * 2 == 144 variants

column and row join a second box data

I want to column join
┌─┬─┬─┐
│1│1│2│
│2│4│4│
│3│9│6│
└─┴─┴─┘
and I'd like to put a=.1 2 3 as the fourth row, and then put b=.1 1 1 1 as the first column to the new boxed data. How can I do this easily? Do I have to ravel the whole thing and compute the dimention on my own in order to box it again?
Also, if I want the data i.8 to be 2 rows, do I have to calculate the other dimension 4(=8/2) in order to form a matrix 2 4$i.8? And then box it ;/2 4$i.8? Can I just specify one dimension, either the number of row or columns and ask automatic boxing or forming the matrix?
The answer to your question will involve learning about &. , the 'Under' conjunction, which is tremendously useful in J.
m
┌─┬─┬─┐
│1│1│2│
│2│2│4│
│3│9│6│
└─┴─┴─┘
a=. 1 2 3
b=. 1 1 1 1
So we want to add each item of a to each boxed column of m . It would be perfect if we could unbox the column using unbox(>), append the item of a to the column using append (,) and then rebox the column using box (<). This undo, act, redo cycle is exactly what Under (&.) does. It undoes both its right and left arguments ( m and a ) using the verb to its right, then applies the verb to its left, then uses the reverse of the verb to its right on the result. In practice,
m , &. > a
┌─┬─┬─┐
│1│1│2│
│2│2│4│
│3│9│6│
│1│2│3│
└─┴─┴─┘
The fact that a is unboxed when it was never boxed to begin with means that it is not changed, while m is unboxed before (,) is applied to each a . In fact this is used so often in J that &. > is assigned the name 'each'.
m , each a
┌─┬─┬─┐
│1│1│2│
│2│2│4│
│3│9│6│
│1│2│3│
└─┴─┴─┘
Prepending a boxed version of b requires first giving it an extra dimension with laminate (,:) then transposing (|:) b and finally boxing (<) the result. The step of adding the extra dimension is required because transposing swaps the indices and b start as a one-dimensional list.
(<#|:#,:b)
┌─┐
│1│
│1│
│1│
│1│
└─┘
The rest is easy as we just use append (,) to join the boxed b with (m, each a)
(<#|:#,: b) , m , each a
┌─┬─┬─┬─┐
│1│1│1│2│
│1│2│2│4│
│1│3│9│6│
│1│1│2│3│
└─┴─┴─┴─┘
Brackets around (<#|:#,: b) are necessary to force the correct order of execution.
For the second question, you can use i. n m to create a n X m array, which may help.
i. 4 2
0 1
2 3
4 5
6 7
i. 2 4
0 1 2 3
4 5 6 7
but perhaps I am misunderstanding your intentions here.
Hope this helps, bob
append a (with rank): ,"x a
You can simply append (,) a to your unboxed (>) input but you have to be careful with the append rank. You want to append each "item" of a, so you have right rank of "0". You want to apend to a 2-cell so you have a left rank of "2". Therefore, the , you need has rank "2 0. After the append, you rebox your data to a 2-cell with <"2.
<"2(>in)(,"2 0) a
┌─┬─┬─┐
│1│1│2│
│2│4│4│
│3│9│6│
│1│2│3│
└─┴─┴─┘
prepend b: b,
If your b has the right shape you prepend it with b,. The shape you seem to use is (boxed) 4 1:
b =: < 4 1$ 1
┌─┐
│1│
│1│
│1│
│1│
└─┘
b,in
┌─┬─┬─┬─┐
│1│1│1│2│
│1│2│4│4│
│1│3│9│6│
│1│1│2│3│
└─┴─┴─┴─┘

How to count every word occurence in a string in a ORACLE loop?

I've got a problem which seems simple at first, but really isn't. I'm storing words in a table in such way that pair of strings "A B C D E" and "D E F" becomes:
id value
-- -----
1 A
1 B
1 C
1 D
1 E
2 D
2 E
2 F
And i pass to my ORACLE procedure string which looks like this: "A B C D G". And now I want to check percentage of similarity between strings in the database and string passed as a parameter.
I presume that I have to use one of split functions and use an array. Later check if every word in passed string occurs in the table and then count ids. But there`s a twist: I need precise percentage value.
So, result from example above should look like this:
id percentage
-- ----------
1 80 -- 4 out of 5 letters exists in query string (A B C D)
2 33 -- 1 out of 3 (D)
So, my questions are:
what is most effective way to split query string and then iterate on it (table?)
how to store partial results and then count them?
how to count final percentage value?
Every help would be greatly appreciated.
The following query would give you what you want without the need to bother with procedures.
select id
, sum(case when value in ('A', 'B', 'C', 'D', G') then 1 else 0 ) / count(*)
from my_table
group by id
Alternatively if you have to pass the string "A B C D G" and get a result back you could do:
select id
, sum(case when instr('A B C D G', value) <> 0 then 1 else 0 ) / count(*)
from my_table
group by id
These do involve full scanning the table or an index full scan if you use the suggested index below, so you might want to add the following where clause if you only want to find ids that have a percentage > 0.
select id
, sum(case when instr('A B C D G', value) <> 0 then 1 else 0 ) / count(*)
from my_table
where exists ( select 1
from my_table
where id = mt.id
and instr('A B C D G', value) <> 0 )
group by id
For all the queries your table should be indexed on my_table, id in that order.
Have you had a look at UTL_MATCH? It doesn't do exactly what you're trying to achieve, but you may find it useful if the definition of your percentage agreement isn't set in stone.

Resources