Thinking Sphinx not working in test mode - ruby-on-rails

I'm trying to get Thinking Sphinx to work in test mode in Rails. Basically this:
ThinkingSphinx::Test.init
ThinkingSphinx::Test.start
freezes and never comes back.
My test and devel configuration is the same for test and devel:
dry_setting: &dry_setting
adapter: mysql
host: localhost
encoding: utf8
username: rails
password: blahblah
development:
<<: *dry_setting
database: proj_devel
socket: /tmp/mysql.sock # sphinx requires it
test:
<<: *dry_setting
database: proj_test
socket: /tmp/mysql.sock # sphinx requires it
and sphinx.yml
development:
enable_star: 1
min_infix_len: 2
bin_path: /opt/local/bin
test:
enable_star: 1
min_infix_len: 2
bin_path: /opt/local/bin
production:
enable_star: 1
min_infix_len: 2
The generated config files, config/development.sphinx.conf and config/test.sphinx.conf only differ in database names, directories and similar things; nothing functional.
Generating the index for devel goes without an issue
$ rake ts:in
(in /Users/pupeno/proj)
default config
Generating Configuration to /Users/pupeno/proj/config/development.sphinx.conf
Sphinx 0.9.8.1-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff
using config file '/Users/pupeno/proj/config/development.sphinx.conf'...
indexing index 'user_core'...
collected 7 docs, 0.0 MB
collected 0 attr values
sorted 0.0 Mvalues, 100.0% done
sorted 0.0 Mhits, 99.8% done
total 7 docs, 422 bytes
total 0.098 sec, 4320.80 bytes/sec, 71.67 docs/sec
indexing index 'user_delta'...
collected 0 docs, 0.0 MB
collected 0 attr values
sorted 0.0 Mvalues, nan% done
total 0 docs, 0 bytes
total 0.010 sec, 0.00 bytes/sec, 0.00 docs/sec
distributed index 'user' can not be directly indexed; skipping.
but when I try to do it for test it freezes:
$ RAILS_ENV=test rake ts:in
(in /Users/pupeno/proj)
DEPRECATION WARNING: require "activeresource" is deprecated and will be removed in Rails 3. Use require "active_resource" instead.. (called from /Users/pupeno/.rvm/gems/ruby-1.8.7-p249/gems/activeresource-2.3.5/lib/activeresource.rb:2)
default config
Generating Configuration to /Users/pupeno/proj/config/test.sphinx.conf
Sphinx 0.9.8.1-release (r1533)
Copyright (c) 2001-2008, Andrew Aksyonoff
using config file '/Users/pupeno/proj/config/test.sphinx.conf'...
indexing index 'user_core'...
It's been there for more than 10 minutes, the user table has 4 records.
The database directory look quite diferently, but I don't know what to make of it:
$ ls -l db/sphinx/development/
total 96
-rw-r--r-- 1 pupeno staff 196 Mar 11 18:10 user_core.spa
-rw-r--r-- 1 pupeno staff 4982 Mar 11 18:10 user_core.spd
-rw-r--r-- 1 pupeno staff 417 Mar 11 18:10 user_core.sph
-rw-r--r-- 1 pupeno staff 3067 Mar 11 18:10 user_core.spi
-rw-r--r-- 1 pupeno staff 84 Mar 11 18:10 user_core.spm
-rw-r--r-- 1 pupeno staff 6832 Mar 11 18:10 user_core.spp
-rw-r--r-- 1 pupeno staff 0 Mar 11 18:10 user_delta.spa
-rw-r--r-- 1 pupeno staff 1 Mar 11 18:10 user_delta.spd
-rw-r--r-- 1 pupeno staff 417 Mar 11 18:10 user_delta.sph
-rw-r--r-- 1 pupeno staff 1 Mar 11 18:10 user_delta.spi
-rw-r--r-- 1 pupeno staff 0 Mar 11 18:10 user_delta.spm
-rw-r--r-- 1 pupeno staff 1 Mar 11 18:10 user_delta.spp
$ ls -l db/sphinx/test/
total 0
-rw-r--r-- 1 pupeno staff 0 Mar 11 18:11 user_core.spl
-rw-r--r-- 1 pupeno staff 0 Mar 11 18:11 user_core.tmp0
-rw-r--r-- 1 pupeno staff 0 Mar 11 18:11 user_core.tmp1
-rw-r--r-- 1 pupeno staff 0 Mar 11 18:11 user_core.tmp2
-rw-r--r-- 1 pupeno staff 0 Mar 11 18:11 user_core.tmp7
Nothing gets added to a log when this happens. Any ideas where to go from here?
I can run the command line manually:
/opt/local/bin/indexer --config config/test.sphinx.conf --all
which generates the output as the rake ts:in, so no help there.

The problem was the random ids generated by fixtures. The solution is described on http://freelancing-god.github.com/ts/en/common_issues.html#slow_indexing
Slow Indexing
If Sphinx is taking a
while to process all your records,
there are a few common reasons for
this happening. Firstly, make sure you
have database indexes on any foreign
key columns and any columns you filter
or sort by.
Secondly – are you using fixtures?
Rails’ fixtures have randomly
generated IDs, which are usually
extremely large integers, and Sphinx
isn’t set up to process disparate IDs
efficiently by default. To get around
this, you’ll need to set
sql_range_step in your
config/sphinx.yml file for the
appropriate environments:
development:
sql_range_step: 10000000
I added it to both, development and test environments.

Related

grep --exclude-from: how to include multiple files

If I use --exclude-from multiple times (to include multiple files), will grep just use the last --exclude-from or will it "or" all the filters together as if they had been in one file (and using one --exclude-from)?
Although this is not clear from either the man pages or grep's source code, exclude-from is additive. Here's my example:
Make five files named 'file.a' through 'file.f' each containing 'test_string', and five filters 'ex_a.lst' through 'ex_f.lst' containing '*.a' through '*.f', respectively:
$ for X in a b c d e f; do echo test_string > file.$X; echo file.$X > ex_$X.lst; done
$ ls -l
total 48
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_a.lst
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_b.lst
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_c.lst
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_d.lst
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_e.lst
-rw-rw-r-- 1 user group 7 Jan 17 17:02 ex_f.lst
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.a
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.b
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.c
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.d
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.e
-rw-rw-r-- 1 user group 12 Jan 17 17:02 file.f
$ cat file.a
test_string
$ cat ex_a.lst
file.a
Search for 'test_string' in the current directory, without filters:
$ grep -R test_string | sort
file.a:test_string
file.b:test_string
file.c:test_string
file.d:test_string
file.e:test_string
file.f:test_string
All files matched. Now add three filters from three files:
$ grep -R test_string --exclude-from=ex_a.lst --exclude-from=ex_c.lst --exclude-from=ex_e.lst | sort
file.b:test_string
file.d:test_string
file.f:test_string
We are left with only three results, the ones that weren't filtered out! For this to be the case, we must have selected all three 'ex_[ace].lst' filter files.

Rails 4 SQLite3::ReadOnlyException: attempt to write a readonly database

I keep receiving the error SQLite3::ReadOnlyException: attempt to write a readonly database: UPDATE "users" SET "current_sign_in_at" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = ? when trying to sign into my Rails 4 app which uses the devise gem.
I figured it has something to do with permissions on the dev db so checked out the permissions of the dir first, it has a + tacked onto the end which after some googling still couldn't figure out what it's doing.
-rw-r--r-- 1 a36971 staff 2.1K 24 Jan 20:16 Gemfile
-rw-r--r-- 1 a36971 staff 5.7K 24 Jan 20:16 Gemfile.lock
-rw-r--r-- 1 a36971 staff 47B 7 Jan 22:31 README.md
-rw-r--r--+ 1 root staff 249B 7 Jan 19:57 Rakefile
drwxr-xr-x+ 8 root staff 272B 7 Jan 19:57 app/
drwxr-xr-x+ 7 root staff 238B 7 Jan 19:57 bin/
drwxr-xr-x+ 13 root staff 442B 22 Jan 20:14 config/
-rw-r--r--+ 1 root staff 153B 7 Jan 19:57 config.ru
drwxr-xr-x+ 8 root staff 272B 26 Jan 10:28 db/
drwxr-xr-x+ 4 root staff 136B 7 Jan 19:57 lib/
drwxr-xr-x+ 5 root staff 170B 8 Jan 15:51 log/
drwxr-xr-x+ 7 root staff 238B 7 Jan 19:57 public/
drwxr-xr-x 7 a36971 staff 238B 17 Jan 22:38 spec/
drwxr-xr-x+ 9 root staff 306B 7 Jan 19:57 test/
drwxr-xr-x+ 6 root staff 204B 7 Jan 20:19 tmp/
drwxr-xr-x+ 3 root staff 102B 7 Jan 19:57 vendor/
After cd ing into the db dir you can see there's nothing wrong with the permissions on the db itself:
-rw-r--r-- 1 a36971 staff 44K 26 Jan 09:30 development.sqlite3
drwxr-xr-x 5 a36971 staff 170B 22 Jan 20:14 migrate/
-rw-r--r-- 1 a36971 staff 2.2K 22 Jan 20:14 schema.rb
-rw-r--r-- 1 a36971 staff 1.2K 25 Jan 23:22 seeds.rb
-rw-r--r-- 1 a36971 staff 44K 26 Jan 09:23 test.sqlite3
So my questions are:
a) why is it unable to write to the db when there doesn't appear to be anything wrong with the permissions themselves
b) what does the + mean on mac os?
a) why is it unable to write to the db when there doesn't appear to be anything wrong with the permissions themselves
My best guess is that the db/ directory is owned by the root user, whereas the db/*.sqlite3 files are owned by user a36971. It may be necessary for the db/ directory to also be owned by user a36971.
Try changing the owner from root to a36971 for the db directory:
sudo chown a36971 db
b) what does the + mean on mac os?
+ sign means there are additional permission details not displayed by the default output from ls -l. Try running ls -le to see the details (source: http://tech.enekochan.com/en/2014/05/29/plus-and-at-symbols-listing-file-permissions-in-mac-os-x/).
Got the same error after running rails db:reset
Restarting the local server fixed my problem

idlj parameter invalid argument -td mac?

Im trying to follow a tutorial to do a CORBA assignment.
project
-Client/HelloClient.java
-Server/HelloServer.java
-Hello.idl
I do the first step, trying to compile the IDL (from the project root), and it fails.
$ idlj –td Client –fclient Hello.idl
com.sun.tools.corba.se.idl.InvalidArgument: Invalid argument: –td.
java version "1.8.0_11"
$ ls -l
total 16
drwxr-xr-x 3 juliusskye staff 102 Oct 28 20:14 Client
-rw-r-----# 1 juliusskye staff 85 Oct 28 17:49 Hello.idl
drwxr-xr-x 3 juliusskye staff 102 Oct 28 17:52 Server
-rw-r--r-- 1 juliusskye staff 425 Oct 29 13:45 idljintro.iml
drwxr-xr-x 2 juliusskye staff 68 Oct 29 13:45 src
I found this which says CORBA has problems parsing paths with / in front. But mine doesn't have a /
apparently the Lecturer's instructions were wrong or outdated or the compiler is not fully working but compilation of all files is achieved by
idlj -fall hello.idl

Heroku Pushing My Rails app as Play

I have a rails app called MBAToolbox. When I enter the directory and type "play", I get the following:
This is not a play application!
That's good! Now I type rails c and I am entered into the rails command line. Clearly this is a rails app. But when I type 'heroku create' and push 'git push heroku master', heroku tries to deploy this as a 'play' app?
I saw on their site that Heroku states:
Heroku Play framework support will be applied to applications that
match:
*/conf/application.conf in any directory except for the modules directory
, when determining to use Play.
I don't have that. My directory is as follows:
drwxr-xr-x 21 admin staff 714 Mar 22 00:20 .
drwxr-xr-x 26 admin staff 884 Mar 21 21:39 ..
-rw-r--r--# 1 admin staff 6148 Mar 21 23:37 .DS_Store
-rw-r--r-- 1 admin staff 430 Mar 21 21:39 .gitignore
drwxr-xr-x 12 admin staff 408 Mar 22 00:22 .idea
-rw-r--r-- 1 admin staff 935 Mar 21 22:38 Gemfile
-rw-r--r-- 1 admin staff 3884 Mar 21 22:38 Gemfile.lock
-rw-r--r-- 1 admin staff 9208 Mar 21 21:39 README.rdoc
-rw-r--r-- 1 admin staff 275 Mar 21 21:39 Rakefile
drwxr-xr-x 9 admin staff 306 Mar 21 21:57 app
drwxr-xr-x 10 admin staff 340 Mar 21 21:56 config
-rw-r--r-- 1 admin staff 160 Mar 21 21:39 config.ru
drwxr-xr-x 6 admin staff 204 Mar 22 00:06 db
drwxr-xr-x 3 admin staff 102 Mar 21 21:39 doc
drwxr-xr-x 5 admin staff 170 Mar 21 21:48 lib
drwxr-xr-x 4 admin staff 136 Mar 21 21:39 log
drwxr-xr-x 9 admin staff 306 Mar 21 23:37 public
drwxr-xr-x 3 admin staff 102 Mar 21 21:39 script
drwxr-xr-x 8 admin staff 272 Mar 21 21:39 test
drwxr-xr-x 6 admin staff 204 Mar 21 21:53 tmp
drwxr-xr-x 4 admin staff 136 Mar 21 21:39 vendor
Thoughts?
This article on the Heroku dev site covers both ends of this. It has a pointer to the actual source of the Play buildpack, so you can read the code that figures out which buildpack to use. You can also explicitly pick the Rails buildpack instead.

Ruby on Rails: Use Curl command in localhost

I want to save the content of a page with the system command curl but it's not working.
I think it's a problem with localhost but I don't know how to solve this.
def save_page
`/usr/bin/curl -O http://127.0.0.1:3000/category_plist`
end
Server output:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:04:54 --:--:-- 0
If you change your function to the following it should work ...
def save_page
system("/usr/bin/curl -O http://127.0.0.1:3000/category_plist")
end
To test commands like this, exit your local webserver and run "rails console", from there you can enter a command such as this and get an immediate response ...
$ rails console
Loading development environment (Rails 3.1.0.rc4)
1.9.2-p290 :001 > puts system("ls -l")
total 56
-rw-r--r--# 1 creativetechnologist staff 212 3 Feb 2011 Capfile
-rw-r--r--# 1 creativetechnologist staff 924 6 Feb 2012 Gemfile
-rw-r--r--# 1 creativetechnologist staff 3072 6 Feb 2012 Gemfile.lock
-rw-r--r--# 1 creativetechnologist staff 3943 16 Oct 23:16 MOR_git.tmproj
-rw-r--r--# 1 creativetechnologist staff 18 12 Jul 19:06 README
-rw-r--r--# 1 creativetechnologist staff 267 30 Aug 2011 Rakefile
drwxr-xr-x 7 creativetechnologist staff 238 30 Aug 2011 app
drwxr-xr-x 11 creativetechnologist staff 374 13 Sep 2011 config
-rw-r--r--# 1 creativetechnologist staff 157 30 Aug 2011 config.ru
drwxr-xr-x 6 creativetechnologist staff 204 3 Feb 2011 db
drwxr-xr-x 3 creativetechnologist staff 102 3 Feb 2011 doc
drwxr-xr-x 4 creativetechnologist staff 136 3 Feb 2011 key
drwxr-xr-x 6 creativetechnologist staff 204 7 Sep 2011 lib
drwxr-xr-x 6 creativetechnologist staff 204 11 Mar 2012 log
drwxr-xr-x 3 creativetechnologist staff 102 30 Aug 2011 logs
drwxr-xr-x 13 creativetechnologist staff 442 6 Feb 2012 public
drwxr-xr-x 3 creativetechnologist staff 102 3 Feb 2011 script
drwxr-xr-x 8 creativetechnologist staff 272 3 Feb 2011 test
drwxr-xr-x 6 creativetechnologist staff 204 3 Feb 2011 tmp
drwxr-xr-x 3 creativetechnologist staff 102 3 Feb 2011 vendor
true
=> nil
1.9.2-p290 :002 >
Hope that helps.
Try this:
def save_page
`/usr/bin/curl -s http://127.0.0.1:3000/category_plist` # -s will silent curl's output except the page
end

Resources