How to extract the repeatable part of lucene query? - lucene

I have 4 fields, docContent, visibility, docOwner and docType. I want to get all docType:ProfileDocument except those with visibility:1. But the owner of each document can say that his document with visibility:1 can be returned from the search result. The query bellow searches for asd, returning all documents that matches the term and their visibility is not 1 except for docOwner:390. The query works but the docType:ProfileDocument is repeated twice. How to refactor the query so docType:ProfileDocument be presented only once?
docContent:asd
AND(
(NOT visibility:1 AND docType:ProfileDocument)
OR ( docOwner:390 AND visibility:1 AND docType:ProfileDocument)
)
I tried this but I failed:
docContent:asd
AND(
(((NOT visibility:1)
OR ( docOwner:390 AND visibility:1))
AND docType:ProfileDocument)
)

The AND NOT operator cannot be used with just one term. For example, the following search will return no results:
AND NOT "jakarta apache"
Reference: http://drupal.org/node/375446

Related

Regex comparison in Oracle between 2 varchar columns (from different tables)

I am trying to find a way to capture relevant errors from oracle alertlog. I have one table (ORA_BLACKLIST) with column values as below (these are the values which I want to ignore from
V$DIAG_ALERT_EXT)
Below are sample data in ORA_BLACKLIST table. This table can grow based on additional error to ignore from alertlog.
ORA-07445%[kkqctdrvJPPD
ORA-07445%[kxsPurgeCursor
ORA-01013%
ORA-27037%
ORA-01110
ORA-2154
V$DIAG_ALERT_EXT contains a MESSAGE_TEXT column which contains sample text like below.
ORA-01013: user requested cancel of current operation
ORA-07445: exception encountered: core dump [kxtogboh()+22] [SIGSEGV] [ADDR:0x87] [PC:0x12292A56]
ORA-07445: exception encountered: core dump [java_util_HashMap__get()] [SIGSEGV]
ORA-00600: internal error code arguments: [qercoRopRowsets:anumrows]
I want to write a query something like below to ignore the black listed errors and only capture relevant info like below.
select
dae.instance_id,
dae.container_name,
err_count,
dae.message_level
from
ORA_BLACKLIST ob,
V$DIAG_ALERT_EXT dae
where
group by .....;
Can someone suggest a way or sample code to achieve it?
I should have provided the exact contents of blacklist table. It currently contains some regex (perl) and I want to convert it to oracle like regex and compare with v$diag_alert_ext message_text column. Below are sample perl regex in my blacklist table.
ORA-0(,|$| )
ORA-48913
ORA-00060
ORA-609(,|$| )
ORA-65011
ORA-65020 ORA-31(,|$| )
ORA-7452 ORA-959(,|$| )
ORA-3136(,|)|$| )
ORA-07445.[kkqctdrvJPPD
ORA-07445.[kxsPurgeCursor –
Your blacklist table looks like like patterns, not regular expressions.
You can write a query like this:
select dae.* -- or whatever columns you want
from V$DIAG_ALERT_EXT dae
where not exists (select 1
from ORA_BLACKLIST ob
where dae.message_text like ob.<column name>
);
This will not have particularly good performance if the tables are large.

Not able to perform COUNT and GROUP BY operations on field elasticsearch SQL

I am using Elasticsearch SQL to fetch data from the elasticsearch index in canvas[Kibana] for visualization.
Here is my ESSQL query:
SELECT COUNT(status), status FROM "indexName" GROUP BY status
Note: field status is of type text
When I try to execute this query the below error occurred:
[essql] > Unexpected error from Elasticsearch:
[verification_exception] Found 1 problem(s) line 1:57: Field [status]
of data type [text] cannot be used for grouping;
No keyword/multi-field defined exact matches for [status]; define one
or use MATCH/QUERY instead
thanks in advance.
I think this is because you are not allowed to count or perform aggregations on a text field. The same is mentioned in the error description you have got
"[verification_exception] Found 1 problem(s) line 1:57: Field [status]
of data type [text] cannot be used for grouping;"
AFAIK elastic search tokenises the content of a text field into an inverted index. And so a text like "a room full of brooms" would be indexed into as "a","room","full","of","brooms".
This would depend on the type of analyzer being used also.
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-analyzers.html

jpa postgres - query result difference with like on TEXT fields

I'm trying to make a query to search items structured as follows:
IssueCategory --* Issue (one to many)
using the following JPQL
select count(z) from IssueCategory z join z.issues x
where
lower(cast(function('lo_get', cast(x.diagnosis as integer)) as text)) like lower(concat('TEXT TO SEARCH', '%'))
where diagnosis is a Issue's String field with #Lob annotation, mapped as a text field in postgres:
CREATE TABLE issues (
...
diagnosis text,
...
)
this query produces the following query
select count(issuecateg0_.id) as col_0_0_
from issue_categories issuecateg0_
inner join issues issues1_ on issuecateg0_.id=issues1_.category_id
where lower(cast(lo_get(cast(issues1_.diagnosis as int4)) as text)) like lower(('TEXT TO SEARCH'||'%'))
Obviously in origin the "TEXT TO SEARCH" was passed as a parameter to the query.
The problem is: when I execute the JPQL query, it returns 0, but if I execute the generated query directly in postgres, I get 1.
Does anyone know of behaviours like this one?
I finally changed to the following conditions:
lower(function('encode', (function('lo_get', cast(x.diagnosis as integer))), 'escape') like lower(concat('TEXT TO SEARCH', '%'))

Like Clause over an 'Element' - ORACLE APEX

I encounter some problems that i don't understand with APEX.... Well, let's be specific.
I ve got a select element retrieving a top 50 of most liked url (P11_URL). This is populate by a table view, TOp_Domains.
I create an element called "Context" that have to print all text containing the URL selected by the user from the element select. Those Texts come from another table, let's say "twitter_post".
I create a dynamic action (show only) with this sql/statement:
Select TXT, NB_RT, RANK
from myschema.twitter_post
where TXT like '%:P11_URL%'
group by TXT, NB_RT, RANK
.... and it doesn't work... I think APEX don't like like clause... But i don't know how to do. Let's keep in min an url could have been shared by multiple Tweets, that's why this element "context" is important for me.
I tried to bypass the problem by building a State (in french Statique) and a dynamic action that will refresh the state but it doesn't work neither... bouhououououou
TriX
Right click on the 'P11_URL' and create DA. Event :change, Item:P11_URL. As the true action of the DA, select 'Set Value'. Write your query in the sql stmt area. In the page items to submit, select 'P11_URL' . In the 'Affected Items': select 'Context'.
Query should be :
Select TXT, NB_RT, RANK
from myschema.twitter_post
where TXT like '%' || :P11_URL || '%'
group by TXT, NB_RT, RANK
So
Thanks to #Madona... Their example made me realised my mistake. I wrote the answer here for futher help if somebody encouter the same porblem.
A list select element get as arguments a display value (the one you want to be shown in your screen.... if you want so....^^ ) and a return value (in order, I think to linked dynamic actions). So to solved my problem i had to shape my sql statement as:
select hashtags d, hastags r
from my table
order by 1
[let s say that now in Apex it s an object called P1_HASHTAGS]
First step problem solving.
In fact, the ranking as second value, as i put into my sql statement was making some mitsakens into my 'Where like' clause search... well... Newbie am i!
Second step was to correctly formate the sql statement receiving the datas from my select lov (P1_HASHTAGS) into my interactive report. As shown here:
Select Id, hashtags
from my table
where txt like '%'||:P1_HASHTAGS||'%'
And it works!
Thank you Madona your example helped me figure my mistakes!

looking for db2 text function or method I can do a text contain rather than like

I'm looking for a db2 function that does a text contain search. At present I am running the following query against the data below....
SELECT distinct
s.search_id,
s.search_heading,
s.search_url
FROM repman.search s, repman.search_tags st
WHERE s.search_id = st.search_id
AND ( UPPER(s.search_heading) LIKE (cast('%REPORT%' AS VARGRAPHIC(32)))
OR (UPPER(st.search_tag) LIKE cast('%REPORT%' AS VARGRAPHIC(32)))
)
ORDER BY s.search_heading;
Which returns...
But if I change the search text to %REPORTS% rather than %REPORT% (which I need to do) the like search does not work and I get zero results.
I read a link that used a function named CONTAINS like below but when trying to use the function I get an error.
SELECT distinct
s.search_id,
s.search_heading,
s.search_url
FROM repman.search s, repman.search_tags st
WHERE s.search_id = st.search_id
AND CONTAINS(s.search_heading, 'REPORTS') = 1
Has anynoe got any suggestions? I'm on db2 version DB2/LINUXPPC 9.1.6.
Thanks
In order to look for a pattern in a string, you can use Regular Expressions. They are built-in DB2 with xQuery since DB2 v9. There are also other ways to do that. I wrote an article in my blog (in Spanish that you can translate) about Regular Expressions in DB2.
xmlcast(xmlquery('fn:matches(\$TEXT,''^[A-Za-z 0-9]*$'')')