Sphinx search by attribute - sphinx

Could I search with sphinx only by attributes without query word
config:
sql_query = SELECT p.ID as price_id, p.info, p.sort_id, p.made_id, p.category_id, 'prices' as table_id FROM price AS p
sql_query_info = SELECT * FROM price WHERE ID = $id
sql_attr_uint = sort_id
...
min_word_len = 0
min_infix_len = 0
min_prefix_len = 0
enable_star = 1
docinfo = extern
code:
$search->SetFilter('sort_id',[1,2]);
$search->Query("*","prices");
Get 0 results

$search->Query("","prices");
If that returns no results, you've got some other logic error.
Tangential, why are you 'enable_star' with infix/prefix set to 0? It will have no effect.

Related

How to select fields using alias name?

I have an select:
SELECT
tb_dim_equipe.no_equipe "EQUIPE",
tb_dim_profissional.no_profissional "PROFISSIONAL",
no_cidadao "CIDADÃO",
a.nu_cns "CNS",
sum(case when co_dim_tempo >= 20190100 and co_dim_tempo <= 20200131 then 1 else 0 end) as "TOTAL"
from (
SELECT no_cidadao,
tb_fat_cad_individual.nu_cns,
tb_fat_cad_individual.co_dim_profissional,
tb_fat_cad_individual.co_dim_equipe from tb_fat_cidadao_pec
join tb_fat_cad_individual on tb_fat_cad_individual.nu_cns = tb_fat_cidadao_pec.nu_cns
join tb_fat_cidadao on tb_fat_cad_individual.co_seq_fat_cad_individual = tb_fat_cidadao.co_fat_cad_individual
where st_mudou = 0
and st_vivo = 1
and st_gestante = 1
and tb_fat_cidadao.co_dim_tempo_validade = 30001231) a
left join (
SELECT tb_fat_atendimento_individual.nu_cns,
tb_fat_atendimento_individual.co_dim_tempo
from tb_fat_atendimento_individual
join tb_dim_tempo on tb_dim_tempo.co_seq_dim_tempo = tb_fat_atendimento_individual.co_dim_tempo
where co_seq_dim_tempo >= 20190100
and co_seq_dim_tempo <= 20200131
and ds_filtro_ciaps like '%ABP001%'
union SELECT tb_fat_proced_atend.nu_cns,
tb_fat_proced_atend.co_dim_tempo
from tb_fat_proced_atend
join tb_dim_tempo on tb_dim_tempo.co_seq_dim_tempo = tb_fat_proced_atend.co_dim_tempo
where co_seq_dim_tempo >= 20190100
and co_seq_dim_tempo <= 20200131
and ds_filtro_procedimento like '%0301010110%') b
on a.nu_cns = b.nu_cns
join tb_dim_equipe on tb_dim_equipe.co_seq_dim_equipe = a.co_dim_equipe
join tb_dim_profissional on tb_dim_profissional.co_seq_dim_profissional = a.co_dim_profissional
group by no_equipe, no_profissional, no_cidadao, a.nu_cns
order by no_equipe, no_profissional, no_cidadao
This return to me five columns EQUIPE, PROFISSIONAL, CIDADÃO, CNS and TOTAL
I want to create a new select command like this:
SELECT sum(c.TOTAL) from *query above* c
but I receive the error that column not exists.
How I can use a select with the names of alias columns EQUIPE, PROFISSIONAL, CIDADÃO, CNS and TOTAL?
Just like in the alias, you need to quote the column identifier if it is all-uppercase:
SELECT sum(c."TOTAL") from /*query above*/ c
-- ^ ^

Sphinx wildcard match on realtime index

I have created realtime index:
index berni_filter2
{
rt_mem_limit = 512M
type = rt
path = /var/lib/sphinxsearch/data/berni_filter
rt_attr_uint = product_id
rt_attr_uint = store_id
rt_field = product_name
rt_attr_json = attributes
prefix_fields = product_name
expand_keywords = 1
min_infix_len = 2
dict = keywords
}
Then I trying to get data by product name field over SphinxQL:
SELECT product_id FROM berni_filter2 WHERE store_id = 0 AND MATCH ('#product_name mothercare')
This query work fine, but I need to find partically words, for example "mother" must return products with "mothercare". I have tried:
SELECT product_id FROM berni_filter2 WHERE store_id = 0 AND MATCH ('#product_name mother')
SELECT product_id FROM berni_filter2 WHERE store_id = 0 AND MATCH ('#product_name mother*')
SELECT product_id FROM berni_filter2 WHERE store_id = 0 AND MATCH ('#product_name *mother*')
I tried change min_infix_len to min_prefix_len. Nothing work.
My mistake was, that I don't delete data files from filesystem, when change config, this is final working config:
index berni_filter
{
rt_mem_limit = 512M
type = rt
path = /var/lib/sphinxsearch/data/berni_filter
rt_attr_uint = product_id
rt_attr_uint = store_id
rt_field = product_name
rt_attr_json = attributes
index_exact_words = 1
expand_keywords = 1
min_prefix_len = 3
min_word_len = 2
morphology = stem_enru
dict = keywords
}
I faced the same problem. Deleting the index files helps me too.
Before deleting I stop the searchd service and then restart it.

get OBJECT_ID in linked server

Second select (from linked server) does not return any values.. Object_ID doesnt work. Is any workaround?
select '', name
FROM sys.databases
WHERE 1 = 1
AND NAME <> db_name() -- exclude current database
AND CASE
WHEN STATE = 0
THEN CASE
WHEN OBJECT_ID(NAME + '.dbo.tPA_SysParam', 'U') IS NOT NULL
THEN 1
END
END = 1
union
select '[LINKED]', name
FROM [LINKED].master.sys.databases
WHERE 1 = 1
AND CASE
WHEN STATE = 0
THEN CASE
WHEN OBJECT_ID('[LINKED].'+NAME + '.dbo.tPA_SysParam', 'U') IS NOT NULL
THEN 1
END
END = 1
You can also mimic OBJECT_ID with a little help from the PARSENAME function:
Declare #FullTableName nvarchar(max) = '[dbo].[MyTable]';
Select t.object_id
From [LINKED].MyDatabase.sys.tables As t
Inner Join [LINKED].MyDatabase.sys.schemas As s On t.schema_id = s.schema_id
Where t.[name] = PARSENAME(#FullTableName, 1)
And s.[name] = PARSENAME(#FullTableName, 2)

db2 error with sum()

I am using the IBM tool 'JRS' to exctract data from 'RTC' with DB2.
I have the folowing code, wich it works just fine:
SELECT
CASE WHEN (T3.REQUEST_TYPE = 'Corretiva' OR T3.REQUEST_TYPE = 'Corretiva Interna' )
THEN (MAX(T1.ACTUAL_WORK) - MIN(T1.ACTUAL_WORK))/3600
ELSE 0
END AS CORRETIVAS_TIME,
(MAX(T1.ACTUAL_WORK) - MIN(T1.ACTUAL_WORK))/3600 AS TOTAL_TIME
FROM RICALM.VW_RQST_HISTORY T1 -- HISTORICO DA TAREFA
INNER JOIN RICALM.VW_RQST_HISTORY T0 -- HISTORICO ANTERIOR DA TAREFA
ON T0.REQUEST_HISTORY_ID = T1.PREV_REQUEST_HISTORY_ID
INNER JOIN RIDW.VW_REQUEST T2 -- TAREFA
ON T2.REQUEST_ID = T1.REQUEST_ID
INNER JOIN RIDW.VW_REQUEST_RELATIONAL_LINK LT1
ON T2.REQUEST_ID = LT1.REQUEST1_ID AND LT1.NAME = 'com.ibm.team.workitem.linktype.parentworkitem'
INNER JOIN RIDW.VW_REQUEST T3 -- CORRETIVA
ON LT1.REQUEST2_ID = T3.REQUEST_ID AND LT1.NAME = 'com.ibm.team.workitem.linktype.parentworkitem'
WHERE ( YEAR(CURRENT_TIMESTAMP)*12 + MONTH(CURRENT_TIMESTAMP) = YEAR(T1.REC_DATETIME)*12 + MONTH(T1.REC_DATETIME)
)
AND T1.ACTUAL_WORK <> T0.ACTUAL_WORK
AND T2.REQUEST_TYPE = 'Tarefa'
AND (T3.REQUEST_CATEGORY_NAME = 'SIENGE/Manutenção Contínua/MC-COMCRC' OR
T3.REQUEST_CATEGORY_NAME = 'SIENGE/Manutenção Programada/MP-COMCRC')
AND
(T1.ISSOFTDELETED = 0 AND T2.ISSOFTDELETED = 0 AND T3.ISSOFTDELETED = 0)
GROUP BY T1.REFERENCE_ID,T3.REQUEST_TYPE
Resulting on the folowing table:
corretivas_time
total_time
0 0
0 6
0 0
0 6
0 0
1 1
4 4
Now I want to get the sum of each column to compare eachother, so I make this folowing selection:
SELECT
SUM(CASE WHEN (T3.REQUEST_TYPE = 'Corretiva' OR T3.REQUEST_TYPE = 'Corretiva Interna' )
THEN (MAX(T1.ACTUAL_WORK) - MIN(T1.ACTUAL_WORK))/3600
ELSE 0
END) AS CORRETIVAS_TIME,
SUM((MAX(T1.ACTUAL_WORK) - MIN(T1.ACTUAL_WORK))/3600) AS TOTAL_TIME
And the rest is the same...
I get this error:
CRRGW5628E An com.ibm.db2.jcc.am.SqlSyntaxErrorException error
occurred when validating the input SQL string, caused by DB2 SQL
Error: SQLCODE=-112, SQLSTATE=42607, SQLERRMC=SUM, DRIVER=4.14.121.
I also tried this code:
SELECT SUM(SELECT
CASE WHEN (T3.REQUEST_TYPE = 'Corretiva' OR T3.REQUEST_TYPE = 'Corretiva Interna' )
THEN (MAX(T1.ACTUAL_WORK) - MIN(T1.ACTUAL_WORK))/3600
ELSE 0
END AS CORRETIVAS_TIME
With the rest being the same.
I got this error:
CRRGW5628E An com.foundationdb.sql.parser.SQLParserException error
occurred when validating the input SQL string, caused by Encountered
"" at line 2, column 12. Was expecting one of: .
I'm almost sure you want something like this instead:
SELECT SUM(corretivas_time), SUM(total_time) FROM (
SELECT
CASE WHEN (T3.REQUEST_TYPE = 'Corretiva' OR T3.REQUEST_TYPE = 'Corretiva Interna' )
THEN (MAX(T1.ACTUAL_WORK) - MIN(T1.ACTUAL_WORK))/3600
ELSE 0
END AS CORRETIVAS_TIME,
(MAX(T1.ACTUAL_WORK) - MIN(T1.ACTUAL_WORK))/3600 AS TOTAL_TIME
FROM RICALM.VW_RQST_HISTORY T1 -- HISTORICO DA TAREFA
INNER JOIN RICALM.VW_RQST_HISTORY T0 -- HISTORICO ANTERIOR DA TAREFA
ON T0.REQUEST_HISTORY_ID = T1.PREV_REQUEST_HISTORY_ID
INNER JOIN RIDW.VW_REQUEST T2 -- TAREFA
ON T2.REQUEST_ID = T1.REQUEST_ID
INNER JOIN RIDW.VW_REQUEST_RELATIONAL_LINK LT1
ON T2.REQUEST_ID = LT1.REQUEST1_ID AND LT1.NAME = 'com.ibm.team.workitem.linktype.parentworkitem'
INNER JOIN RIDW.VW_REQUEST T3 -- CORRETIVA
ON LT1.REQUEST2_ID = T3.REQUEST_ID AND LT1.NAME = 'com.ibm.team.workitem.linktype.parentworkitem'
WHERE ( YEAR(CURRENT_TIMESTAMP)*12 + MONTH(CURRENT_TIMESTAMP) = YEAR(T1.REC_DATETIME)*12 + MONTH(T1.REC_DATETIME)
)
AND T1.ACTUAL_WORK <> T0.ACTUAL_WORK
AND T2.REQUEST_TYPE = 'Tarefa'
AND (T3.REQUEST_CATEGORY_NAME = 'SIENGE/Manutenção Contínua/MC-COMCRC' OR
T3.REQUEST_CATEGORY_NAME = 'SIENGE/Manutenção Programada/MP-COMCRC')
AND
(T1.ISSOFTDELETED = 0 AND T2.ISSOFTDELETED = 0 AND T3.ISSOFTDELETED = 0)
GROUP BY T1.REFERENCE_ID,T3.REQUEST_TYPE
) as t

Sphinx empty index

I'm trying to create index from table domains. When I get 10 attributes, everything is ok. When i add 11-th, indexer returns:
collected 1629494 docs, 0.0 MB
Config:
#...
sql_attr_uint = did
sql_attr_string = url
sql_attr_uint = zone_id
sql_attr_uint = first_letter
sql_attr_uint = category_id
sql_attr_uint = is_parking
#sql_attr_uint = data3
sql_attr_uint = views
sql_attr_uint = data1
sql_attr_uint = data2
sql_attr_uint = is_top_site
#...
When I remove any of the 11 attributes, everything works fine. Is there some kind of limit ?