Improved attachment search.

This commit is contained in:
Martin Edenhofer 2015-04-06 22:04:03 +02:00
parent 0406243988
commit a4593c160f
4 changed files with 22 additions and 13 deletions

View file

@ -17,9 +17,20 @@
* Configure Zammad
* rails r "Setting.set('es_url', 'http://172.0.0.1:9200')"
* rails r "Setting.set('es_user', 'elasticsearch')" # optional
* rails r "Setting.set('es_password', 'zammad')" # optional
* rails r "Setting.set('es_index', Socket.gethostname + '_zammad')" # optional
# optional - es with http basic auth
* rails r "Setting.set('es_user', 'elasticsearch')"
* rails r "Setting.set('es_password', 'zammad')"
# optional - extra es index name space
* rails r "Setting.set('es_index', Socket.gethostname + '_zammad')"
# optional - ignore certain file extentions
* rails r "Setting.set('es_attachment_ignore', [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe', '.box', '.mbox' ] )"
# optional - max attachment size which is used by es, default is 50 mb
* rails r "Setting.set('es_attachment_max_size_in_mb', 50 )"
* Create elastic search indexes
* rake searchindex:rebuild # drop/create/reload

View file

@ -51,10 +51,10 @@ returns
attributes = search_index_attribute_lookup( attributes, ticket )
# list ignored file extentions
attachments_ignore = Setting.set('es_attachment_ignore') || [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe' ]
attachments_ignore = Setting.get('es_attachment_ignore') || [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe' ]
# max attachment size
attachment_max_size_in_mb = Setting.set('es_attachment_max_size_in_mb') || 40
attachment_max_size_in_mb = Setting.get('es_attachment_max_size_in_mb') || 40
# collect article data
articles = Ticket::Article.where( :ticket_id => self.id )
@ -84,6 +84,7 @@ returns
# check file size
if true
# if attachment.content && attachment.content.size / 1024 / 1024 <= attachment_max_size_in_mb
# check ignored files
if attachment.filename

View file

@ -37,7 +37,7 @@ class AddSearchIndex < ActiveRecord::Migration
:name => 'es_attachment_ignore',
:area => 'SearchIndex::Elasticsearch',
:description => 'Define attachment extentions which are ignored for Elasticsearch.',
:state => [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe' ],
:state => [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe', '.box', '.mbox' ],
:frontend => false
)
Setting.create_or_update(

View file

@ -117,9 +117,6 @@ class ElasticsearchTest < ActiveSupport::TestCase
)
# simulate upload
form_id = '123456789'
# add attachments which should get index / .txt
@ -256,7 +253,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
# search for indexed attachment
result = Ticket.search(
:current_user => agent,
:query => '"some normal text"',
:query => 'some AND normal AND text',
:limit => 15,
)
assert(result[0], 'record 1')
@ -264,7 +261,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
result = Ticket.search(
:current_user => agent,
:query => '"otrs.org"',
:query => 'otrs.org',
:limit => 15,
)
assert(result[0], 'record 1')
@ -274,14 +271,14 @@ class ElasticsearchTest < ActiveSupport::TestCase
# search for not indexed attachment
result = Ticket.search(
:current_user => agent,
:query => '"some too big text"',
:query => 'some AND too AND big AND text',
:limit => 15,
)
assert(!result[0], 'record 1')
result = Ticket.search(
:current_user => agent,
:query => '"Old programmers never die"',
:query => 'Old AND programmers AND never AND die',
:limit => 15,
)
assert(!result[0], 'record 1')