I have a rails project that I need to implement a search box in my project , I decide to use elastic search because performance speed of the query in comparison to SQL query it's important . In this project it's important that user could define type of condition like " < , > != , = " .I ask
question
and someone told me that I could use query string to solve these issues. but I have no idea how could I implement in my project this type of query.
In my project, I use two elasticsearch gems, "elasticsearch-rails" and "elasticsearch-model" and follow this tutorial
for implementation in my project but it's not useful for this issues.
could you please tell me how could I implement query string on the rails project?
This is how you run a query_string on RoR :
Article.search(query: { query_string: { query: "(new york city) OR (big apple)"} })
I just read you want to execute SQL queries on ES. That can be done out of the box using the SQL API.
I found the implementation for elasticsearch-ruby here :
https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-xpack
On this file exactly
https://github.com/elastic/elasticsearch-ruby/blob/master/elasticsearch-xpack/lib/elasticsearch/xpack/api/actions/sql/query.rb
And this is the documentation about
https://rdoc.info/gems/elasticsearch-xpack/Elasticsearch%2FXPack%2FAPI%2FSQL%2FActions:query
Related
I need to get a nested Jira search. I am okay with JQL query but I have a usecase that I don't know how to solve
Company uses project=XTBOW for reporting purpose for executives (Epic)
The company also uses project=XTA for underling development work (Task)
The XTA task are linked to the XTBOW Epic for a subset of task, but not all. (There is a large body of XTA task that are not linked to XTBOW)
I need to get a filter going for all XTA projects that are linked to XTBOW Epics only. I would like to use a filter like this:
project = XTA and "Epic Link" in (<project = XTBOW.key>)
I can manually prove this filter works. But need a way to automate this filter, because the number of tickets being created/tracked in growing exponentially, and if someone deletes a key for XTBOW that is in the "Epic Link" field, the JQL search throws and error because the "Key" is missing.
Example - FYI cf[10231] is the "Epic Link" field:
project in (XTA,XTWOF) and cf[10231] in (XTBOW-42,XTBOW-59)
The overall objective is to download the data to a dataframe. So if there is a better suggestion to even avoid JQL and do it through python. I am all ears. Just need so pointers to start. I am just going this route because I have already built a JIRA-Downloader/Parser using Python.
The easiest way to get subsets of issues is with:
search_issues(jql_str, startAt=0, maxResults=50, validate_query=True, fields=None, expand=None, json_result=None)
You should be able to just pull the issue sets using the queries you already created, just make them into strings.
DOC
LuaSQL, which seems to be the canonical library for most SQL database systems in Lua, doesn't seem to have any facilities for quoting/escaping values in queries. I'm writing an application that uses SQLite as a backend, and I'd love to use an interface like the one specified by Python's DB-API:
c.execute('select * from stocks where symbol=?', t)
but I'd even settle for something even dumber, like:
conn:execute("select * from stocks where symbol=" + luasql.sqlite.quote(t))
Are there any other Lua libraries that support quoting for SQLite? (LuaSQLite3 doesn't seem to.) Or am I missing something about LuaSQL? I'm worried about rolling my own solution (with regexes or something) and getting it wrong. Should I just write a wrapper for sqlite3_snprintf?
I haven't looked at LuaSQL in a while but last time I checked it didn't support it. I use Lua-Sqlite3.
require("sqlite3")
db = sqlite3.open_memory()
db:exec[[ CREATE TABLE tbl( first_name TEXT, last_name TEXT ); ]]
stmt = db:prepare[[ INSERT INTO tbl(first_name, last_name) VALUES(:first_name, :last_name) ]]
stmt:bind({first_name="hawkeye", last_name="pierce"}):exec()
stmt:bind({first_name="henry", last_name="blake"}):exec()
for r in db:rows("SELECT * FROM tbl") do
print(r.first_name,r.last_name)
end
LuaSQLite3 as well an any other low level binding to SQLite offers prepared statements with variable parameters; these use methods to bind values to the statement parameters. Since SQLite does not interpret the binding values, there is simply no possibility of an SQL injection. This is by far the safest (and best performing) approach.
uroc shows an example of using the bind methods with prepared statements.
By the way in Lua SQL there is an undocumented escape function for the sqlite3 driver in conn:escape where conn is a connection variable.
For example with the code
print ("con:escape works. test'test = "..con:escape("test'test"))
the result is:
con:escape works. test'test = test''test
I actually tried that to see what it'd do. Apparently there is also such a function for their postgres driver too. I found this by looking at the tests they had.
Hope this helps.
I'm looking for a search engine, which will let my users to search my website using syntax similar to this gmail's one.
My website is a map-based directory of restaurants and shops so it would be lovely to make it possible to search it using strings like those:
Restaurant's name city:Boston diet:vegetarian
Restaurant's name country:Belgium tags:fast-food
Restaurant's name country:Poland diet:vegan tags:pizza
etc...
Have you any idea what can i use to achieve such a functionality? I've browsed all of the solutions from ruby-toolbox but most of them requires to have some kind of special search server set up. I can do that on my VPS but at first i would love to hear your opinion which one is the most powerfull, dev-friendly and which one covers the functionality described above. Thank you in advance! :)
How about https://github.com/makandra/dusen gem?
It supports gmail-like token search!
You could try to use regexp to extract search params from request:
search_pairs = params[:search].scan(/([a-zA-Z]+):([a-zA-Z]+)/)
>> [ ['country', 'Poland'], ['diet', 'vegan'] ]
My Rails application version is 2.3.11 and I am using acts_as_solr for search.
Search is working fine. My problem is it does not supports partial word search.
"success"
=>Getting search results
"succ"
=>No results
I have found that NGramTokenizerFactory can do that.But it requires to change the solr configuration file schema.xml.
Is there any other alternative solution to support partial word search without changing the solr configuration?
OR
Is there any solr query logic which supports the partial word search?
I have tried adding "succ*" it gives correct result.But still I am not able to search like "*word*".
To use * at the beginning of the word you might need to add ReversedWildcardFilterFactory to your schema
I have a web application with a EF model which I originally designed using a SQL Server 2008 backend. Later on, I decided to use SQL CE for portability, so I converted the model to target Sql CE 4.0. However, I am running into serious performance issues when running this app.
For example, I have a portion in code that retrieves an entity from the database:
Trace.Write("Retrieving node from database", "Application");
var name = value.ToString();
var node = DataContext.Entities.Nodes
.SingleOrDefault(n => n.Name == name);
Trace.Write("Node retrieved from database ", "Application");
When I look at the trace information (trace.axd), those lines of code take a wooping 0.6 seconds!!
Trace Information
Category Message From First(s) From Last(s)
Application Retrieving node from database 0.00057591118424269 0.000576
Application Node retrieved from database 0.595122564460008 0.594547
And this happens everywhere in my application where I query by Name.
Any ideas? I'm guessing I have to define an index on the column, but how would I do that in the EF model?
EDIT : Gramma
EDIT 2: Spelling in Title
I have a sample with some performance advice here, using global.asax: http://erikej.blogspot.com/2011/01/entity-framework-with-sql-server.html and other performance tips here: http://blogs.msdn.com/b/wriju/archive/2011/03/15/ado-net-entity-framework-performance-tips.aspx
I've used the older versions of SQL CE in the past, and I've found that one major bottleneck is opening the connection.
You might try managing the open connection on your own, and passing it into the data context by hand (rather than allowing the context to automatically manage the connection.)