Strange results when using word_start with Searchkick - searchkick

I'm getting some weird results when using word_start in a query.
My model:
class Label < ApplicationRecord
searchkick word_start: [:name]
end
If run Label.search('A&M', limit: 10).pluck(:name) I get the following returned:
"A&M", "A&M", "A&M", "A&M", "A&M", "A&M", "A&M", "A&M", "A&M", "A&M"]
But when I add match: :word_start (Label.search('A&M', limit: 10, match: :word_start).pluck(:name)) to the query I get:
["Air Music And Media", "Ambush Artist Management", "Arcane Metal Arts", "A&M / Ariola", "Abrams Music Assocaition", "Mt. Angel Abbey", "A&A Music", "Astan Music AG", "A&M AMLH", "Air Mail Archive"]
Why are the "A&M" results not given the highest score when match: :word_start is added? Can anyone explain why this happens?
I could just remove this from the query to satisfy the results I expect for this example, but it could affect others.

Related

ERROR: missing FROM-clause entry for table "director" LINE 2: JOIN directors d ON mo.director.id = d.director.id (BEGINNER LEVEL)

SELECT mo.movie_name,d.first_name,d.last_names FROM movies mo
JOIN directors d ON mo.director.id = d.director.id
WHERE mo.movie_id IN
(SELECT movie_id FROM movie_revenues
WHERE international_takings > domestic_takings);
Following a tutorial on Udemy and keep getting this
Error: missing FROM-clause entry for table "director"
LINE 2: JOIN directors d ON mo.director.id = d.director.id
I have used the exact same syntax and punctation as a video tutorial I get. I also got the same error message when referencing the director table in an earlier query, although I dont understand where the error lies?

ERROR:root:Error running query: RequestError(400, u'parsing_exception', u'no [query] registered for [not]')

I am using metricbeat-6.4.0, elasticsearch-6.4.0, elastalert-0.1.35
I want to set email alerts when any process, suppose notepad++.exe is stopped.
Below is my rule:
realert:
minutes: 60
from_addr: appmonProcess#company.com
alert_text: "Dear User,\n\t notepad++.exe is not running on server IN-MUM-EADMTOOL for the last 15 minutes"
es_host: linux-a2adm.in.company.com
index: metricbeat-6.4.0-*
smtp_host: ismtp.corp.company.com
type: frequency
es_port: 29200
filter:
term:
beat.hostname: IN-MUM-EADMTOOL
not:
term:
system.process.name: notepad++.exe
timeframe:
minutes: 15
alert: email
name: 93__server__IN-MUM-EADMTOOL__system.process.name__eqnotepad++.exe__1__15
email: ["aviral.srivastava#company.com"]
num_events: 1
I am getting below error:
INFO:elastalert:Starting up
WARNING:elasticsearch:GET http://linux-a2adm.in.company:29200/metricbeat-6.4.0-*/_search?_source_include=%40timestamp%2C%2A&ignore_unavailable=true&scroll=30s&size=10000 [status:400 request:0.035s]
ERROR:root:Error running query: RequestError(400, u'parsing_exception', u'no [query] registered for [not]')
INFO:elastalert:Ran 93__server__IN-MUM-EADMTOOL__system.process.name__eqnotepad++.exe__1__15 from 2018-11-09 17:18 India Standard Time to 2018-11-09 17:29 India Standard Time: 0 query hits (0 already seen), 0 matches, 0 alerts sent
INFO:elastalert:Sleeping for 59.895 seconds
Issue with the filter, try using:
filter:
-and:
- term:
beat.hostname: "IN-MUM-EADMTOOL"
- not:
term:
system.process.name: "notepad++.exe"
For Elasticsearch Version > 5, this filter will not work writing queries embedding filters in and, not, or keywords. Instead, you can use query key to write the complete query.
filter:
- query:
query_string:
query: " beat.hostname: IN-MUM-EADMTOOL AND NOT system.process.name: notepad++.exe"
Relevant Documentation states that the kind of filter you have written using keywords like and, not only works for Elasticsearch 2.X or earlier

Sequence not start with a initial number using aparment gem

I try start a sequence with initial number in tenants, but only public schema got this.
Take a look at my migration:
class CreateDisputes < ActiveRecord::Migration[5.0]
def change
create_table :disputes, id: :uuid do |t|
...
t.integer :code
...
end
execute %{
CREATE SEQUENCE disputes_code_seq INCREMENT BY 1
NO MINVALUE NO MAXVALUE
START WITH 1001 CACHE 1
OWNED BY disputes.code;
ALTER TABLE ONLY disputes
ALTER COLUMN code SET DEFAULT nextval('disputes_code_seq'::regclass);
}
...
end
end
Thanks!
I am no expert in apartement gem. But, apartment is not creating the disputes_code_seq in the tenant's schema.
The workaround for this is to uncomment the following line in config/initializers/apartment.rb
# Apartment can be forced to use raw SQL dumps instead of schema.rb for creating new schemas.
# Use this when you are using some extra features in PostgreSQL that can't be respresented in
# schema.rb, like materialized views etc. (only applies with use_schemas set to true).
# (Note: this option doesn't use db/structure.sql, it creates SQL dump by executing pg_dump)
#
config.use_sql = true
With config.user_sql set to true, Apartment migration will create the sequence for tenant. Here is the log(s) from migration and rails console for reference.
Following is the migration log
ubuntu#ubuntu-xenial:~/devel/apartment/testseq$ rails db:migrate
== 20170224161015 CreateDisputes: migrating ===================================
-- create_table(:disputes)
-> 0.0035s
-- execute("\n CREATE SEQUENCE disputes_code_seq INCREMENT BY 1\n NO MINVALUE NO MAXVALUE\n START WITH 1001 CACHE 1\n OWNED BY disputes.code;\n\n ALTER TABLE ONLY disputes\n ALTER COLUMN code SET DEFAULT nextval('disputes_code_seq'::regclass);\n ")
-> 0.0012s
== 20170224161015 CreateDisputes: migrated (0.0065s) ==========================
[WARNING] - The list of tenants to migrate appears to be empty. This could mean a few things:
1. You may not have created any, in which case you can ignore this message
2. You've run `apartment:migrate` directly without loading the Rails environment
* `apartment:migrate` is now deprecated. Tenants will automatically be migrated with `db:migrate`
Note that your tenants currently haven't been migrated. You'll need to run `db:migrate` to rectify this.
Following is the log of tenant creation and adding a row to disputes
irb(main):001:0> Apartment::Tenant.create('tenant2')
<output snipped for brevity>
irb(main):005:0> Apartment::Tenant.switch!('tenant2')
=> "\"tenant2\""
irb(main):006:0> d = Dispute.new
=> #<Dispute id: nil, code: nil, created_at: nil, updated_at: nil>
irb(main):007:0> d.save
(0.2ms) BEGIN
SQL (0.6ms) INSERT INTO "disputes" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", 2017-02-25 03:09:49 UTC], ["updated_at", 2017-02-25 03:09:49 UTC]]
(0.6ms) COMMIT
=> true
irb(main):008:0> d.reload
Dispute Load (0.3ms) SELECT "disputes".* FROM "disputes" WHERE "disputes"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
=> #<Dispute id: 1, code: 1001, created_at: "2017-02-25 03:09:49", updated_at: "2017-02-25 03:09:49">
As you can see in the following log , code is starting with sequence numbers.
irb(main):009:0> d = Dispute.new
=> #<Dispute id: nil, code: nil, created_at: nil, updated_at: nil>
irb(main):010:0> d.save
(0.3ms) BEGIN
SQL (0.6ms) INSERT INTO "disputes" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", 2017-02-25 03:11:13 UTC], ["updated_at", 2017-02-25 03:11:13 UTC]]
(0.5ms) COMMIT
=> true
irb(main):011:0> d.reload
Dispute Load (0.5ms) SELECT "disputes".* FROM "disputes" WHERE "disputes"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
=> #<Dispute id: 2, code: 1002, created_at: "2017-02-25 03:11:13", updated_at: "2017-02-25 03:11:13">

Print hierarchical vertices in a graph [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How to print all the parents of a given node.
Graham's answer is okay, but uses expensive path computations, which are not really required for your use-case.
This is how I've set up your graph:
g = TinkerGraph.open().traversal()
g.addV().property(id, 1).as("v1").
addV().property(id, 2).as("v2").
addV().property(id, 3).as("v3").
addV().property(id, 4).as("v4").
addV().property(id, 5).as("v5").
addV().property(id, 6).as("v6").
addV().property(id, 7).as("v7").
addV().property(id, 8).as("v8").
addE("black").from("v2").to("v1").
addE("black").from("v7").to("v2").
addE("black").from("v8").to("v7").
addE("orange").from("v8").to("v7").
addE("black").from("v3").to("v2").
addE("black").from("v6").to("v3").
addE("black").from("v4").to("v3").
addE("black").from("v5").to("v4").
addE("orange").from("v5").to("v4").iterate()
Now, to get all ancestors, all you need is this:
gremlin> g.V(5).repeat(out().dedup()).emit()
==>v[4]
==>v[3]
==>v[2]
==>v[1]
Likewise you won't need path computations to determine the maximum depth:
gremlin> g.V(5).emit().repeat(out().dedup()).count()
==>5
Here's a sample graph that I think matches the branch you want to traverse.
graph=TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
g=graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
v1 = graph.addVertex(T.label, "vtx", T.id, 1, "name", "alpha")
==>v[1]
v2 = graph.addVertex(T.label, "vtx", T.id, 2, "name", "beta")
==>v[2]
v3 = graph.addVertex(T.label, "vtx", T.id, 3, "name", "gamma")
==>v[3]
v4 = graph.addVertex(T.label, "vtx", T.id, 4, "name", "delta")
==>v[4]
v5 = graph.addVertex(T.label, "vtx", T.id, 5, "name", "epsilon")
==>v[5]
v5.addEdge("parent", v4, T.id, 101)
==>e[101][5-parent->4]
v4.addEdge("parent", v3, T.id, 102)
==>e[102][4-parent->3]
v3.addEdge("parent", v2, T.id, 103)
==>e[103][3-parent->2]
v2.addEdge("parent", v1, T.id, 104)
==>e[104][2-parent->1]
A repeat() loop taking outbound 'parent' edges will traverse 'up' the hierarchy. In the following example, we've told it to start at v[5] and take two 'hops':
g.V(5).repeat(out('parent')).times(2).path()
==>[v[5],v[4],v[3]]
In practice you probably want to keep traversing (i.e. repeating) until you hit some terminating condition which will depend on what you want to achieve.
You might know you want to stop at a particular vertex, e.g. if you know the root of the hierarchy is v[1], or has a particular property:
g.V(5).repeat(out('parent')).until(hasId(1)).path()
==>[v[5],v[4],v[3],v[2],v[1]]
Or you may want to traverse until you hit the top of the hierarchy (i.e. until there are no more outgoing edges):
g.V(5).repeat(out('parent')).until(outE().count().is(0)).path()
==>[v[5],v[4],v[3],v[2],v[1]]
To get the max depth from the root to the furthest leaf node:
Let's add some more vertices to the graph, to match your graph.
v7 = graph.addVertex(T.label, "vtx", T.id, 7, "name", "eta")
==>v[7]
v8 = graph.addVertex(T.label, "vtx", T.id, 8, "name", "theta")
==>v[8]
v6 = graph.addVertex(T.label, "vtx", T.id, 6, "name", "zeta")
==>v[6]
v8.addEdge("parent", v7, T.id, 105)
==>e[105][8-parent->7]
v7.addEdge("parent", v2, T.id, 106)
==>e[106][7-parent->2]
v6.addEdge("parent", v3, T.id, 107)
==>e[107][6-parent->3]
A traversal from the root toward the leaf vertices will now result in 3 paths:
g.V(1).repeat(__.in('parent')).until(inE().count().is(0)).path()
==>[v[1],v[2],v[3],v[6]]
==>[v[1],v[2],v[7],v[8]]
==>[v[1],v[2],v[3],v[4],v[5]]
But you only want the length of the longest path:
g.V(1).repeat(__.in('parent')).until(inE().count().is(0)).path().
......1> tail(1).unfold().count()
==>5
Hope that helps,
Graham

ActiveAdmin sortable error in production

I would like to sort the trainings by their owner, whose name is included in my profile model.
A Training belongs to a Profile.
I have this in my trainings.rb:
column "Owner", :sortable => :profile_name do |training|
if training.profile.nil?
"No associated profile"
else
training.profile.name
end
end
I get this error in production:
Completed 500 Internal Server Error in 19ms
ActionView::Template::Error (PG::UndefinedColumn: ERROR: column "profile_name" does not exist
LINE 1: SELECT "trainings".* FROM "trainings" ORDER BY "profile_na...
^
: SELECT "trainings".* FROM "trainings" ORDER BY "profile_name" desc LIMIT 30 OFFSET 0):
1: insert_tag renderer_for(:index)
You could try the following:
column "Owner", :sortable => 'profile.name' do |training|
Let me know if that works for you!