Loklak Server is a data-scraping system that indexes all the scraped data for the purpose to optimize it. The data fetched by different users is stored as cache. This helps in retrieving of data directly from cache for recurring queries. When users search for the same queries, load on Loklak Server is reduced by outputting indexed data, thus optimizing the operations.
It is dependent on ElasticSearch for indexing of cached data (as JSON). The data that is fetched by different users is stored as cache. This helps in fetching data directly from cache for same queries. When users search for the same queries, load on Loklak Server is reduced and it is optimized by outputting indexed data instead of scraping the same date again.
When is data indexing done?
The indexing of data is done when:
1) Data is scraped:
When data is scraped, data is indexed concurrently while cleaning of data in TwitterTweet data object. For this task, addScheduler static method of IncomingMessageBuffer is used, which acts as
abstract between scraping of data and storing and indexing of data.
The following is the implementation from TwitterScraper (from here). Here writeToIndex is the boolean input to whether index the data or not.
if (this.writeToIndex) IncomingMessageBuffer.addScheduler(this, this.user, true);
2) Data is fetched from backend:
When data is fetched from backend, it is indexed in Timeline iterator. It calls the above method to index data concurrently.
The following is the definition of writeToIndex() method from Timeline.java (from here). When writeToIndex() is called, the fetched data is indexed.
When addScheduler static method of IncomingMessageBuffer is called, a thread is started that indexes all data. When the messagequeue data structure is filled with some messages, indexing continues.
See here . The DAO method writeMessageBulk is called here to write data. The data is then written to the following streams:
1) Dump: The data fetched is dumped into Import directory in a file. It can also be fetched from other peers.
2) Index: The data fetched is checked if it exists in the index and data that isn’t indexed is indexed.
Whereas for dumping of data writeMessageBulkDump(Dump) is called. It is defined here
- Iterable: https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html
- Use of Iterable: https://stackoverflow.com/questions/1059127/what-is-the-iterable-interface-used-for
- ElasticSearch Webinar: https://www.elastic.co/webinars/getting-started-elasticsearch?elektra=home&storm=sub1
- Ways to iterate through loop: https://crunchify.com/how-to-iterate-through-java-list-4-way-to-iterate-through-loop/