This repository has been archived by the owner on Sep 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elasticsearch: asciifolding (issue #10)
- Loading branch information
1 parent
6a777cb
commit 8183bac
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from haystack.backends.elasticsearch_backend import ElasticsearchSearchBackend | ||
from haystack.backends.elasticsearch_backend import ElasticsearchSearchEngine | ||
|
||
|
||
class AsciifoldingElasticBackend(ElasticsearchSearchBackend): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(AsciifoldingElasticBackend, self).__init__(*args, **kwargs) | ||
analyzer = { | ||
"ascii_analyser": { | ||
"tokenizer": "standard", | ||
"filter": ["standard", "asciifolding", "lowercase"] | ||
}, | ||
"ngram_analyzer": { | ||
"type": "custom", | ||
"tokenizer": "lowercase", | ||
"filter": ["haystack_ngram", "asciifolding"] | ||
}, | ||
"edgengram_analyzer": { | ||
"type": "custom", | ||
"tokenizer": "lowercase", | ||
"filter": ["haystack_edgengram", "asciifolding"] | ||
} | ||
} | ||
self.DEFAULT_SETTINGS['settings']['analysis']['analyzer'] = analyzer | ||
|
||
def build_schema(self, fields): | ||
content_field_name, mapping = super(AsciifoldingElasticBackend, self).build_schema(fields) | ||
|
||
for field_name, field_class in fields.items(): | ||
field_mapping = mapping[field_class.index_fieldname] | ||
|
||
if field_mapping['type'] == 'string' and field_class.indexed: | ||
if not hasattr(field_class, 'facet_for') and not field_class.field_type in('ngram', 'edge_ngram'): | ||
field_mapping['analyzer'] = "ascii_analyser" | ||
|
||
mapping.update({field_class.index_fieldname: field_mapping}) | ||
return (content_field_name, mapping) | ||
|
||
|
||
class AsciifoldingElasticSearchEngine(ElasticsearchSearchEngine): | ||
backend = AsciifoldingElasticBackend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters