Shared Compass/Lucene Index in JDBC Store - grails

Using the searchable plugin in Grails (which uses Compass/Lucene under the hood) we're trying to share a search index between two different web applications. One application accesses the data only in a read-only fashion. The other application allows to modify the data and is in charge of updating the index on any change or do a full re-index on demand.
To store the index we're using the JDBC Store (with both applications pointing to the same DB) http://www.compass-project.org/docs/latest/reference/html/core-connection.html.
Unfortunately, as soon as we rebuild the whole index in one application, the other application seems to have invalid data cached and an exception is thrown if a search is performed:
| Error 2012-05-30 09:22:07,560 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver - IndexOutOfBoundsException occurred when processing request: [POST] /search
Index: 45, Size: 13. Stacktrace follows:
Message: Index: 45, Size: 13
Line | Method
->> 547 | RangeCheck in java.util.ArrayList
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 322 | get in ''
| 265 | fieldInfo . in org.apache.lucene.index.FieldInfos
| 254 | fieldName in ''
| 86 | read . . . in org.apache.lucene.index.TermBuffer
| 127 | next in org.apache.lucene.index.SegmentTermEnum
| 158 | scanTo . . in ''
| 271 | get in org.apache.lucene.index.TermInfosReader
| 332 | terms . . . in ''
| 717 | terms in org.apache.lucene.index.SegmentReader
| 93 | generate . in org.apache.lucene.search.PrefixGenerator
| 58 | getDocIdSet in org.apache.lucene.search.PrefixFilter
| 116 | <init> . . in org.apache.lucene.search.ConstantScoreQuery$ConstantScorer
| 81 | scorer in org.apache.lucene.search.ConstantScoreQuery$ConstantWeight
| 230 | scorer . . in org.apache.lucene.search.BooleanQuery$BooleanWeight
| 131 | search in org.apache.lucene.search.IndexSearcher
| 112 | search . . in ''
| 204 | search in org.apache.lucene.search.MultiSearcher
| 113 | getMoreDocs in org.apache.lucene.search.Hits
| 90 | <init> in ''
| 61 | search . . in org.apache.lucene.search.Searcher
| 146 | findByQuery in org.compass.core.lucene.engine.transaction.support.AbstractTransactionProcessor
| 259 | doFind . . in org.compass.core.lucene.engine.transaction.readcommitted.ReadCommittedTransactionProcessor
| 246 | find in org.compass.core.lucene.engine.transaction.support.AbstractConcurrentTransactionProcessor
| 352 | find . . . in org.compass.core.lucene.engine.LuceneSearchEngine
| 188 | hits in org.compass.core.lucene.engine.LuceneSearchEngineQuery
| 199 | hits . . . in org.compass.core.impl.DefaultCompassQuery
| 104 | doInCompass in grails.plugin.searchable.internal.compass.search.DefaultSearchMethod$SearchCompassCallback
| 133 | execute . . in org.compass.core.CompassTemplate
| 57 | doInCompass in grails.plugin.searchable.internal.compass.support.AbstractSearchableMethod
| 66 | invoke . . in grails.plugin.searchable.internal.compass.search.DefaultSearchMethod
| 37 | search in grails.plugin.searchable.SearchableService
We could communicate the fact that the index is rebuilt from one to the other application so that some clean-up could be performed.
Did anybody have a similar problem with Grails and the Searchable plugin?
Is it possible to discard data cached by Compass/Lucene?
Is it possible to disable caching generally?

Clearing all caches before searching seems to solve the issue...
searchableService.compass.compass.searchEngineFactory.indexManager.clearCache()

Related

How to add slim to rails statistics (stats) for code statistics?

I tried to search and experimented, but couldn't figure out, how to add slim to rails stats views statistics. It is counting only .erb templates, but I want .slim to be added as these are views too.
% bin/rails stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers | 3245 | 1634 | 57 | 218 | 3 | 5 |
| Helpers | 186 | 149 | 0 | 18 | 0 | 6 |
| Jobs | 34 | 20 | 2 | 2 | 1 | 8 |
| Models | 879 | 541 | 25 | 77 | 3 | 5 |
| Mailers | 85 | 53 | 3 | 6 | 2 | 6 |
| Channels | 46 | 28 | 3 | 4 | 1 | 5 |
| Views | 0 | 0 | 0 | 0 | 0 | 0 |
+----------------------+--------+--------+---------+---------+-----+-------+
I could add an extra rules for something like "Slim views", but this would count the .erb templates in views too.

How to replace multiple values across different datasets in SPSS

I currently have two datasets, RTWANEW2016.sav and MERGED.sav.
RTWANEW2016:
+----+------------+--------+--------+--------+--------+--------+--------+
| id | date | value1 | value2 | value3 | value4 | value5 | value6 |
+----+------------+--------+--------+--------+--------+--------+--------+
| 1 | 01-03-2006 | 3 | 9 | 85 | 766 | 3 | 45 |
| 1 | 03-23-2010 | 56 | 34 | 23 | 33 | 556 | 43 |
| 2 | 12-04-2014 | 56 | 655 | 523 | 566 | 9 | 9 |
| 3 | 07-23-2011 | 34 | 56 | 661 | 23 | 22 | 11 |
| 4 | 03-05-2007 | 45 | 345 | 222 | 556 | 4566 | 4 |
+----+------------+--------+--------+--------+--------+--------+--------+
MERGED:
+----+------------+--------+--------+--------+
| id | date | value4 | value5 | value6 |
+----+------------+--------+--------+--------+
| 1 | 01-03-2006 | 345 | 44 | 5345 |
| 2 | 12-04-2014 | 522 | 55 | 5444 |
| 4 | 03-05-2007 | 234 | 88 | 9001 |
+----+------------+--------+--------+--------+
I want to update RTWANEW2016 with the values from variables "value4", "value5" and "value6" from MERGED.
Notice that some data RTWANEW2016 has duplicate ID's, but different dates, so I would need to sort by both id and date
See the UPDATE command which is designed to achieve this.
Overview (UPDATE command)
UPDATE replaces values in a master file with updated values recorded
in one or more files called transaction files. Cases in the master
file and transaction file are matched according to a key variable.
The master file and the transaction files must be IBM® SPSS®
Statistics data files or datasets available in the current session,
including the active dataset. UPDATE replaces values and creates a new
active dataset, which replaces the original active dataset.
UPDATE is designed to update values of existing variables for existing
cases. Use MATCH FILES to add new variables to a data file and ADD
FILES to add new cases.
UPDATE FILE='/RTWANEW2016.sav'
/FILE='/MERGED.sav'
/BY=ID Date.

Login to Grails Application using Google account and OAuth plugin

I am trying to create a login page in which users can use their Google account to login in. I am using grail's 'oauth:2.6.1' plugin to achieve this.
I registered an app in google and got client id and secret, but I am not able to use that in my config.groovy. It throws the below exception:
[http-bio-8080-exec-10] ERROR errors.GrailsExceptionResolver - OAuthException occurred when processing request: [GET] /MyApp/oauth/google/authenticate - parameters:
redirectUrl:
Response body is incorrect. Can't extract token and secret from this: 'Consumer is not registered: 553489692142-6l3c1tk0l0rtc7dgebeijbh5jtcv4tor.apps.googleusercontent.com
'. Stacktrace follows:
Message: Response body is incorrect. Can't extract token and secret from this: 'Consumer is not registered: 553489692142-6l3c1tk0l0rtc7dgebeijbh5jtcv4tor.apps.googleusercontent.com
'
Line | Method
->> 41 | extract in org.scribe.extractors.TokenExtractorImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 27 | extract in ''
| 64 | getRequestToken in org.scribe.oauth.OAuth10aServiceImpl
| 40 | getRequestToken in ''
| 45 | getRequestToken in ''
| 78 | authenticate in uk.co.desirableobjects.oauth.scribe.OauthController
| 198 | doFilter . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . in java.lang.Thread
My grails version is 2.5. Please help me to sort this out.
It seems like your credentials for google api are bad. Check your key/secret in google developer console.

Cucumber table + find("table tr:eq(x)") not working right

I have this cucumber task:
Then I should see following posting modes
| row | day | hour | minute | location | category |
| 1 | 1 | 7 | 0 | 29 | 6 |
| 2 | 2 | 8 | 5 | 27 | 7 |
| 3 | 3 | 9 | 10 | 28 | 18 |
| 4 | 4 | 15 | 15 | 29 | 18 |
| 5 | 5 | 17 | 20 | 27 | 7 |
| 6 | 6 | 20 | 30 | 28 | 6 |
| 6 | 0 | 22 | 50 | 29 | 7 |
And behind it there is this description:
Then /^I should see following posting modes$/ do |table|
table.hashes.each do |posting|
within("#itemPosting .attributeContainer table tbody tr:eq(#{posting[:row]})") do
find("#item_posting_day").value.should == posting[:day]
find("#item_posting_hour").value.should == posting[:hour]
find("#item_posting_minute").value.should == posting[:minute]
find("#item_posting_location").value.should == posting[:location]
find("#item_posting_category").value.should == posting[:category]
end
end
end
So this part:
tr:eq(#{posting[:row]})
doesn't work(it goes to next step, and then gives an error that #item_posting_day is not found.)
But if I do this instead:
tr:eq(4)
It works (finds the #item_posting_day field, gets its value, and then gives an error saying that value is not what is expected to be, but that's ok).
So I don't understand what's the problem with using this syntax:
tr:eq(#{posting[:row]})
It seems that hashes converts column headers to strings, not symbols. Try to use 'row' instead of :row

Does the Searchable plugin work with Grails 2.0.0? (I argue no)

When I upgrade to the project to grails 2.0 (with a fresh install of the searchable plugin), I get a Hibernate class cast exception. Does anybody else get this problem?
http://grails.org/ uses the Searchable plugin and it works with Grails 2.0.3. What issue are you running into?
Searchable is based on Compass which is being rewritten as ElasticSearch.
The ElasticSearch plugin works with Grails 2.0.
For more information see The Future of Compass & ElasticSearch.
Migrating my app from Grails 1.3.7 to 2.1.1 ran into a similar issue. I was able to resolve it by updating the Searchable plugin from 0.5.5 to 0.6.4.
Here's what the stacktrace looked like:
| Error 2012-10-05 19:02:18,691 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error executing bootstraps: org.codehaus.groovy.grails.orm.hibernate.SessionFactoryProxy cannot be cast to org.hibernate.impl.SessionFactoryImpl
Message: org.codehaus.groovy.grails.orm.hibernate.SessionFactoryProxy cannot be cast to org.hibernate.impl.SessionFactoryImpl
Line
| Method
->> 95 | injectLifecycle in org.compass.gps.device.hibernate.lifecycle.DefaultHibernateEntityLifecycleInjector
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 46 | injectLifecycle in org.compass.gps.device.hibernate.lifecycle.DefaultHibernateEntityCollectionLifecycleInjector
| 149 | doStart . . . . in org.compass.gps.device.hibernate.HibernateGpsDevice
| 125 | start in org.compass.gps.device.AbstractGpsDevice
| 73 | start . . . . . in org.compass.gps.device.support.parallel.AbstractParallelGpsDevice
| 166 | start in org.compass.gps.impl.AbstractCompassGps
| 144 | doCall . . . . in SearchableGrailsPlugin$_closure3
| 303 | innerRun in java.util.concurrent.FutureTask$Sync
| 138 | run . . . . . . in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . . . . . in ''
^ 680 | run in java.lang.Thread
| Error 2012-10-05 19:02:18,715 [localhost-startStop-1] ERROR [localhost].[/myApp] - Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
Message: Error executing bootstraps; nested exception is java.lang.ClassCastException: org.codehaus.groovy.grails.orm.hibernate.SessionFactoryProxy cannot be cast to org.hibernate.impl.SessionFactoryImpl
Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 680 | run . . in java.lang.Thread
Caused by ClassCastException: org.codehaus.groovy.grails.orm.hibernate.SessionFactoryProxy cannot be cast to org.hibernate.impl.SessionFactoryImpl
->> 95 | injectLifecycle in org.compass.gps.device.hibernate.lifecycle.DefaultHibernateEntityLifecycleInjector
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 46 | injectLifecycle in org.compass.gps.device.hibernate.lifecycle.DefaultHibernateEntityCollectionLifecycleInjector
| 149 | doStart in org.compass.gps.device.hibernate.HibernateGpsDevice
| 125 | start in org.compass.gps.device.AbstractGpsDevice
| 73 | start . in org.compass.gps.device.support.parallel.AbstractParallelGpsDevice
| 166 | start in org.compass.gps.impl.AbstractCompassGps
| 144 | doCall . in SearchableGrailsPlugin$_closure3
| 303 | innerRun in java.util.concurrent.FutureTask$Sync
| 138 | run . . in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . in ''
^ 680 | run in java.lang.Thread
Yes me too used searchable on grails 1.3.7 , 2.0.3 and now using on 2.1.1
All i have to do was upgrade my searchable plugin to the latest one. Though I had to made some tweaks in the code but every thing was mentioned in the plugin documentation
link to documentation
Mind the imports in the controllers. As I guess the class path has been changed. And this was the only change I made.
This happends because when you upgrade to a Grails version that uses Hibernate 4.X.
This happends because there were several package and class name changes between Hiberate 3.x and 4.x, so code that works with Hibernate 3.x won't work with 4.x except in rare cases. Beyond the name changes, there were big internal changes in how things work, so code that compiles won't necessarily run. App option #1 is to downgrade to Hibernate 3.x. The config settings for that are included and commented out (BuildConfig.groovy, DataSource.groovy), so this a very quick option. Obviously not an option if you depend on a feature added in 4.x, and this just delays the real problem until you have to upgrade Hibernate.

Resources