Improved attachment search.
This commit is contained in:
parent
0406243988
commit
a4593c160f
4 changed files with 22 additions and 13 deletions
|
@ -17,9 +17,20 @@
|
||||||
* Configure Zammad
|
* Configure Zammad
|
||||||
|
|
||||||
* rails r "Setting.set('es_url', 'http://172.0.0.1:9200')"
|
* 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
|
# optional - es with http basic auth
|
||||||
* rails r "Setting.set('es_index', Socket.gethostname + '_zammad')" # optional
|
* 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
|
* Create elastic search indexes
|
||||||
* rake searchindex:rebuild # drop/create/reload
|
* rake searchindex:rebuild # drop/create/reload
|
||||||
|
|
|
@ -51,10 +51,10 @@ returns
|
||||||
attributes = search_index_attribute_lookup( attributes, ticket )
|
attributes = search_index_attribute_lookup( attributes, ticket )
|
||||||
|
|
||||||
# list ignored file extentions
|
# 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
|
# 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
|
# collect article data
|
||||||
articles = Ticket::Article.where( :ticket_id => self.id )
|
articles = Ticket::Article.where( :ticket_id => self.id )
|
||||||
|
@ -84,6 +84,7 @@ returns
|
||||||
|
|
||||||
# check file size
|
# check file size
|
||||||
if true
|
if true
|
||||||
|
# if attachment.content && attachment.content.size / 1024 / 1024 <= attachment_max_size_in_mb
|
||||||
|
|
||||||
# check ignored files
|
# check ignored files
|
||||||
if attachment.filename
|
if attachment.filename
|
||||||
|
|
|
@ -37,7 +37,7 @@ class AddSearchIndex < ActiveRecord::Migration
|
||||||
:name => 'es_attachment_ignore',
|
:name => 'es_attachment_ignore',
|
||||||
:area => 'SearchIndex::Elasticsearch',
|
:area => 'SearchIndex::Elasticsearch',
|
||||||
:description => 'Define attachment extentions which are ignored for 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
|
:frontend => false
|
||||||
)
|
)
|
||||||
Setting.create_or_update(
|
Setting.create_or_update(
|
||||||
|
|
|
@ -117,9 +117,6 @@ class ElasticsearchTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
# simulate upload
|
# simulate upload
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
form_id = '123456789'
|
form_id = '123456789'
|
||||||
|
|
||||||
# add attachments which should get index / .txt
|
# add attachments which should get index / .txt
|
||||||
|
@ -256,7 +253,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
|
||||||
# search for indexed attachment
|
# search for indexed attachment
|
||||||
result = Ticket.search(
|
result = Ticket.search(
|
||||||
:current_user => agent,
|
:current_user => agent,
|
||||||
:query => '"some normal text"',
|
:query => 'some AND normal AND text',
|
||||||
:limit => 15,
|
:limit => 15,
|
||||||
)
|
)
|
||||||
assert(result[0], 'record 1')
|
assert(result[0], 'record 1')
|
||||||
|
@ -264,7 +261,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
result = Ticket.search(
|
result = Ticket.search(
|
||||||
:current_user => agent,
|
:current_user => agent,
|
||||||
:query => '"otrs.org"',
|
:query => 'otrs.org',
|
||||||
:limit => 15,
|
:limit => 15,
|
||||||
)
|
)
|
||||||
assert(result[0], 'record 1')
|
assert(result[0], 'record 1')
|
||||||
|
@ -274,14 +271,14 @@ class ElasticsearchTest < ActiveSupport::TestCase
|
||||||
# search for not indexed attachment
|
# search for not indexed attachment
|
||||||
result = Ticket.search(
|
result = Ticket.search(
|
||||||
:current_user => agent,
|
:current_user => agent,
|
||||||
:query => '"some too big text"',
|
:query => 'some AND too AND big AND text',
|
||||||
:limit => 15,
|
:limit => 15,
|
||||||
)
|
)
|
||||||
assert(!result[0], 'record 1')
|
assert(!result[0], 'record 1')
|
||||||
|
|
||||||
result = Ticket.search(
|
result = Ticket.search(
|
||||||
:current_user => agent,
|
:current_user => agent,
|
||||||
:query => '"Old programmers never die"',
|
:query => 'Old AND programmers AND never AND die',
|
||||||
:limit => 15,
|
:limit => 15,
|
||||||
)
|
)
|
||||||
assert(!result[0], 'record 1')
|
assert(!result[0], 'record 1')
|
||||||
|
|
Loading…
Reference in a new issue