why text_en doesn't work on type : "vegetable" in arangosearch example - arangodb

i was doing the example provided in the first page of arangosearch in manual of arangodb which is we have a set of documents about foods with two fields : name and type
in the aql query when i set
search analyzer(doc.type == "fruit" , "text_en")
it just works fine , but when i change the value from "fruit" to be "vegetable" it just returns an empty array , text_en is set in indexing time and it is showing it in the configuration of the view , it only works if i change the value back to fruit or use "identity" instead of "text_en"
why is that ? any solutions ?
link to the manual :
https://www.arangodb.com/docs/stable/arangosearch.html#search-expressions-with-arangosearch-functions

so apparently "text_en" turns "vegetable" to "veget" (stems it) and stores it like that in the view , if "text_en" is also applied to the entry value , it works , for example :
search analyzer(doc.type in tokens("vegetable" , "text_en") , "text_en")

Related

Lotus Notes: Controlling input on multi-value fields

I have been using multi-value checkbox field. Now I want to disable some of the checkboxes depending on criteria. For example if field A has value "no license" then disable field B's checkbox with value "car" but leave values "bike" and "train" available for user to select.
Having all the values in the same field would make handling the checked values easier but is it possible to modify multi-value field to work like that?
You need to compute the values allowed in the multi-value check box field based on the value of FieldA.
#If(FieldA = "No License"; "Bike":"Train"; "Car":"Bike":"Train")
You then need to set properties on the Checkbox field like this:
And on FieldA like this:
This will refresh the field choices for the checkbox whenever the value in FieldA changes
There is no way to selectively disable single values from checkbox. You can just remove the option completely so that it cannot be selected anymore.
So instead of just typing the values for the checkbox, use a formula to calculate them like:
#If( fieldA = "no license" ;
"bike" : "train" ;
"car" : "bike" : "train" )
The formula could be as complex / simple as you want. e.g. something like:
_licenseNeeded := "car" : "taxi" : "motorbike";
_other := "bike" : "train";
#Trim( #If( fieldA = "no license" ; ""; _licenseNeeded ) : _other )

How to query field exist some document in firebase

I using firebase, nodejs and i have a question how to query field exist some document.
Example :
Collections : users => document : A with field {
....
is_correct: true
}
document : B with field {
.....
}
In my above example , i have two document in collection users. On document A i have field is_correct: true and on document B field is_correct not exist.
My collection users about 15.000 document and it have 50 document contain field is_correct: true
When i write code look like :
await firestore.collection('users').where('is_correct', '==', true).get();
it can get correct me 50 document. But i don't understand it can using index on field is_correct or not ? And it can query best performance ? I understand firebase can't get document if field undefined. It impart in case ? Please help ? Thanks you
For a simple query like
firestore.collection('users').where('is_correct', '==', true)
you don't need to configure any index, Firestore does it automatically.
As you mentioned, only documents where the given field exists can match the query.
And this is the case also for Not-equal (!=) and not-in queries: they exclude documents where the given field does not exist, as explained in the documentation.
Also, note that a field exists when it's set to any value, including an empty string (""), null, and NaN (not a number).
So, in conclusion, if you want to query for documents where is_correct is not true, you need to create this field in these documents with a value different than true.

How to obtain nested fields within JSON

Background:
I wish to update a nested field within my JSON document. I want to query for all of the "state" that equal "new"
{
"id": "123"
"feedback" : {
"Features" : [
{
"state":"new"
}
]
}
This is what I have tried to do:
Since this is a nested document. My query looks like this:
SELECT * FROM c WHERE c.feedback.Features.state = "new"
However, I keep ending up with zero results when I know that this exists within the database. What am I doing wrong? Maybe I am getting 0 results because the Features is an array?
Any help is appreciated
For arrays, you'll need to use ARRAY_CONTAINS(). For example, in your case:
SELECT *
FROM c
WHERE ARRAY_CONTAINS(c.feedback.Features,{'state': 'new'}, true)
The 3rd parameter specifies that you're searching within documents within the array, not scalar values.

OrientDB: containsall operator

I have collection of documents. Document have a field which value is an array of maps (for example: map with one field name). Structure is like that:
{
arrayfield: [
{
name: "value1",
},
{
name: "value2",
}
]
}
I want to fetch documents whose arrayfieds all maps contain values from specified array. Documentation says that I can use containsall operator. I use it in this way:
select from SomeCollection where arrayfiled containsall (name in ['value1','value2'])
But this construction always returns empty result. Where I do mistake? Thanks.
PS: If my question not understandable, I can post more detailed example of the collection and and a result which I want to receive.
Found a solution to solve my issue without containsAll:
select from SomeCollection where not (arrayfield contains (fname not in ["value1", "value2"]))
Try the following query
select from SomeCollection where arrayfiled.name contains "value1" and arrayfiled.name contains "value2"

How do I keep existing data in couchbase and only update the new data without overwriting

So, say I have created some records/documents under a bucket and the user updates only one column out of 10 in the RDBMS, so I am trying to send only that one columns data and update it in couchbase. But the problem is that couchbase is overwriting the entire record and putting NULL`s for the rest of the columns.
One approach is to copy all the data from the exisiting record after fetching it from Cbase, and then overwriting the new column while copying the data from the old one. But that doesn`t look like a optimal approach
Any suggestions?
You can use N1QL update Statments google for Couchbase N1QL
UPDATE replaces a document that already exists with updated values.
update:
UPDATE keyspace-ref [use-keys-clause] [set-clause] [unset-clause] [where-clause] [limit-clause] [returning-clause]
set-clause:
SET path = expression [update-for] [ , path = expression [update-for] ]*
update-for:
FOR variable (IN | WITHIN) path (, variable (IN | WITHIN) path)* [WHEN condition ] END
unset-clause:
UNSET path [update-for] (, path [ update-for ])*
keyspace-ref: Specifies the keyspace for which to update the document.
You can add an optional namespace-name to the keyspace-name in this way:
namespace-name:keyspace-name.
use-keys-clause:Specifies the keys of the data items to be updated. Optional. Keys can be any expression.
set-clause:Specifies the value for an attribute to be changed.
unset-clause: Removes the specified attribute from the document.
update-for: The update for clause uses the FOR statement to iterate over a nested array and SET or UNSET the given attribute for every matching element in the array.
where-clause:Specifies the condition that needs to be met for data to be updated. Optional.
limit-clause:Specifies the greatest number of objects that can be updated. This clause must have a non-negative integer as its upper bound. Optional.
returning-clause:Returns the data you updated as specified in the result_expression.
RBAC Privileges
User executing the UPDATE statement must have the Query Update privilege on the target keyspace. If the statement has any clauses that needs data read, such as SELECT clause, or RETURNING clause, then Query Select privilege is also required on the keyspaces referred in the respective clauses. For more details about user roles, see Authorization.
For example,
To execute the following statement, user must have the Query Update privilege on travel-sample.
UPDATE `travel-sample` SET foo = 5
To execute the following statement, user must have the Query Update privilege on the travel-sample and Query Select privilege on beer-sample.
UPDATE `travel-sample`
SET foo = 9
WHERE city = (SELECT raw city FROM `beer-sample` WHERE type = "brewery"
To execute the following statement, user must have the Query Update privilege on `travel-sample` and Query Select privilege on `travel-sample`.
UPDATE `travel-sample`
SET city = “San Francisco”
WHERE lower(city) = "sanfrancisco"
RETURNING *
Example
The following statement changes the "type" of the product, "odwalla-juice1" to "product-juice".
UPDATE product USE KEYS "odwalla-juice1" SET type = "product-juice" RETURNING product.type
"results": [
{
"type": "product-juice"
}
]
This statement removes the "type" attribute from the "product" keyspace for the document with the "odwalla-juice1" key.
UPDATE product USE KEYS "odwalla-juice1" UNSET type RETURNING product.*
"results": [
{
"productId": "odwalla-juice1",
"unitPrice": 5.4
}
]
This statement unsets the "gender" attribute in the "children" array for the document with the key, "dave" in the tutorial keyspace.
UPDATE tutorial t USE KEYS "dave" UNSET c.gender FOR c IN children END RETURNING t
"results": [
{
"t": {
"age": 46,
"children": [
{
"age": 17,
"fname": "Aiden"
},
{
"age": 2,
"fname": "Bill"
}
],
"email": "dave#gmail.com",
"fname": "Dave",
"hobbies": [
"golf",
"surfing"
],
"lname": "Smith",
"relation": "friend",
"title": "Mr.",
"type": "contact"
}
}
]
Starting version 4.5.1, the UPDATE statement has been improved to SET nested array elements. The FOR clause is enhanced to evaluate functions and expressions, and the new syntax supports multiple nested FOR expressions to access and update fields in nested arrays. Additional array levels are supported by chaining the FOR clauses.
Example
UPDATE default
SET i.subitems = ( ARRAY OBJECT_ADD(s, 'new', 'new_value' )
FOR s IN i.subitems END )
FOR s IN ARRAY_FLATTEN(ARRAY i.subitems
FOR i IN items END, 1) END;
If you're using structured (json) data, you need to read the existing record then update the field you want in your program's data structure and then send the record up again. You can't update individual fields in the json structure without sending it all up again. There isn't a way around this that I'm aware of.
It is indeed true, to update individual items in a JSON doc, you need to fetch the entire document and overwrite it.
We are working on adding individual item updates in the near future.

Resources