Duplicate index field definition: - hibernate-search-6

How to handle this scenario? Here is the property defined in my entity class
#Column(nullable = false)
#NotNull
#ApiModelProperty(required = true)
#Size(min = 3, max = 255)
#GenericField(sortable = Sortable.YES)
#FullTextField(analyzer = "lowercaseWhitespaceAnalyzer")
private String title;
Exception:
HSEARCH400520: Duplicate index field definition: 'title'. Index field names must be unique. Look for two property mappings with the same field name, or two indexed-embeddeds with prefixes that lead to conflicting index field names, or two custom bridges declaring index fields with the same name.
Do I need to create two separate fields as shown in the documentation like:
#FullTextField
#KeywordField(name = "title_sort", normalizer = "myNormalizer", sortable = Sortable.YES)
private String title;
If I tried this getting below exception:
Invalid value. Expected 'lowercaseWhitespaceAnalyzer', actual is 'null'
field 'context':
attribute 'type':
failures:
- Invalid value. Expected 'text', actual is 'keyword'
attribute 'analyzer':
failures:
- Invalid value. Expected 'lowercaseWhitespaceAnalyzer', actual is 'null'
field 'context_sort':
failures:
- Missing property mapping

Do I need to create two separate fields as shown in the documentation like:
Yes, indeed, you do.
If I tried this getting below exception:
Invalid value. Expected 'lowercaseWhitespaceAnalyzer', actual is 'null' field 'context': attribute 'type': failures: - Invalid value. Expected 'text', actual is 'keyword' attribute 'analyzer': failures: - Invalid value. Expected 'lowercaseWhitespaceAnalyzer', actual is 'null' field 'context_sort': failures: - Missing property mapping
If you look at the full context of this error (which you didn't include here), you'll notice it says something like "Elasticsearch schema validation failed".
In short, the schema of the index that already exists on Elasticsearch doesn't match what Hibernate Search needs to implement what you described with annotations.
You should drop the Elasticsearch schema and re-create it (you'll lose all indexed data and will need to reindex). You can do it manually, or you can let Hibernate Search do it for you; see this section of the documentation.

Related

`op_name` parameter for `graphene_django`

The django graphene documentation shows a test example like this:
class MyFancyTestCase(GraphQLTestCase):
def test_some_query(self):
response = self.query(
'''
query {
myModel {
id
name
}
}
''',
op_name='myModel'
)
content = json.loads(response.content)
# This validates the status code and if you get errors
self.assertResponseNoErrors(response)
# Add some more asserts if you like
...
They don't have any API documentation for what op_name is, and what we should set it as. I tried to set it to my query name, but get the error:
[{'message': 'Unknown operation named "myQuery".'}]
Operation name is only needed when there are multiple operations in the query string. You only have one operation so the default (None) is fine.
https://docs.graphene-python.org/en/latest/execution/execute/#operation-name
As per my comment:
If the query is a mutation or named query, you must supply the op_name. For annon queries ("{ ... }"), should be None (default)
I am not sure how to create a "named query" with django graphene, but apparently my query is NOT a named query. Leaving op_name as None got my query to work via my unit test.

Loopback 4: How to access table with underscore in name from loopback 4?

I am trying to get data from my data source using loopback 4. It is working fine if the table name is simple and does not contain any special character.
But if there is a table with some special character like Underscore it does not allow me to create a model for that and I am not able to access the data from that table.
I have a table named "my_data" that contains column:- id,first_name,last_name.
But when I use the command lb4 model and pass the model name as my_data it converts it to my-data. and later on, when I call the API it throws an error by saying that relation publi.mydata does not exist.
WARNING: relational database doesn't support {strict: false} mode. {strict: true} mode will be set for model MyData instead.
Unhandled error in GET /my_data?filter=%7B%0A%20%20%22fields%22%3A%20%7B%0A%20%20%20%20%22id%22%3A%20true%2C%0A%20%20%20%20%first_name%22%3A%20true%2C%0A%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%7D%0A%7D: 500 error: relation "public.mydata" does not exist
at Connection.parseE (/Users/apple/others/loopback4/hello/node_modules/pg/lib/connection.js:614:13)
at Connection.parseMessage (/Users/apple/others/loopback4/hello/node_modules/pg/lib/connection.js:413:19)
at Socket.<anonymous> (/Users/apple/others/loopback4/hello/node_modules/pg/lib/connection.js:129:22)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:273:9)
at Socket.Readable.push (_stream_readable.js:214:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
Is ther any way to get data from table named like this? If anyone know how to do this please let me know.
Use settings.table in the #model decorator:
#model({
settings: {
table: 'my_data',
},
})
Further reading
https://loopback.io/doc/en/lb4/Model.html#data-mapping-properties

Odoo error: return self.models[model_name] KeyError: 'res_groups_users_rel'

I need to make UI many2one dopdown list where I can identify users which depend to Manager group role.
Now I have dropdown field:
test = fields.Many2one('res.groups', 'Purchase request type', default=_get_users, track_visibility='onchange')
And I tried to write a function which can identify all users which depend to manager group role.
def _get_users(self):
pickings = self.env['res_groups_users_rel'].search([('gid','=',61)])
pickings_available = []
for picking in pickings:
pickings_available.append(picking)
return pickings_available
And I got an error:
return self.models[model_name]
KeyError: 'res_groups_users_rel'
I don't know how can I change this function and get value from amy2many relation.
I changed my function to:
def _get_users(self):
pickings = self.env['res.groups'].browse(61).users
pickings_available = []
for picking in pickings:
pickings_available.append(picking)
return pickings_available
and field:
test = fields.Many2one('res.users', 'Some text', default=_get_users, track_visibility='onchange')
I logged function _get_users and get values: [res.users(9,), res.users(65,)]
But I still can't get these values on my test field dropdown. What I am doing wrong?
If you are trying to get all users that belong to a group, why not do the following:
self.env['res_groups'].browse(61).users
On a side note, you might get an error, trying to assign a list as default value to a Many2one field.
Also you seem to be assigning users belonging to a group to a field that is specified to store reference to groups.
If you need to have a field to select a user that belongs to group with id 61, you can do the following:
test = fields.Many2one('res.users', 'Some description', domain="[('groups_id', 'in', [61])]")

How to make attribute_names list all attribute names in a document with dynamic attributes

I have a Rails 4.2 application with mongoid in which I'm importing csv files with test results. I can't define all fields in the model because they change from test to test and theres always around 700 of them. I use Dynamic Attributes and importing and displaying works fine.
I'm trying to use attribute_names method to get all attribute names but all I get is those defined in the model. If I don't define anything in the model it comes back with "_id" only. attributes method on the other hand can see attributes in the actual document on the other hand.
>> #results.first.attributes.count
=> 763
>> #results.first.attribute_names
=> ["_id"]
I also tried fields.keys, same problem
>> #results.first.fields.keys
=> ["_id"]
My model at the moment looks like this
class Result
include Mongoid::Document
include Mongoid::Attributes::Dynamic
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
Result.create! row.to_hash
end
end
end
Can somebody explain how to make it work?
Any help greatly appreciated.
This part is not very clear in the documentation.
and this answer doesn't address how you can make your case works ( I really don't know)... but it has one monkey patch at the end...
all I know is why this case not working...
as the documentation states
When dealing with dynamic attributes the following rules apply:
If the attribute exists in the document, Mongoid will provide you with your standard getter and setter methods.
For example, consider a person who has an attribute of "gender" set on the document:
# Set the person's gender to male.
person[:gender] = "Male"
person.gender = "Male"
# Get the person's gender.
person.gender
this is not your case... cause as it appears you are not defining any attributes in your model...
what applies in your case (from the code you showed and problem you described)
If the attribute does not already exist on the document,
Mongoid will not provide you with the getters and setters and will enforce normal method_missing behavior.
In this case you must use the other provided accessor methods: ([] and []=) or (read_attribute and write_attribute).
# Raise a NoMethodError if value isn't set.
person.gender
person.gender = "Male"
# Retrieve a dynamic field safely.
person[:gender]
person.read_attribute(:gender)
# Write a dynamic field safely.
person[:gender] = "Male"
person.write_attribute(:gender, "Male")
as you can see... there is no way for mongoid to add the setter and getter methods in runtime...
Monkey Patch
you could add a field (maybe string, array, hash, whatever suites you) to the document (attribute exists in the document)
on populating the document from the CSV row.. just save what are the fields of the CSV in that field... (hold the CSV keys in it)
use your predefined field (that holds the keys) instead of using .keys.
code example in your case.
class Result
include Mongoid::Document
include Mongoid::Attributes::Dynamic
field :the_field_that_holds_the_keys, type: Array
# ...
end
and in your controller:
#results.first.some_attribute
#=> method missing error
#results.first[:some_attribute]
#=> some_value
#results.first.the_field_that_holds_the_keys
#=> [:some_attribute, :some_other_attribute, :yada]

how to filter items with a certain attribute empty

I'm using boto and DynamoDB and I want to count all the items with Feature attribute empty. I tried the following,
not_empty_ct = db.instance.query_count(
Feature__eq=''
)
But didn't work,
boto.dynamodb2.exceptions.ValidationException: ValidationException: 400 Bad Request
{'message': 'One or more parameter values were invalid: An AttributeValue may not contain an empty string', '__type':
'com.amazon.coral.validate#ValidationException'}
I didn't find too much information in boto's API Docs.
You probably need to do a Scan which you should probably not be doing in your code.