2015-05-17 4 views
4

В моем приложении symfony2 я использую пакет FOS Elastica для выполнения поиска.Как правильно настроить анализаторы и фильтры FOS Elastica?

Я попытался настроить анализаторы и фильтры, но кажется, что они просто не имеют никакого эффекта. Например, если я ищу слово «торт», объекты, содержащие фразу предложения «Торт», не будут возвращены.

Как я могу правильно настроить эти анализаторы и фильтры?

Мой конфиг:

#Elastic Search 
fos_elastica: 
    default_manager: orm 
    clients: 
     default: { host: localhost, port: 9200 } 
    indexes: 
     website: 
      client: default 
      settings: 
       index: 
        analysis: 
         analyzer: 
          custom_index_analyzer : 
           type  : custom 
           tokenizer: nGram 
           filter : [stopwords, asciifolding ,lowercase, snowball, elision, worddelimiter] 
          custom_search_analyzer : 
           type  : custom 
           tokenizer: nGram 
           filter : [stopwords, asciifolding ,lowercase, snowball, elision, worddelimiter] 
         tokenizer: 
          nGram: 
           type:  nGram 
           min_gram: 1 
           max_gram: 2 
         filter: 
          snowball: 
           type:  snowball 
           language: French 
          elision: 
           type:  elision 
           articles: [l, m, t, qu, n, s, j, d] 
          stopwords: 
           type:  stop 
           stopwords: [_french_] 
           ignore_case : true 
          worddelimiter : 
           type:  word_delimiter 
      index_name: foodmeup 
      types: 
       recipe: 
        mappings: 
         name: 
          boost: 5 
          index_analyzer : custom_index_analyzer 
          search_analyzer : custom_search_analyzer 
         nickName: 
          index_analyzer : custom_index_analyzer 
          search_analyzer : custom_search_analyzer 
         content: 
          index_analyzer : custom_index_analyzer 
          search_analyzer : custom_search_analyzer 
         recipeIngredients: 
          type: "nested" 
          properties: 
           name: 
            index_analyzer : custom_index_analyzer 
            search_analyzer : custom_search_analyzer 
           product: 
            type: "nested" 
            properties: 
             name: { type: string, boost: 10} 
             nickName: { type: string } 
             content: { type: string } 
             tags: 
              type: "nested" 
              boost: 5 
              properties: 
               name: { type: string } 
         userRecipes: 
          type: "nested" 
          properties: 
           name: 
            index_analyzer : custom_index_analyzer 
            search_analyzer : custom_search_analyzer 
           content: 
            index_analyzer : custom_index_analyzer 
            search_analyzer : custom_search_analyzer 
         tags: 
          type: "nested" 
          boost: 5 
          properties: 
           name: 
            index_analyzer : custom_index_analyzer 
            search_analyzer : custom_search_analyzer 
        persistence: 
         driver: orm 
         model: AppBundle\Entity\FoodAnalytics\Recipe 
         repository: AppBundle\Repository\FoodAnalytics\RecipeRepository 
         provider: ~ 
         finder: ~ 
         listener: ~ # by default, listens to "insert", "update" and "delete" 
       product: 
        mappings: 
         name: { type: string, boost: 10} 
         nickName: { type: string } 
         content: { type: string } 
         userIngredients: 
          type: "nested" 
          properties: 
           name: { type: string } 
           content: { type: string } 
         tags: 
          type: "nested" 
          boost: 5 
          properties: 
           name: { type: string } 
        persistence: 
         driver: orm 
         model: AppBundle\Entity\MarketPlace\Product 
         repository: AppBundle\Repository\MarketPlace\ProductRepository 
         provider: ~ 
         finder: ~ 
         listener: ~ # by default, listens to "insert", "update" and "delete" 
       user: 
        mappings: 
         firstName: { type: string, boost: 3} 
         lastName: { type: string, boost: 10 } 
         content: { type: string } 
         username: { type: string } 
         email: { type: string } 
         jobSeeker: 
          type: "nested" 
          properties: 
           skills: 
            type: "nested" 
            properties: 
             name: { type: string } 
           experiences: 
            type: "nested" 
            properties: 
             position: 
              type: "nested" 
              properties: 
               name: { type: string } 
             content: { type: string } 
           trainings: 
            type: "nested" 
            properties: 
             name: { type: string } 
             content: { type: string } 
             diploma: 
              type: "nested" 
              properties: 
               name: { type: string } 
        persistence: 
         driver: orm 
         model: AppBundle\Entity\User\User 
         repository: AppBundle\Repository\User\UserRepository 
         provider: ~ 
         finder: ~ 
         listener: ~ # by default, listens to "insert", "update" and "delete" 
       organization: 
        mappings: 
         name: { type: string, boost: 10} 
         legalName: { type: string, boost: 10} 
         shortDescription: { type: string, boost: 3} 
         route: { type: string} 
         content: { type: string } 
        persistence: 
         driver: orm 
         model: AppBundle\Entity\User\Organization 
         repository: AppBundle\Repository\User\OrganizationRepository 
         provider: ~ 
         finder: ~ 
         listener: ~ # by default, listens to "insert", "update" and "delete" 
       offer: 
        mappings: 
         name: { type: string, boost: 10} 
         content: { type: string } 
         responsibilities: { type: string } 
         skills: 
          type: "nested" 
          properties: 
           name: { type: string } 
         contractType: 
          type: "nested" 
          properties: 
           name: { type: string } 
         position: 
          type: "nested" 
          properties: 
           name: { type: string, boost: 10 } 
        persistence: 
         driver: orm 
         model: AppBundle\Entity\Job\Offer 
         repository: AppBundle\Repository\Job\OfferRepository 
         provider: ~ 
         finder: ~ 
         listener: ~ 
       post: 
        mappings: 
         name: { type: string, boost: 10} 
         content: { type: string } 
         summary: { type: string } 
         tags: 
          type: "nested" 
          boost: 5 
          properties: 
           name: { type: string } 
         comments: 
          type: "nested" 
          properties: 
           content: { type: string } 
        persistence: 
         driver: orm 
         model: AppBundle\Entity\Social\Post 
         repository: AppBundle\Repository\Social\PostRepository 
         provider: ~ 
         finder: ~ 
         listener: ~ 

Запрос является одним из основных один:

$finder = $this->container->get('website.recipe') 
$elasticaResults = $finder->find($search); 
+0

Как мы можем помочь вам без запроса ... –

+0

хорошо, запрос работает нормально, это конфигурация, которая нуждается в некоторой настройке. Я добавил запрос на случай, если он что-то изменит, но я так не верю ... или я ошибаюсь? –

+0

На первый взгляд, ваш файл конфигурации кажется прекрасным (по крайней мере, для меня). У меня есть несколько вопросов: - Вы заполняете индекс любыми данными? php app/console f: e: p --index = веб-сайт - у вас есть тестовый запрос с помощью [головного плагина] (http://mobz.github.io/elasticsearch-head/)? Я переместил свой «ответ» в этом комментарии. –

ответ

0

Каждый раз, когда вы обновляете fos_elasticaconfig файл, вам нужно в первый раз, чтобы обновить индекс (ов) с командой:

php app/console fos:elastica:populate --index website --type= <<you type>> 

Эта команда будет переиндексировать ваши данные с помощью стирания Предыдущая. Во второй раз вам нужно будет проверить свою картографическую информацию, чтобы проверить, все ли в порядке и синхронно.

Вы можете проверить свой анализатор с помощью этой команды:

curl 'http://<<yourdomain>>:9200/website/_analyze?pretty=true&analyzer=custom_french_analyzer' -d "Cake"