質問

I have a searchable model setup as:

class Tag{
   def searchable = true
   String name
}

class PersonTag{
    static belongsTo = [person: Person]
    static searchable = {
        tag(component: true)
        person(component: true)
    }
    static PersonTag addTag(String name, Person person){
      if(person && person.id){
          def tag = Tag.findOrCreate(name)
          def t = new PersonTag(tag:tag, person:person)
          t.save(flush:true)
          return t
      }
    }
}

class Person{
    static searchable = {
        name boost: 2.0
        tags component:true         
    }
}

What I am working on is searching "Persons" by tags. When my server starts it indexes everything and all existing tags on people work. If I add a new tag, I can not search for it until a server restart. However if I change a simple property like the persons name, I am able to search for it w/o a restart. All of my changes for tags are going through a PeopleAdminController.

Any suggestions on why searching by tags is not working? I have even tried to manually index/reindex Person, Tag, and PersonTag via the domainInstance.reindex(), as well as in the controller using the searchableService.

I am searching for People in a different controller PeopleController:

def search(){
    def result = People.search("${params.q}")
        render (view: '/searchable/search.gsp' , model:[searchResult: result])
}
役に立ちましたか?

解決

Well I found a way to "fix the issue" but i dont like it(because its a reindexAll()). After I add the tag if I call:

searchableService.reindexAll()

It will work. I dont understand why the following wouldn't work:

static PersonTag addTag(String name, Person person){
  if(person && person.id){
      def tag = Tag.findOrCreate(name)
      def t = new PersonTag(tag:tag, person:person)
      t.save(flush:true)

      t.index()
      tag.reindex()
      person.reindex()
      return t
  }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top