Пример #1
0
    def message_belongs_to(self, discussion_id, message_id):
        """Search if a message belongs to a discussion"""

        msg = IndexedMessage.get(message_id,
                                 using=self.proxy,
                                 index=self.index)
        return str(msg.discussion_id) == str(discussion_id)
Пример #2
0
def setup_shard_index(shard):
    """Setup a shard index."""
    url = Configuration('global').get('elasticsearch.url')
    client = Elasticsearch(url)

    try:
        log.info('Creating index {0}'.format(shard))
        client.indices.create(index=shard,
                              body={
                                  "settings": {
                                      "analysis": {
                                          "analyzer": {
                                              "text_analyzer": {
                                                  "type": "custom",
                                                  "tokenizer": "lowercase",
                                                  "filter": ["ascii_folding"]
                                              },
                                              "email_analyzer": {
                                                  "type": "custom",
                                                  "tokenizer":
                                                  "email_tokenizer",
                                                  "filter": ["ascii_folding"]
                                              }
                                          },
                                          "filter": {
                                              "ascii_folding": {
                                                  "type": "asciifolding",
                                                  "preserve_original": True
                                              }
                                          },
                                          "tokenizer": {
                                              "email_tokenizer": {
                                                  "type": "ngram",
                                                  "min_gram": 3,
                                                  "max_gram": 25
                                              }
                                          }
                                      }
                                  }
                              })
    except Exception as exc:
        log.warn("failed to create index {} : {}".format(shard, exc))
        return

    # TOFIX
    # core Message is no more in core_registry, use hard coded build mapping
    from caliopen_main.message.store.message_index import IndexedMessage
    from caliopen_main.contact.store.contact_index import IndexedContact
    log.info(
        'Creating index mapping for message and contact in shard {}'.format(
            shard))
    message_mapping = IndexedMessage.build_mapping()
    message_mapping.save(shard, using=client)
    contact_mapping = IndexedContact.build_mapping()
    contact_mapping.save(shard, using=client)
Пример #3
0
 def _prepare_search(self):
     """Prepare a dsl.Search object on current index."""
     search = IndexedMessage.search(using=self.proxy, index=self.index)
     search = search.filter('term', user_id=self.user_id)
     return search
Пример #4
0
 def _prepare_search(self):
     """Prepare a dsl.Search object on current index."""
     search = IndexedMessage.search(using=self.proxy, index=self.index)
     return search
Пример #5
0
 def _prepare_search(self):
     """Prepare a dsl.Search object on current index."""
     search = IndexedMessage.search(using=self.proxy,
                                    index=self.index)
     search = search.filter('term', user_id=self.user_id)
     return search
Пример #6
0
    def message_belongs_to(self, discussion_id, message_id):
        """Search if a message belongs to a discussion"""

        msg = IndexedMessage.get(message_id, using=self.proxy, index=self.index)
        return str(msg.discussion_id) == str(discussion_id)