Search errors

30 views
Skip to first unread message

[jake]

unread,
Sep 29, 2010, 10:08:41 AM9/29/10
to play-framework
I have a play Job that runs in the background inserting Documents into
my database. I have the search-1.2 module installed.

When I try to perform a Search like this:

Query q = Search.search("text:" + query, Document.class);
List<Document> docs = q.fetch();

I get an error.

Here's my model:

package models;

import javax.persistence.Entity;
import play.db.jpa.Model;
import play.modules.search.Field;
import play.modules.search.Indexed;

@Entity
@Indexed
public class Document extends Model {

@Field
public String text;

public Document(String text) {
this.text = text;
}
}

Here's the play Job that does the inserts:

import models.Document;
import play.jobs.Job;
import play.modules.search.Search;

public class DocGrabber extends Job {

public void doJob() {
for (int i = 0; i < 200; i++) {
Document d = new Document("hello " + i);
d.save();
}
}
}


And here's the exception:


Oops: AlreadyClosedException
An unexpected error occured caused by exception
AlreadyClosedException: this IndexReader is closed

play.exceptions.UnexpectedException: Unexpected Error
at play.modules.search.Search.index(Search.java:289)
at play.modules.search.SearchPlugin.onEvent(SearchPlugin.java:27)
at play.PlayPlugin.postEvent(PlayPlugin.java:199)
at play.db.jpa.JPASupport.save(JPASupport.java:183)
at DocGrabber.doJob(DocGrabber.java:12)
at play.jobs.Job.doJobWithResult(Job.java:37)
at play.jobs.Job.call(Job.java:110)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor
$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor
$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:207)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:637)
Caused by: org.apache.lucene.store.AlreadyClosedException: this
IndexReader is closed
at org.apache.lucene.index.IndexReader.ensureOpen(IndexReader.java:
163)
at
org.apache.lucene.index.DirectoryIndexReader.reopen(DirectoryIndexReader.java:
85)
at play.modules.search.Search.dirtyReader(Search.java:357)
at play.modules.search.Search.index(Search.java:286)
... 13 more
10:02:25,218 ERROR ~

@64254e6ki
Internal Server Error (500) for request GET /?query=cowboy

Oops: UnexpectedException
An unexpected error occured caused by exception UnexpectedException:
Unexpected Error

play.exceptions.UnexpectedException: Unexpected Error
at play.modules.search.Search$Query.fetch(Search.java:165)
at controllers.Application.index(Application.java:18)
at play.utils.Java.invokeStatic(Java.java:129)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:139)
at Invocation.HTTP Request(Play!)
Caused by: play.exceptions.UnexpectedException: Unexpected Error
at play.modules.search.Search$Query.executeQuery(Search.java:246)
at play.modules.search.Search$Query.fetch(Search.java:158)
... 4 more
Caused by: org.apache.lucene.store.AlreadyClosedException: this
IndexReader is closed
at org.apache.lucene.index.IndexReader.ensureOpen(IndexReader.java:
163)
at
org.apache.lucene.index.MultiSegmentReader.docFreq(MultiSegmentReader.java:
370)
at org.apache.lucene.search.IndexSearcher.docFreq(IndexSearcher.java:
87)
at org.apache.lucene.search.Similarity.idf(Similarity.java:457)
at org.apache.lucene.search.TermQuery
$TermWeight.<init>(TermQuery.java:44)
at org.apache.lucene.search.TermQuery.createWeight(TermQuery.java:
146)
at org.apache.lucene.search.Query.weight(Query.java:95)
at org.apache.lucene.search.Hits.<init>(Hits.java:72)
at org.apache.lucene.search.Searcher.search(Searcher.java:55)
at play.modules.search.Search$Query.executeQuery(Search.java:206)
... 5 more


Any ideas?

[jake]

Jean-Francois Poux

unread,
Sep 29, 2010, 11:47:37 AM9/29/10
to play-framework
Hi,

Do you have the same error with the head version ? (play install
search-head)

Regards,
Jean-François POUX

[jake]

unread,
Sep 29, 2010, 12:06:44 PM9/29/10
to play-framework
I get a slightly different error with search-head:

@6425kgj1l
Internal Server Error (500) for request GET /?query=cowboy

Oops: UnexpectedException
An unexpected error occured caused by exception UnexpectedException:
Unexpected Error

play.exceptions.UnexpectedException: Unexpected Error
at play.modules.search.Query.fetch(Query.java:90)
at controllers.Application.index(Application.java:18)
at play.utils.Java.invokeStatic(Java.java:129)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:139)
at Invocation.HTTP Request(Play!)
Caused by: play.exceptions.UnexpectedException: Unexpected Error
at play.modules.search.Query.executeQuery(Query.java:173)
at play.modules.search.Query.fetch(Query.java:83)
... 4 more
Caused by: play.modules.search.Query$SearchException: Please re-index
at play.modules.search.Query.executeQuery(Query.java:151)
... 5 more

Jean-Francois Poux

unread,
Sep 29, 2010, 12:24:48 PM9/29/10
to play-framework

Search complains like this when it finds a matching object id in the
index, but the entity can't be retrieved from Jpa. Empty your db and
delete the data/search folder to start again with clean datas, or
while in dev mode, point your browser at http://127.0.0.1:9000/@search
and rebuild your index.

Regards,
Jean-Francois

[jake]

unread,
Sep 29, 2010, 12:36:23 PM9/29/10
to play-framework
Clearing out my db and index seemed to fix it.

That's ok for dev, but what do I do if my index gets corrupted in
production?

[jake]

On Sep 29, 12:24 pm, Jean-Francois Poux <jf.p...@gmail.com> wrote:
> Search complains like this when it finds a matching object id in the
> index, but the entity can't be retrieved from Jpa. Empty your db and
> delete the data/search folder to start again with clean datas, or
> while in dev mode, point your browser athttp://127.0.0.1:9000/@search

Jean-Francois Poux

unread,
Sep 29, 2010, 2:25:45 PM9/29/10
to play-framework
Hi,

It seems you hit a bug in 1.2 that let the index and the database not
synchronized together, and it's not supposed to happen in production.
The module is designed to create and maintain an "indexed view" of
your objects, that's to say your master data is in your jpa/db data.

In case you need to migrate your database, or alter data manually
(SQL), you have two tools to re-create your indexes reading data from
database. Until 1.2, you had to add play.search.reindex=true property
+ restart your application. After 1.2, there's the embed admin in dev
mode to do click do it, per index.

Regards,
Jean-Francois
Reply all
Reply to author
Forward
0 new messages