Complex text index in mongodb - mongodb

I have such property in my document
"Resources" : {
"Data" : [
[
"ru.Title",
"Привет, Мир"
],
[
"ru.ManualExcerpt",
null
],
[
"ru.AutoExcerpt",
"Привет, Мир "
],
[
"ru.Body",
"<p>Привет, Мир</p>\n"
],
[
"en.Title",
"Hello world"
],
[
"en.ManualExcerpt",
null
],
[
"en.AutoExcerpt",
"Hello world "
],
[
"en.Body",
"<p>Hello world</p>\n"
]
]
},
I need to created text index for each of these items. I have tried to do something like this
db.document.ensureIndex(
{
"Resources.Data[0][1]": "text",
"Resources.Data[1][1]": "text",
"Resources.Data[2][1]": "text",
"Resources.Data[3][1]": "text",
"Resources.Data[4][1]": "text",
"Resources.Data[5][1]": "text",
"Resources.Data[6][1]": "text",
"Resources.Data[7][1]": "text"
},
{ name: "text-index" }
But search is still not working. Is it possible to create index in my situation?

Related

Querying Mongo DB nested Documents

I am using complex nested mongo DB document. I have tried to use aggregate with replaceroot but using replaceroot I am able to go for only one sub-level. In my ocument I am having 3 sub levels. I tried to get all document and loop information in python but I ended up using 5nested for loops.
[
{
"_id": "A-38",
"resourcePaths": [
{
"resourcePathName": "some1",
"method": "POST",
"scenarioDetails": [
{
"scenarioId": "4-ABCD",
"scenarioName": "scenaio1",
"propertiesDatatype": {},
"requestData": [
{
"sql": "Select * from tbl",
"insUpdFlag": "Y",
},
{
"digit": "",
"insUpdFlag": "N",
}
],
"updatedBy": "db_insert",
},
{
"scenarioId": "4-QZWBJ3",
"scenarioName": "Scen2",
"requestData": [
{
"sql": "",
"insUpdFlag": "N",
}
],
"updated": "01/31/2023 09:16:41"
}
]
}
],
}
]
I am trying get the scenario details which is having "insUpdFlag" as Y like this
{
"scenarioId": "4-ABCD",
"scenarioName": "scenaio1",
"propertiesDatatype": {},
"requestData": [
{
"sql": "Select * from tbl",
"insUpdFlag": "Y",
},
{
"digit": "",
"insUpdFlag": "N",
}
],
"updatedBy": "db_insert",
}
I tried but giving me entire document. I need some help here. TYIA
db.collection.find({
"resourcePaths.scenarioDetails.requestData.insUpdFlag": "Y"
},

Watson Speech To Text, Word timestamps are not in sync with Audio

I am using speech to text with following params -
timestamps=true&max_alternatives=1&model=en-US_NarrowbandModel&smart_formatting=true',
Headers - 'Content-Type' => 'audio/flac', 'Transfer-Encoding' => 'chunked'
And providing an audio/flac file to process, but returned words time boundary is not in sync with audio.
For eg. Response is -:
take a morning I have 2 questions please %HESITATION first how how much of the ability
Timestamps are like these -
[
[
"take",
1409.48,
1409.62
],
[
"a",
1409.62,
1409.67
],
[
"morning",
1409.67,
1410.03
],
[
"I",
1410.06,
1410.17
],
[
"have",
1410.17,
1410.38
],
[
"two",
1410.41,
1410.58
],
[
"questions",
1410.58,
1411.05
],
[
"please",
1411.05,
1411.42
],
[
"%HESITATION",
1411.42,
1411.65
],
[
"first",
1411.65,
1412.17
],
[
"how",
1412.33,
1412.62
],
[
"how",
1412.65,
1412.77
],
[
"much",
1412.77,
1413
],
[
"of",
1413,
1413.1
],
[
"the",
1413.1,
1413.37
],
[
"ability",
1413.37,
1413.82
]
]
But in actual audio these words are at different times. (few seconds difference)
Any Suggestion ??

Highcharts two datetime xAxis chart with same ticks interval

I two days think about problem, but i don't know make chart with two normalized datetime xAxis.
I Tried use linkedTo and normalize data arrays (but this hard overkill).
linkedTo showing only overlapped data.
Without linkedTo and normalization arrays, ticks showed as async like this
Help me, please
What make chart like this?
$('#container').highcharts({
yAxis: {
gridLineWidth:0
},
xAxis: [
{
gridLineWidth: 1,
type: 'datetime',
lineColor: '#ff9c00'
},
{
type: 'datetime',
opposite: true,
lineColor: '#FF6B6B'
}
],
series: [
{
"name": "first",
"data": [
[
1479164400000,
7323
],
[
1479160800000,
6204
],
[
1479157200000,
3561
],
[
1479153600000,
9706
],
[
1479150000000,
2539
],
[
1479146400000,
4570
],
[
1479142800000,
4187
],
[
1479139200000,
3631
],
[
1479135600000,
7512
],
[
1479132000000,
2456
],
[
1479128400000,
6983
],
[
1479124800000,
3511
],
[
1479121200000,
2765
],
[
1479117600000,
3401
],
[
1479114000000,
2565
],
[
1479110400000,
4425
],
[
1479106800000,
4592
],
[
1479103200000,
4328
],
[
1479099600000,
2694
],
[
1479096000000,
2787
],
[
1479092400000,
11633
],
[
1479088800000,
3311
],
[
1479085200000,
2839
],
[
1479081600000,
12620
]
]
},
{
"name": "second",
"data": [
[
1479250800000,
22730
],
[
1479247200000,
10695
],
[
1479243600000,
12017
],
[
1479240000000,
12110
],
[
1479236400000,
9689
],
[
1479232800000,
4288
],
[
1479229200000,
3702
],
[
1479225600000,
5575
],
[
1479222000000,
5694
],
[
1479218400000,
3098
],
[
1479214800000,
9885
],
[
1479211200000,
6587
],
[
1479207600000,
3028
],
[
1479204000000,
3281
],
[
1479200400000,
12577
],
[
1479196800000,
3886
],
[
1479193200000,
4014
],
[
1479189600000,
6553
],
[
1479186000000,
2041
],
[
1479182400000,
4056
],
[
1479178800000,
4223
],
[
1479175200000,
4920
],
[
1479171600000,
5432
],
[
1479168000000,
7857
],
[
1479164400000,
7323
],
[
1479160800000,
6204
],
[
1479157200000,
3561
],
[
1479153600000,
9706
],
[
1479150000000,
2539
],
[
1479146400000,
4570
],
[
1479142800000,
4187
],
[
1479139200000,
3631
],
[
1479135600000,
7512
],
[
1479132000000,
2456
],
[
1479128400000,
6983
],
[
1479124800000,
3511
],
[
1479121200000,
2765
],
[
1479117600000,
3401
],
[
1479114000000,
2565
],
[
1479110400000,
4425
],
[
1479106800000,
4592
],
[
1479103200000,
4328
],
[
1479099600000,
2694
],
[
1479096000000,
2787
],
[
1479092400000,
11633
],
[
1479088800000,
3311
],
[
1479085200000,
2839
],
[
1479081600000,
12620
]
],
"xAxis": 1,
"dashStyle": "shortdot"
}
]
});
#container {
min-width: 1024px;
max-width: 1024px;
height: 300px;
margin: 1em auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>
My solution is as follows:
Grab the bottom axis ticks values
Map the values to pixels
Map the pixels to top axis values
Set the values to top axis ticks
All the calculation can be done in tickPositioner.
tickPositioner: function() {
var axisTop = this,
axisBottom = this.chart.xAxis[0],
ticksBottom = axisBottom.tickPositions;
var ticksTop = ticksBottom.map(function(tickValue) {
return axisTop.toValue(axisBottom.toPixels(tickValue));
});
return ticksTop;
},
example: https://jsfiddle.net/439adgpa/
After setting tick positions in tick positioner, you have to manually set the correct format or use it from the bottom axis ticks.
labels: {
format: '{value:%H:%M}'
}
or
ticksTop.info = ticksBottom.info;
example: https://jsfiddle.net/439adgpa/1/
Use stacked series over each other. yAxis stacked and numbered as 0,1,2.
Here is an example fiddle
{
name : 'First',
data :data for first,
zIndex : 1,
lineWidth:3,
color:'red',
yAxis: 0 ,
marker : {
enabled : false
}
}, {
name : 'second',
data : data for second,
lineWidth:3,
zIndex : 1,
yAxis: 1 ,
color:'#BE6230',
marker : {
enabled : false
}
}

Is there a better way to write this Postgres JSONB query?

Below is a sample JSONB array. I'm trying to figure out how to write a query that doesn't require a cross product like this.
select b.id from brand b,jsonb_array_elements (b.tree) a where a#>>'{Name}' = 'Skiing';
Bonus points for helping me translate this to SQL Alchemy
[
{
"Name": "Snowboarding",
"Order": 1,
"Categories": {
"Jackets": [
22002,
23224
],
"Helmets": [
24920
],
"Freestyle Boards": [
20164
],
"Goggles": [
23169,
23280
],
"Hats": [
22966,
21727
],
"Bindings": [
19265
],
"Gloves": [
20461
],
"Boots": [
26374,
19079,
21765,
22669
],
"Freeride Boards": [
18395,
25505
],
"Pants": [
24143,
20957
]
}
},
{
"Name": "Skiing",
"Order": 2,
"Categories": {
"Jackets": [
22518,
25791,
19972
],
"Pants": [
17516,
23113
],
"Goggles": [
25066,
20996
],
"Helmets": [
24378
],
"Hats": [
20009,
21245
],
"Cross-country Skiing": [
17464
],
"Gloves": [
25822
],
"Boots": [
16616
],
"Poles": [
19280
]
}
},....]
SQL solution first:
SELECT brand.id
FROM brand
WHERE brand.tree #> '[{"Name": "Skiing"}]'::jsonb;
As for sqlalchemy version, you can simply use contains in order to generate SQL statement above:
q = (session.query(Brand.id)
.filter(Brand.tree.contains([{"Name": "Skiing"}]))
)

Mongodb get element from object

I have a collection on which if I do a find().pretty gives me the following values
{
"_id": ObjectId("55f7a2a9247a911393333681"),
"education": [
"Schooling",
"Plus 2",
"Graduate",
"Post Graduate"
],
"identification": [
],
"jobtype": [
],
"actor": [
]
}
Can I just get the values under "actor" without getting the entire collection and then iterating through the values?
Its simple. You can use the following query,
db.collection.distinct('actor')