Sphinx Search use_boundaries in SINPPET - sphinx

I have an index rt with following configuration
index rt
{
type = rt
min_stemming_len = 4
morphology = stem_en
wordforms = /home/mis/syns.txt
exceptions = /home/mis/exp.txt
# english charset defined with alias
#charset_table = 0..9, english, _
phrase_boundary = ., ?, !
path = /var/lib/sphinxsearch/data/rt
rt_field = title
rt_field = content
rt_attr_string = content
rt_attr_string = title
rt_attr_uint = gid
}
and data in Index is
mysql> select * from rt;
+------+------+--------------------------------------------------------------------+-------+
| id | gid | content | title |
+------+------+--------------------------------------------------------------------+-------+
| 1 | 2 | This is a test with walks. Then No data shown. Wow This is fine. | test1 |
| 2 | 2 | This is a test with walks | test1 |
+------+------+--------------------------------------------------------------------+-------+
2 rows in set (0.00 sec)
I would like to get only "Wow This is fine." From rt index with snippet.
I set boundaries to the index. So that i can use the use_boundaries option for spippent. But still i am not getting the excepted result.
SELECT id, SNIPPET(content, 'wow', 'use_boundaries=1') as t FROM rt;
+------+---------------------------------------------------------------------------+
| id | t |
+------+---------------------------------------------------------------------------+
| 1 | This is a test with walks. Then No data shown. <b>Wow</b> This is fine. |
| 2 | This is a test with walks |
+------+---------------------------------------------------------------------------+
2 rows in set (0.01 sec)
any way i can use phrase_boundary to return the result by 'sentence'

Dont see any reason why use_boundaries wouldnt work.
Sounds like you also want limit_passages=1 to get just the one passage in result.
Maybe also allow_empty=1, to deal with the second document, where its been unable to highlight the query word.

Related

postgres how to update append and cut string

I have a table looks like below:
id | name | type | info | ksid | iv
----+-------+------+-------------------------------------------------------+------+----------------------------------
1 | local | 1 | "keyId"=>"1234", "server"=>"http://10.10.13.10/keys/" | | 30646462653237643965373830343334
how to append string to info so that the info value is
"keyId"=>"1234", "server"=>"http://10.10.13.10/keys/", "period"=>"0"
And after the changing, how to change back to
"keyId"=>"1234", "server"=>"http://10.10.13.10/keys/"
you can add value with:
UPDATE yourtable SET info = info || '"period"=>"0"' :: hstore WHERE id = 1;
and remove with:
UPDATE yourtable SET info = delete(info, 'period') WHERE id = 1;

orient DB search on datetime field and get result data from linked dataset

I am quite new to OrientDB and have some trouble that keeps me for days now:
I have two classes. "PAGES" is holding information about pages, "CHECKS" contains information about checks on these pages.
They are connected by a 1 > n linkset called page2chck
It looks like this
Class PAGES
+----+---------+---------------------------------+
| Id | Title | Url |
+----+-------------------------------------------+
| 30 | Blahbla | http://www.test.com/test.html |
+----+-------------------------------------------+
| 40 | sometxt | http://www.foo.org/dummy.html |
+----+-------------------------------------------+
Class CHECKS
+---------------------+---------+
| Lastcheck | Status |
+-------------------------------+
| 2016-02-01 23:58:12 | OK |
+-------------------------------+
| 2016-02-02 22:04:24 | OK |
+-------------------------------+
| 2016-02-02 23:57:55 | ERR |
+-------------------------------+
| 2016-02-01 23:59:01 | OK |
+-------------------------------+
I created a linkset like this
CREATE LINK page2chck TYPE LINKSET FROM CHECKS.CH_PID to PAGES.Id INVERSE
Now I want to retrieve all Pages that do not have a check after 2016-02-03, and I want to show the last date they were checked and the status
What I tried was:
select Title, page2chck.Lastcheck, page2chck.Status from PAGES
where date.asLong(page2chck.Lastcheck) < 1454540400
But it returns an empty result
However, to test the integrity of the relation I ran
select Title from PAGES where page2chck.CH_PID=30
which correctly returns "BlahBlah"
So I tried
page2chck.Lastcheck, page2chck.Status, Title from PAGES
where page2chck.CH_PID=30
which returned
# |#CLASS|page2chck|page2chck|Title
----+------+---------+---------+---------------------------------
0 |null |[441] |[441] |BlahBlah
So basically I have two problems here:
How can I run comparison on the date of a linked class and
how can I show the fields of this class?
CREATE LINK page2chck TYPE LINKSET FROM CHECKS.CH_PID to PAGES.Id INVERSE
Now From console
From Studio
You can use this query
SELECT Title, $checks[0].Lastcheck as Lastcheck , $checks[0].Status as Status FROM PAGES
let $a = (select EXPAND(page2chck) from $parent.$current),
$checks= ( select Lastcheck, Status from $a where Lastcheck in
( select max(Lastcheck) from $a where Lastcheck < DATE("2016-02-03 00:00:00")))
From console
From Studio
If you want to retrieve all Pages that do not have a check after 2016-02-03
you can use this query
select from (SELECT Title, $checks[0].Lastcheck as Lastcheck , $checks[0].Status as Status FROM PAGES
let $a = ( select EXPAND(page2chck) from $parent.$current),
$checks= ( select Lastcheck, Status from $a where Lastcheck in ( select max(Lastcheck) from $a))
) where Lastcheck < DATE("2016-02-03 00:00:00")
Hope it helps.
I think I've found one of the problems in your query
select Title, page2chck.Lastcheck, page2chck.Status from PAGES where date.asLong(page2chck.Lastcheck) < 1454540400
1454540400 means 1970-01-17 21:02:20, verifiable by
select DATE(1454540400)
----+------+-------------------
# |#CLASS|DATE
----+------+-------------------
0 |null |1970-01-17 21:02:20
----+------+-------------------
BTW, you could create the linklist without the INVERSE
CREATE LINK chck2page TYPE LINKSET FROM CHECKS.CH_PID to PAGES.Id
and querying like this:
orientdb {db=pages_checks}> select chck2page.title, lastcheck, status from CHECKS where lastcheck < DATE("2016-02-01 23:59:10")
----+------+---------+-------------------+------
# |#CLASS|chck2page|lastcheck |status
----+------+---------+-------------------+------
0 |null |blablabla|2016-02-01 23:58:12|OK
1 |null |foo |2016-02-01 23:59:01|OK
----+------+---------+-------------------+------

cassandra 2.0.7 cql SELECT Secific Value from map

ALTER TABLE users ADD todo map;
UPDATE users SET todo = { '1':'1111', '2':'2222', '3':'3' ,.... } WHERE user_id = 'frodo';
now ,i want to run the follow cql ,but failed ,is here any other method ?
SELECT user_id, todo['1'] FROM users WHERE user_id = 'frodo';
ps:
the length my map can change. for example : { '1':'1111', '2':'2222', '3':'3' } or { '1':'1111', '2':'2222', '3':'3', '4':'4444'} or { '1':'1111', '2':'2222', '3':'3', '4':'4444' ...}
If you want to use a map collection, you'll have the limitation that you can only select the collection as a whole (docs).
I think you could use the suggestion from the referenced question, even if the length of your map changes. If you store those key/value pairs for each user_id in separate fields, and make your primary key based on user_id and todo_k, you'll have access to them in the select query.
For example:
CREATE TABLE users (
user_id text,
todo_k text,
todo_v text,
PRIMARY KEY (user_id, todo_k)
);
-----------------------------
| user_id | todo_k | todo_v |
-----------------------------
| frodo | 1 | 1111 |
| frodo | 2 | 2222 |
| sam | 1 | 11 |
| sam | 2 | 22 |
| sam | 3 | 33 |
-----------------------------
Then you can do queries like:
select user_id,todo_k,todo_v from users where user_id = 'frodo';
select user_id,todo_k,todo_v from users where user_id = 'sam' and todo_k = 2;

How do you do a "where in" sql query with an array data type?

I have a field:
dtype ==> character varying(3)[]
... but it's an array. So I have for example:
ID | name | dtype
1 | one | {'D10', 'D20', 'D30'}
2 | sam | {'D20'}
3 | jax | {'D10', 'D20'}
4 | pam | {'D10', 'D30'}
5 | pot | {'D10'}
I want to be able to do something like this:
select * from table where dtype in ('D20', 'D30')
This syntax doesnt work, but the goal is to then return fields 1,2,3,4 but not 5.
Is this possible?
Use the && operator as shown in the PostgreSQL manual under "array operators".
select * from table where dtype && ARRAY['D20', 'D30']

Update a single value in a database table through form submission

Here is my table in the database :
id | account_name | account_number | account_type | address | email | ifsc_code | is_default_account | phone_num | User
-----+--------------+----------------+--------------+---------+------------------------------+-----------+--------------------+-------------+----------
201 | helloi32irn | 55265766432454 | Savings | | mypal.appa99721989#gmail.com | 5545 | f | 98654567876 | abc
195 | hello | 55265766435523 | Savings | | mypal.1989#gmail.com | 5545 | t | 98654567876 | axyz
203 | what | 01010101010101 | Current | | guillaume#sample.com | 6123 | f | 09099990 | abc
On form submission in the view, which only posts a single parameter which in my case is name= "activate" which corresponds to the column "is_default_account" in the table.
I want to change the value of "is_default_account" from "t" to "f". For example here in the table, for account_name "hello" it is "t". And i want to deactivate it, i.e make it "f" and activate any of the other that has been sent trough the form
This will update your table and make account 'what' default (assuming that is_default_account is BOOLEAN field):
UPDATE table
SET is_default_account = (account_name = 'what')
You may want limit updates if table is more than just few rows you listed, like this:
UPDATE table
SET is_default_account = (account_name = 'what')
WHERE is_default_account != (account_name = 'what')
AND <limit updates by some other criteria like user name>
I think to accomplish what you want to do you should send at least two values from the form. One for the id of the account you want to update and the other for the action (activate here). You can also just send the id and have it toggle. There are many ways to do this but I can't figure out exactly what you are trying to do and whether you want SQL or Playframework code. Without limiting your update in somewhere (like id) you can't precisely control what specific rows get updated. Please clarify your question and add some more code if you want help on the playframework side, which I would think you do.