Cordova Slack Digest

Mon, 07 Sep 2020 08:24:58 GMT

User count: 4101

Join the conversation at slack.cordova.io

Channel #general (10 messages)


Sun, 06 Sep 2020 22:09:28 GMT

@osaintilien55 says

Hello there I have a question that is a bit involved. Just looking for counsel on the matter. I have the whole issue posted on stack overflow but no one seems to be biting. https://stackoverflow.com/questions/63765248/how-can-i-improve-my-search-function-logic-using-lunr-js

Sun, 06 Sep 2020 22:11:06 GMT

@osaintilien55 says

Basically I am getting some long search time results and I think it may be because of how I am doing it. I don't think lunr.js is the issue. This is a cordova project.

Sun, 06 Sep 2020 22:12:17 GMT

@osaintilien55 says

//Clears results-wrapper Html element
document.querySelector(".results-wrapper").innerHTML = "";

//Store query in localDB
searchQuery = document.querySelector("#search-id").value;
localStorage.setItem("searchQuery", searchQuery);

//Returns from the index only the books which contains the query
var results = idx.search(searchQuery);

//Run through "results" and return all the text where the query is found
results.forEach(function (entry) {

//documents contains the database of all the books from my json file
documents.find(findSearchQuery);

//Searches only the text of the doc/books found in results variable 
function findSearchQuery(doc) {

  //searchQuery is the users input
  let re = new RegExp(searchQuery, "i");
  
  //if the book's name matches reference in "results"
  if (doc.name == entry.ref) {
    //And if the searchQuery is found in Books text
    if (doc.text.match(re)) {
      
      //Break up the block of text into sentences
      var sentences = doc.text.match(/[^\.!\?]+[\.!\?]+/g);

      sentences.forEach(function (sentence) {
        //Find the sentence inside the sentences array and return the one with the searchQuery
        //Populate HTML element "results-wrapper" with the results
        if (sentence.match(re)) {
          var anchor = document.createElement("a");
          anchor.className = "anchorSearchResult";
          anchor.href = doc.href;

          //Create "div" element
          var div = document.createElement("div");
          div.className = "div-test";

          //Creates "h4" element for title
          var h4 = document.createElement("h4");
          var title = document.createTextNode(doc.name);
          h4.className = "title-results";

          //Creates "p" element for sentence
          var textElement = document.createElement(p);
          var searchResult = document.createTextNode(sentence);
          textElement.className = "text-results";

          //Creates "p" element for page
          var p = document.createElement("p");
          var pageResult = document.createTextNode(doc.page);
          p.className = "page-results";

          h4.appendChild(title);
          textElement.appendChild(searchResult);
          p.appendChild(pageResult);

          div.appendChild(h4);
          div.appendChild(textElement);
          div.appendChild(p);

          anchor.appendChild(div);

          document.querySelector(".results-wrapper").appendChild(anchor);

          anchor.addEventListener("click", returnSearchResultId);

          function returnSearchResultId(e) {
            //store selectorId value of document
            localStorage.setItem("selectorId", doc.selectorId);
          }

          // Highlight Function
          var instance = new Mark(
            document.querySelector(".results-wrapper")
          );

          instance.mark(searchQuery, {
            element: "span",
            className: "highlight",
          });
        }
      });
    }
  }
}
});
}```


Sun, 06 Sep 2020 22:14:14 GMT

@osaintilien55 says

And here is just a snippet of my json file that is loaded in my “documents” variable

  {
    "name": "Pre-Eleventh-Hour Extra",
    "year": "1941",
    "text": "Pre-\"Eleventh Hour\" Extra MYSTERY OF MYSTERIES EXPOSED!",
    "page": "1TR 2",
    "href": "tracks/tr1.html#page-2.subHeading",
    "selectorId": "#page-2\\.subHeading"
  },
  {
    "name": "Pre-Eleventh-Hour Extra",
    "year": "1941",
    "text": "In the interest of reaching every truth-seeking mind that desires to escape the path that leads to destruction of both body and soul, this tract will be distributed free of charge as long as this issue lasts.",
    "page": "1TR 2",
    "href": "tracks/tr1.html#page-2.1",
    "selectorId": "#page-2\\.1"
  },
  {
    "name": "Pre-Eleventh-Hour Extra",
    "year": "1941",
    "text": "PREFACE PERSONALLY WATCHING FOR EVERY RAY OF LIGHT.",
    "page": "1TR 3",
    "href": "tracks/tr1.html#page-3.preface",
    "selectorId": "#page-3\\.preface"
  },
  {
    "name": "Pre-Eleventh-Hour Extra",
    "year": "1941",
    "text": "One who entrusts to another the investigation of a message from the Lord, is making flesh his arm, and thus is foolishly acting as without a mind of his own. And  "the mind that depends upon the judgment of others is certain, sooner or later, to be misled. " -- Education, p. 231.",
    "page": "1TR 3",
    "href": "tracks/tr1.html#page-3.1",
    "selectorId": "#page-3\\.1"
  },
  {
    "name": "Pre-Eleventh-Hour Extra",
    "year": "1941",
    "text": "Similarly, one who allows prejudice to bar him from a candid investigation of anything new, coming in the name of the Lord, is unwittingly an infidel.",
    "page": "1TR 3",
    "href": "tracks/tr1.html#page-3.2",
    "selectorId": "#page-3\\.2"
  },
  {
    "name": "Pre-Eleventh-Hour Extra",
    "year": "1941",
    "text": "Likewise he who is satisfied with his present attainments in the Word of God, says in effect: \"I am rich, and increased with goods, and have need of nothing.",
    "page": "1TR 3",
    "href": "tracks/tr1.html#page-3.3",
    "selectorId": "#page-3\\.3"
  },
  {
    "name": "Pre-Eleventh-Hour Extra",
    "year": "1941",
    "text": "All these, in variously acting out the part which provoked the condemnation written against the Laodiceans, thereby fulfilling the prophecy which they ought not fulfill, are preparing themselves to be spued out (Rev. 3:14-18). And if they continue in their self-satisfied attitude that they have all the truth, and so have need of nothing more, they will spurn every new claimant to truth and toss the message into the discard because it comes through an unexpected channel. Certainly, then, were this tract not the unfolding of prophecy, the fact is inevitable that when the unfoldment did come, they would treat it in like manner, and consequently toss away their salvation!",
    "page": "1TR 3",
    "href": "tracks/tr1.html#page-3.4",
    "selectorId": "#page-3\\.4"
  },
  {
    "name": "Pre-Eleventh-Hour Extra",
    "year": "1941",
    "text": "Throughout the ages, all who have put their trust in the so-called wise men, and foremost Christians of the day, all reputedly godly men, have by these very ones been bereft of the crown of eternal life, as were the Jewish laity in the days of Christ because of their failing to assume full responsibility for their own salvation. Presumptuously trusting in the wisdom of their so-called \"great men,\" they declined to believe in Christ's words \"O Father, Lord of heaven and earth,...Thou hast hid these things from the wise and prudent, and hast revealed them unto babes.\" Matt. 11:25 \"Where is the wise? where is the scribe?...hath not God made foolish the wisdom of this world?\" 1 Cor 1:20.",
    "page": "1TR 4",
    "href": "tracks/tr1.html#page-4.1",
    "selectorId": "#page-4\\.1"
  }
]```


Sun, 06 Sep 2020 22:18:39 GMT

@norman137 says

Probably best to use the google web inspector performance audit tools to determine exactly where the performance bottleneck is slow.

You can start recording, trigger the search action. Stop recording, and you'll get a information like which functions are being called and how much time have been spent in that function alone, and how much time have been spent inside that function including sub function calls, etc...

Sun, 06 Sep 2020 22:20:38 GMT

@norman137 says

like so...

Sun, 06 Sep 2020 22:23:23 GMT

@osaintilien55 says

perfect, will try it out

Sun, 06 Sep 2020 22:47:32 GMT

@joel640 says

Does anyone have any sway with apache releases? i’ve been waiting on the cordova-plugin-statusbar plugin to release this PR https://github.com/apache/cordova-plugin-statusbar/commit/13645b9f53a58ad5c0041247087f1f2864ef4c29 for a year due to a breaking change in the camera popup in iOS 13. There hasn’t been a release since June 2019 and 3.0.0-beta hasnt been released to NPM. Any help is greatly appreciated ❤️

Sun, 06 Sep 2020 23:49:53 GMT

@osaintilien55 says

Wow found out what the problem was, it was the highlight function being used in the foreach loop that was killing the search function. Now everything is lightening fast. 🙂

Mon, 07 Sep 2020 08:04:02 GMT

@madigan.kai says

Why cordova camera is slow when taking pictures ? also is there a way to show the camera feed to canvas ?