search.spec.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. const searchService = require('../../src/services/search/services/search');
  2. const BNote = require('../../src/becca/entities/bnote');
  3. const BBranch = require('../../src/becca/entities/bbranch');
  4. const SearchContext = require('../../src/services/search/search_context');
  5. const dateUtils = require('../../src/services/date_utils');
  6. const becca = require('../../src/becca/becca');
  7. const {NoteBuilder, findNoteByTitle, note} = require('./becca_mocking');
  8. describe("Search", () => {
  9. let rootNote;
  10. beforeEach(() => {
  11. becca.reset();
  12. rootNote = new NoteBuilder(new BNote({noteId: 'root', title: 'root', type: 'text'}));
  13. new BBranch({branchId: 'none_root', noteId: 'root', parentNoteId: 'none', notePosition: 10});
  14. });
  15. it("simple path match", () => {
  16. rootNote
  17. .child(note("Europe")
  18. .child(note("Austria"))
  19. );
  20. const searchContext = new SearchContext();
  21. const searchResults = searchService.findResultsWithQuery('europe austria', searchContext);
  22. expect(searchResults.length).toEqual(1);
  23. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  24. });
  25. it("normal search looks also at attributes", () => {
  26. const austria = note("Austria");
  27. const vienna = note("Vienna");
  28. rootNote
  29. .child(austria
  30. .relation('capital', vienna))
  31. .child(vienna
  32. .label('inhabitants', '1888776'));
  33. const searchContext = new SearchContext();
  34. let searchResults = searchService.findResultsWithQuery('capital', searchContext);
  35. expect(searchResults.length).toEqual(1);
  36. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  37. searchResults = searchService.findResultsWithQuery('inhabitants', searchContext);
  38. expect(searchResults.length).toEqual(1);
  39. expect(findNoteByTitle(searchResults, "Vienna")).toBeTruthy();
  40. });
  41. it("normal search looks also at type and mime", () => {
  42. rootNote
  43. .child(note("Effective Java", {type: 'book', mime:''}))
  44. .child(note("Hello World.java", {type: 'code', mime: 'text/x-java'}));
  45. const searchContext = new SearchContext();
  46. let searchResults = searchService.findResultsWithQuery('book', searchContext);
  47. expect(searchResults.length).toEqual(1);
  48. expect(findNoteByTitle(searchResults, "Effective Java")).toBeTruthy();
  49. searchResults = searchService.findResultsWithQuery('text', searchContext); // should match mime
  50. expect(searchResults.length).toEqual(1);
  51. expect(findNoteByTitle(searchResults, "Hello World.java")).toBeTruthy();
  52. searchResults = searchService.findResultsWithQuery('java', searchContext);
  53. expect(searchResults.length).toEqual(2);
  54. });
  55. it("only end leafs are results", () => {
  56. rootNote
  57. .child(note("Europe")
  58. .child(note("Austria"))
  59. );
  60. const searchContext = new SearchContext();
  61. const searchResults = searchService.findResultsWithQuery('europe', searchContext);
  62. expect(searchResults.length).toEqual(1);
  63. expect(findNoteByTitle(searchResults, "Europe")).toBeTruthy();
  64. });
  65. it("only end leafs are results", () => {
  66. rootNote
  67. .child(note("Europe")
  68. .child(note("Austria")
  69. .label('capital', 'Vienna'))
  70. );
  71. const searchContext = new SearchContext();
  72. const searchResults = searchService.findResultsWithQuery('Vienna', searchContext);
  73. expect(searchResults.length).toEqual(1);
  74. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  75. });
  76. it("label comparison with short syntax", () => {
  77. rootNote
  78. .child(note("Europe")
  79. .child(note("Austria")
  80. .label('capital', 'Vienna'))
  81. .child(note("Czech Republic")
  82. .label('capital', 'Prague'))
  83. );
  84. const searchContext = new SearchContext();
  85. let searchResults = searchService.findResultsWithQuery('#capital=Vienna', searchContext);
  86. expect(searchResults.length).toEqual(1);
  87. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  88. // case sensitivity:
  89. searchResults = searchService.findResultsWithQuery('#CAPITAL=VIENNA', searchContext);
  90. expect(searchResults.length).toEqual(1);
  91. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  92. searchResults = searchService.findResultsWithQuery('#caPItal=vienNa', searchContext);
  93. expect(searchResults.length).toEqual(1);
  94. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  95. });
  96. it("label comparison with full syntax", () => {
  97. rootNote
  98. .child(note("Europe")
  99. .child(note("Austria")
  100. .label('capital', 'Vienna'))
  101. .child(note("Czech Republic")
  102. .label('capital', 'Prague'))
  103. );
  104. const searchContext = new SearchContext();
  105. let searchResults = searchService.findResultsWithQuery('# note.labels.capital=Prague', searchContext);
  106. expect(searchResults.length).toEqual(1);
  107. expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  108. });
  109. it("numeric label comparison", () => {
  110. rootNote
  111. .child(note("Europe")
  112. .label('country', '', true)
  113. .child(note("Austria")
  114. .label('population', '8859000'))
  115. .child(note("Czech Republic")
  116. .label('population', '10650000'))
  117. );
  118. const searchContext = new SearchContext();
  119. const searchResults = searchService.findResultsWithQuery('#country #population >= 10000000', searchContext);
  120. expect(searchResults.length).toEqual(1);
  121. expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  122. });
  123. it("inherited label comparison", () => {
  124. rootNote
  125. .child(note("Europe")
  126. .label('country', '', true)
  127. .child(note("Austria"))
  128. .child(note("Czech Republic"))
  129. );
  130. const searchContext = new SearchContext();
  131. const searchResults = searchService.findResultsWithQuery('austria #country', searchContext);
  132. expect(searchResults.length).toEqual(1);
  133. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  134. });
  135. it("numeric label comparison fallback to string comparison", () => {
  136. // dates should not be coerced into numbers which would then give wrong numbers
  137. rootNote
  138. .child(note("Europe")
  139. .label('country', '', true)
  140. .child(note("Austria")
  141. .label('established', '1955-07-27'))
  142. .child(note("Czech Republic")
  143. .label('established', '1993-01-01'))
  144. .child(note("Hungary")
  145. .label('established', '1920-06-04'))
  146. );
  147. const searchContext = new SearchContext();
  148. let searchResults = searchService.findResultsWithQuery('#established <= "1955-01-01"', searchContext);
  149. expect(searchResults.length).toEqual(1);
  150. expect(findNoteByTitle(searchResults, "Hungary")).toBeTruthy();
  151. searchResults = searchService.findResultsWithQuery('#established > "1955-01-01"', searchContext);
  152. expect(searchResults.length).toEqual(2);
  153. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  154. expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  155. });
  156. it("smart date comparisons", () => {
  157. // dates should not be coerced into numbers which would then give wrong numbers
  158. rootNote
  159. .child(note("My note", {dateCreated: dateUtils.localNowDateTime()})
  160. .label('year', new Date().getFullYear().toString())
  161. .label('month', dateUtils.localNowDate().substr(0, 7))
  162. .label('date', dateUtils.localNowDate())
  163. .label('dateTime', dateUtils.localNowDateTime())
  164. );
  165. const searchContext = new SearchContext();
  166. function test(query, expectedResultCount) {
  167. const searchResults = searchService.findResultsWithQuery(query, searchContext);
  168. expect(searchResults.length).toEqual(expectedResultCount);
  169. if (expectedResultCount === 1) {
  170. expect(findNoteByTitle(searchResults, "My note")).toBeTruthy();
  171. }
  172. }
  173. test("#year = YEAR", 1);
  174. test("#year = 'YEAR'", 0);
  175. test("#year >= YEAR", 1);
  176. test("#year <= YEAR", 1);
  177. test("#year < YEAR+1", 1);
  178. test("#year < YEAR + 1", 1);
  179. test("#year < year + 1", 1);
  180. test("#year > YEAR+1", 0);
  181. test("#month = MONTH", 1);
  182. test("#month = month", 1);
  183. test("#month = 'MONTH'", 0);
  184. test("note.dateCreated =* month", 2);
  185. test("#date = TODAY", 1);
  186. test("#date = today", 1);
  187. test("#date = 'today'", 0);
  188. test("#date > TODAY", 0);
  189. test("#date > TODAY-1", 1);
  190. test("#date > TODAY - 1", 1);
  191. test("#date < TODAY+1", 1);
  192. test("#date < TODAY + 1", 1);
  193. test("#date < 'TODAY + 1'", 1);
  194. test("#dateTime <= NOW+10", 1);
  195. test("#dateTime <= NOW + 10", 1);
  196. test("#dateTime < NOW-10", 0);
  197. test("#dateTime >= NOW-10", 1);
  198. test("#dateTime < NOW-10", 0);
  199. });
  200. it("logical or", () => {
  201. rootNote
  202. .child(note("Europe")
  203. .label('country', '', true)
  204. .child(note("Austria")
  205. .label('languageFamily', 'germanic'))
  206. .child(note("Czech Republic")
  207. .label('languageFamily', 'slavic'))
  208. .child(note("Hungary")
  209. .label('languageFamily', 'finnougric'))
  210. );
  211. const searchContext = new SearchContext();
  212. const searchResults = searchService.findResultsWithQuery('#languageFamily = slavic OR #languageFamily = germanic', searchContext);
  213. expect(searchResults.length).toEqual(2);
  214. expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  215. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  216. });
  217. it("fuzzy attribute search", () => {
  218. rootNote
  219. .child(note("Europe")
  220. .label('country', '', true)
  221. .child(note("Austria")
  222. .label('languageFamily', 'germanic'))
  223. .child(note("Czech Republic")
  224. .label('languageFamily', 'slavic')));
  225. let searchContext = new SearchContext({fuzzyAttributeSearch: false});
  226. let searchResults = searchService.findResultsWithQuery('#language', searchContext);
  227. expect(searchResults.length).toEqual(0);
  228. searchResults = searchService.findResultsWithQuery('#languageFamily=ger', searchContext);
  229. expect(searchResults.length).toEqual(0);
  230. searchContext = new SearchContext({fuzzyAttributeSearch: true});
  231. searchResults = searchService.findResultsWithQuery('#language', searchContext);
  232. expect(searchResults.length).toEqual(2);
  233. searchResults = searchService.findResultsWithQuery('#languageFamily=ger', searchContext);
  234. expect(searchResults.length).toEqual(1);
  235. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  236. });
  237. it("filter by note property", () => {
  238. rootNote
  239. .child(note("Europe")
  240. .child(note("Austria"))
  241. .child(note("Czech Republic")));
  242. const searchContext = new SearchContext();
  243. const searchResults = searchService.findResultsWithQuery('# note.title =* czech', searchContext);
  244. expect(searchResults.length).toEqual(1);
  245. expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  246. });
  247. it("filter by note's parent", () => {
  248. rootNote
  249. .child(note("Europe")
  250. .child(note("Austria"))
  251. .child(note("Czech Republic")
  252. .child(note("Prague")))
  253. )
  254. .child(note("Asia")
  255. .child(note('Taiwan')));
  256. const searchContext = new SearchContext();
  257. let searchResults = searchService.findResultsWithQuery('# note.parents.title = Europe', searchContext);
  258. expect(searchResults.length).toEqual(2);
  259. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  260. expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  261. searchResults = searchService.findResultsWithQuery('# note.parents.title = Asia', searchContext);
  262. expect(searchResults.length).toEqual(1);
  263. expect(findNoteByTitle(searchResults, "Taiwan")).toBeTruthy();
  264. searchResults = searchService.findResultsWithQuery('# note.parents.parents.title = Europe', searchContext);
  265. expect(searchResults.length).toEqual(1);
  266. expect(findNoteByTitle(searchResults, "Prague")).toBeTruthy();
  267. });
  268. it("filter by note's ancestor", () => {
  269. rootNote
  270. .child(note("Europe")
  271. .child(note("Austria"))
  272. .child(note("Czech Republic")
  273. .child(note("Prague").label('city')))
  274. )
  275. .child(note("Asia")
  276. .child(note('Taiwan')
  277. .child(note('Taipei').label('city')))
  278. );
  279. const searchContext = new SearchContext();
  280. let searchResults = searchService.findResultsWithQuery('#city AND note.ancestors.title = Europe', searchContext);
  281. expect(searchResults.length).toEqual(1);
  282. expect(findNoteByTitle(searchResults, "Prague")).toBeTruthy();
  283. searchResults = searchService.findResultsWithQuery('#city AND note.ancestors.title = Asia', searchContext);
  284. expect(searchResults.length).toEqual(1);
  285. expect(findNoteByTitle(searchResults, "Taipei")).toBeTruthy();
  286. });
  287. it("filter by note's child", () => {
  288. rootNote
  289. .child(note("Europe")
  290. .child(note("Austria")
  291. .child(note("Vienna")))
  292. .child(note("Czech Republic")
  293. .child(note("Prague"))))
  294. .child(note("Oceania")
  295. .child(note('Australia')));
  296. const searchContext = new SearchContext();
  297. let searchResults = searchService.findResultsWithQuery('# note.children.title =* Aust', searchContext);
  298. expect(searchResults.length).toEqual(2);
  299. expect(findNoteByTitle(searchResults, "Europe")).toBeTruthy();
  300. expect(findNoteByTitle(searchResults, "Oceania")).toBeTruthy();
  301. searchResults = searchService.findResultsWithQuery('# note.children.title =* Aust AND note.children.title *= republic', searchContext);
  302. expect(searchResults.length).toEqual(1);
  303. expect(findNoteByTitle(searchResults, "Europe")).toBeTruthy();
  304. searchResults = searchService.findResultsWithQuery('# note.children.children.title = Prague', searchContext);
  305. expect(searchResults.length).toEqual(1);
  306. expect(findNoteByTitle(searchResults, "Europe")).toBeTruthy();
  307. });
  308. it("filter by relation's note properties using short syntax", () => {
  309. const austria = note("Austria");
  310. const portugal = note("Portugal");
  311. rootNote
  312. .child(note("Europe")
  313. .child(austria)
  314. .child(note("Czech Republic")
  315. .relation('neighbor', austria.note))
  316. .child(portugal)
  317. .child(note("Spain")
  318. .relation('neighbor', portugal.note))
  319. );
  320. const searchContext = new SearchContext();
  321. let searchResults = searchService.findResultsWithQuery('# ~neighbor.title = Austria', searchContext);
  322. expect(searchResults.length).toEqual(1);
  323. expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  324. searchResults = searchService.findResultsWithQuery('# ~neighbor.title = Portugal', searchContext);
  325. expect(searchResults.length).toEqual(1);
  326. expect(findNoteByTitle(searchResults, "Spain")).toBeTruthy();
  327. });
  328. it("filter by relation's note properties using long syntax", () => {
  329. const austria = note("Austria");
  330. const portugal = note("Portugal");
  331. rootNote
  332. .child(note("Europe")
  333. .child(austria)
  334. .child(note("Czech Republic")
  335. .relation('neighbor', austria.note))
  336. .child(portugal)
  337. .child(note("Spain")
  338. .relation('neighbor', portugal.note))
  339. );
  340. const searchContext = new SearchContext();
  341. const searchResults = searchService.findResultsWithQuery('# note.relations.neighbor.title = Austria', searchContext);
  342. expect(searchResults.length).toEqual(1);
  343. expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  344. });
  345. it("filter by multiple level relation", () => {
  346. const austria = note("Austria");
  347. const slovakia = note("Slovakia");
  348. const italy = note("Italy");
  349. const ukraine = note("Ukraine");
  350. rootNote
  351. .child(note("Europe")
  352. .child(austria
  353. .relation('neighbor', italy.note)
  354. .relation('neighbor', slovakia.note))
  355. .child(note("Czech Republic")
  356. .relation('neighbor', austria.note)
  357. .relation('neighbor', slovakia.note))
  358. .child(slovakia
  359. .relation('neighbor', ukraine.note))
  360. .child(ukraine)
  361. );
  362. const searchContext = new SearchContext();
  363. let searchResults = searchService.findResultsWithQuery('# note.relations.neighbor.relations.neighbor.title = Italy', searchContext);
  364. expect(searchResults.length).toEqual(1);
  365. expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  366. searchResults = searchService.findResultsWithQuery('# note.relations.neighbor.relations.neighbor.title = Ukraine', searchContext);
  367. expect(searchResults.length).toEqual(2);
  368. expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  369. expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  370. });
  371. it("test note properties", () => {
  372. const austria = note("Austria");
  373. austria.relation('myself', austria.note);
  374. austria.label('capital', 'Vienna');
  375. austria.label('population', '8859000');
  376. rootNote
  377. .child(note("Asia"))
  378. .child(note("Europe")
  379. .child(austria
  380. .child(note("Vienna"))
  381. .child(note("Sebastian Kurz"))
  382. )
  383. )
  384. .child(note("Mozart")
  385. .child(austria));
  386. austria.note.isProtected = false;
  387. austria.note.dateCreated = '2020-05-14 12:11:42.001+0200';
  388. austria.note.dateModified = '2020-05-14 13:11:42.001+0200';
  389. austria.note.utcDateCreated = '2020-05-14 10:11:42.001Z';
  390. austria.note.utcDateModified = '2020-05-14 11:11:42.001Z';
  391. austria.note.contentLength = 1001;
  392. const searchContext = new SearchContext();
  393. function test(propertyName, value, expectedResultCount) {
  394. const searchResults = searchService.findResultsWithQuery(`# note.${propertyName} = ${value}`, searchContext);
  395. expect(searchResults.length).toEqual(expectedResultCount);
  396. }
  397. test("type", "text", 7);
  398. test("TYPE", "TEXT", 7);
  399. test("type", "code", 0);
  400. test("mime", "text/html", 6);
  401. test("mime", "application/json", 0);
  402. test("isProtected", "false", 7);
  403. test("isProtected", "FALSE", 7);
  404. test("isProtected", "true", 0);
  405. test("isProtected", "TRUE", 0);
  406. test("dateCreated", "'2020-05-14 12:11:42.001+0200'", 1);
  407. test("dateCreated", "wrong", 0);
  408. test("dateModified", "'2020-05-14 13:11:42.001+0200'", 1);
  409. test("dateModified", "wrong", 0);
  410. test("utcDateCreated", "'2020-05-14 10:11:42.001Z'", 1);
  411. test("utcDateCreated", "wrong", 0);
  412. test("utcDateModified", "'2020-05-14 11:11:42.001Z'", 1);
  413. test("utcDateModified", "wrong", 0);
  414. test("parentCount", "2", 1);
  415. test("parentCount", "3", 0);
  416. test("childrenCount", "2", 1);
  417. test("childrenCount", "10", 0);
  418. test("attributeCount", "3", 1);
  419. test("attributeCount", "4", 0);
  420. test("labelCount", "2", 1);
  421. test("labelCount", "3", 0);
  422. test("relationCount", "1", 1);
  423. test("relationCount", "2", 0);
  424. });
  425. it("test order by", () => {
  426. const italy = note("Italy").label("capital", "Rome");
  427. const slovakia = note("Slovakia").label("capital", "Bratislava");
  428. const austria = note("Austria").label("capital", "Vienna");
  429. const ukraine = note("Ukraine").label("capital", "Kiev");
  430. rootNote
  431. .child(note("Europe")
  432. .child(ukraine)
  433. .child(slovakia)
  434. .child(austria)
  435. .child(italy));
  436. const searchContext = new SearchContext();
  437. let searchResults = searchService.findResultsWithQuery('# note.parents.title = Europe orderBy note.title', searchContext);
  438. expect(searchResults.length).toEqual(4);
  439. expect(becca.notes[searchResults[0].noteId].title).toEqual("Austria");
  440. expect(becca.notes[searchResults[1].noteId].title).toEqual("Italy");
  441. expect(becca.notes[searchResults[2].noteId].title).toEqual("Slovakia");
  442. expect(becca.notes[searchResults[3].noteId].title).toEqual("Ukraine");
  443. searchResults = searchService.findResultsWithQuery('# note.parents.title = Europe orderBy note.labels.capital', searchContext);
  444. expect(searchResults.length).toEqual(4);
  445. expect(becca.notes[searchResults[0].noteId].title).toEqual("Slovakia");
  446. expect(becca.notes[searchResults[1].noteId].title).toEqual("Ukraine");
  447. expect(becca.notes[searchResults[2].noteId].title).toEqual("Italy");
  448. expect(becca.notes[searchResults[3].noteId].title).toEqual("Austria");
  449. searchResults = searchService.findResultsWithQuery('# note.parents.title = Europe orderBy note.labels.capital DESC', searchContext);
  450. expect(searchResults.length).toEqual(4);
  451. expect(becca.notes[searchResults[0].noteId].title).toEqual("Austria");
  452. expect(becca.notes[searchResults[1].noteId].title).toEqual("Italy");
  453. expect(becca.notes[searchResults[2].noteId].title).toEqual("Ukraine");
  454. expect(becca.notes[searchResults[3].noteId].title).toEqual("Slovakia");
  455. searchResults = searchService.findResultsWithQuery('# note.parents.title = Europe orderBy note.labels.capital DESC limit 2', searchContext);
  456. expect(searchResults.length).toEqual(2);
  457. expect(becca.notes[searchResults[0].noteId].title).toEqual("Austria");
  458. expect(becca.notes[searchResults[1].noteId].title).toEqual("Italy");
  459. searchResults = searchService.findResultsWithQuery('# note.parents.title = Europe orderBy #capital DESC limit 1', searchContext);
  460. expect(searchResults.length).toEqual(1);
  461. searchResults = searchService.findResultsWithQuery('# note.parents.title = Europe orderBy #capital DESC limit 1000', searchContext);
  462. expect(searchResults.length).toEqual(4);
  463. });
  464. it("test not(...)", () => {
  465. const italy = note("Italy").label("capital", "Rome");
  466. const slovakia = note("Slovakia").label("capital", "Bratislava");
  467. rootNote
  468. .child(note("Europe")
  469. .child(slovakia)
  470. .child(italy));
  471. const searchContext = new SearchContext();
  472. let searchResults = searchService.findResultsWithQuery('# not(#capital) and note.noteId != root', searchContext);
  473. expect(searchResults.length).toEqual(1);
  474. expect(becca.notes[searchResults[0].noteId].title).toEqual("Europe");
  475. searchResults = searchService.findResultsWithQuery('#!capital and note.noteId != root', searchContext);
  476. expect(searchResults.length).toEqual(1);
  477. expect(becca.notes[searchResults[0].noteId].title).toEqual("Europe");
  478. });
  479. it("test note.text *=* something", () => {
  480. const italy = note("Italy").label("capital", "Rome");
  481. const slovakia = note("Slovakia").label("capital", "Bratislava");
  482. rootNote
  483. .child(note("Europe")
  484. .child(slovakia)
  485. .child(italy));
  486. const searchContext = new SearchContext();
  487. let searchResults = searchService.findResultsWithQuery('# note.text *=* vaki and note.noteId != root', searchContext);
  488. expect(searchResults.length).toEqual(1);
  489. expect(becca.notes[searchResults[0].noteId].title).toEqual("Slovakia");
  490. });
  491. it("test that fulltext does not match archived notes", () => {
  492. const italy = note("Italy").label("capital", "Rome");
  493. const slovakia = note("Slovakia").label("capital", "Bratislava");
  494. rootNote
  495. .child(note("Reddit").label('archived', '', true)
  496. .child(note('Post X'))
  497. .child(note('Post Y')))
  498. .child(note ('Reddit is bad'));
  499. const searchContext = new SearchContext({excludeArchived: true});
  500. let searchResults = searchService.findResultsWithQuery('reddit', searchContext);
  501. expect(searchResults.length).toEqual(1);
  502. expect(becca.notes[searchResults[0].noteId].title).toEqual("Reddit is bad");
  503. });
  504. // FIXME: test what happens when we order without any filter criteria
  505. // it("comparison between labels", () => {
  506. // rootNote
  507. // .child(note("Europe")
  508. // .child(note("Austria")
  509. // .label('capital', 'Vienna')
  510. // .label('largestCity', 'Vienna'))
  511. // .child(note("Canada")
  512. // .label('capital', 'Ottawa')
  513. // .label('largestCity', 'Toronto'))
  514. // .child(note("Czech Republic")
  515. // .label('capital', 'Prague')
  516. // .label('largestCity', 'Prague'))
  517. // );
  518. //
  519. // const searchContext = new SearchContext();
  520. //
  521. // const searchResults = searchService.findResultsWithQuery('#capital = #largestCity', searchContext);
  522. // expect(searchResults.length).toEqual(2);
  523. // expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
  524. // expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
  525. // })
  526. });