[Support] Error creating View
muelldlr opened this issue · comments
Norman Müller commented
I'm trying to create a View and got the following error:
Code:
analyzer_ngram = ArangoAnalyzer("fuzzy_search_bigram")
analyzer_ngram.set_edge_ngrams(max=3)
analyzer_ngram.type = ArangoAnalyzer._TYPE_NGRAM
analyzer_ngram.set_features()
analyzer_ngram.create(self.arango_db)
analyzer_token = ArangoAnalyzer("en_tokenizer")
analyzer_token.set_stopwords(include_default=False)
analyzer_token.stemming = True
analyzer_token.accent = False
analyzer_token.type = ArangoAnalyzer._TYPE_TEXT
analyzer_token.set_features()
analyzer_token.create(self.arango_db)
# Create Link - a view can hvae 0 to * links
link = Link(name="Publication") # Name of a collection in the database
linkAnalyzers = AnalyzerList(
["fuzzy_search_bigram", "en_tokenizer"])
link.analyzers = linkAnalyzers
# A link can have 0..* fields
# text_en is a predifined analyzer from arango
title_field = Field("title", AnalyzerList(
["fuzzy_search_bigram", "en_tokenizer"]))
abstract_field = Field("abstract", AnalyzerList(
["fuzzy_search_bigram", "en_tokenizer"]))
title_emb_field = Field("title_emb")
abstract_emb_field = Field("abstract_emb")
id_field = Field("_id")
display_field = Field("display_name", AnalyzerList(
["fuzzy_search_bigram", "en_tokenizer"]))
#
# "title_emb": {},
# "title": {},
# "display_name": {},
# "abstract_emb": {},
# "abstract": {},
# "_id": {}
link.add_field(title_field)
link.add_field(abstract_field)
link.add_field(title_emb_field)
link.add_field(abstract_emb_field)
link.add_field(id_field)
link.add_field(display_field)
# create view
view = View('publications_view',
view_type="arangosearch")
# add the link (can have 0 or 1 link)
view.add_link(link)
# can have 0..* primary sort
view.add_primary_sort("title", asc=False)
view.add_stored_value(["title"], compression="lz4")
try:
view.create(self.arango_db)
except Exception as e:
print("Error creating view, please delete the one on DB?", e)
raise e
Roxanne commented
The View fields should use the you probably used from cag.graph_elements.nodes import Field instead of cag.view_wrapper.link.Field. closing issue
Norman Müller commented
Resolved:
The class Field as here imported is wrong!
Changed to from cag.view_wrapper.link import Link, Field as FieldView
and replace Field(...
with ViewField