Integrating YaCy Grid Locally with Susper

The YaCy Grid is the second-generation implementation of YaCy, a peer-to-peer search engine.The search results can be improved to a great extent by using YaCy-Grid as the new backend for SUSPER. YaCy Grid is the best choice for distributed search topology. The legacy YaCy is made for decentralised and also distributed network. While both the networks are distributed,the YaCy-Grid is centralized and legacy YaCy is decentralized. YaCy Grid facilitates a lot with scaling that will be in our hand and can be done in all aspects​(loading, parsing, indexing) with computing power we choose. In YaCy,Solr is embedded. But in YaCy Grid,we will get elasticsearch cluster.​They are both built around the core underlying search library Lucene.But ​elasticsearch will help us to scale almost indefinitely. In this blog, I will show you how to integrate YaCy Grid with Susper locally and how to use it to fetch results. Implementing YaCy Grid with Susper: Before using YaCy Grid we need to first setup YaCy Grid and crawl to url using crawl start API, more information about that can be found here Implementing YaCy Grid with Susper and Setting up YaCy Grid locally. So, once we are done with setup and crawling, we need to begin using its APIs in Susper. Following are some easy steps in which we can show results from YaCy Grid in a separate tab is Susper. Step 1: Creating a service to fetch results: In order to fetch results from local YaCy Grid server we need to create a service to fetch results from local YaCy Grid server. Here is the class in grid-service.ts which fetches results for us. export class GridSearchService { server = 'http://127.0.0.1:8100'; searchURL = this.server + '/yacy/grid/mcp/index/yacysearch.json?query='; constructor(private http: Http, private jsonp: Jsonp, private store: Store<fromRoot.State>) { } getSearchResults(searchquery) { return this.http .get(this.searchURL+searchquery).map(res => res.json() ).catch(this.handleError); }   Step 2: Modifying results.component.ts file In order to get results from grid-service.ts in results.component.ts we must need to create an instance of the service and use this instance to get the results and store it in variables results.component.ts file and then use these variables to show results in results template. Following is the code that does this for us ngOnInit() { this.grid.getSearchResults(this.searchdata.query).subscribe(res=>{ this.gridResult=res.channels; }); }   gridClick(){ this.getPresentPage(1); this.resultDisplay = 'grid'; this.totalgridresults=this.gridResult[0].totalResults; this.gridmessage='About ' + this.totalgridresults + ' results'; this.gridItems=this.gridResult[0].items; console.log(this.gridItems); }   Step 3: Creating a New tab to show results from YaCy Grid: Now we need to create a tab in the template where we can use local variables in results.component.ts to show the results following the current design pattern here is the code for that <li [class.active_view]="Display('grid')" (click)="gridClick()">YaCy_Grid</li> <!--YaCy Grid--> <div class="container-fluid"> <div class="result message-bar" *ngIf="totalgridresults > 0 && Display('grid')"> {{gridmessage}} </div> <div class="autocorrect"> <app-auto-correct [hidden]="hideAutoCorrect"></app-auto-correct> </div> </div> <div class="grid-result" *ngIf="Display('grid')"> <div class="feed container"> <div *ngFor="let item of gridItems" class="result"> <div class="title"> <a class="title-pointer" href="{{item.link}}" [style.color]="themeService.titleColor">{{item.title}}</a> </div> <div class="link"> <p [style.color]="themeService.linkColor">{{item.link}}</p> </div> <div class="description"> <p [style.color]="themeService.descriptionColor">{{item.pubDate|date:'MMMM d, yyyy'}} - {{item.description}}</p> </div> </div> </div> </div> <!-- END -->   Step 4: Starting YaCy Grid Locally:…

Continue ReadingIntegrating YaCy Grid Locally with Susper

Configurable Services in Loklak Search

Loklak search being an angular application has a concept of wiring down the code in the special form of classes called Services. These serviced have important characteristics, which make them a powerful feature of angular. Services are shared common object wired together by Dependency Injection. Services are lazily instantiated at the runtime.   The DI and the instantiation part of a service are handled by angular itself so we don’t have to bother about it. The parts of the services we are always concerned about is the logical part of the service. As the services are the sharable code at the time of writing a service we have to be 100% sure that this is the part of the code which we want to share with our components, else this can lead to the bad implementation of architecture which makes application harder to debug. Now, the next question which arises is how services are different from something like redux state? Well, the difference lies in the word itself, services don’t have a persistent state of themselves. They are just a set of methods to separate a common piece of code from all the components into one class. These services have functions which take an input, processes them and spit an output. Services in Loklak Search So in loklak search, the main services are the ones which on request, fetch data from the backend API and return the data to the requester. All the services in loklak search have a fixed well-defined task, i.e. to use the API and get the data. This is how all the services must be designed, with a specific set of goals. A service should never try to do what is not necessary, or in other words, each service should have one and only one aim and it should do it nicely. In loklak search, the services are classified by the API endpoints they hit to retrieve data. These services receive the query to be searched from the requested and they send the AJAX request to correct API endpoint and return the fetched data. This is the common structure of all the Loklak services, they all have a fetchQuery() method which takes a string argument query and requests the API for that query and after completion, it either returns the correct response from the API or throws an error if something goes wrong. @Injectable() class SearchService() { public fetchQuery( query: string ) { … } private extractData( response ) { … } private handleError( error ) { … } } Problems faced in this structure This simple structure was good enough for the application in the basic levels, but as the number of features in the application increase, our simple service becomes less and less flexible as the fetchQuery() method takes only a query string as an argument and requests the API for that query, along with some query parameters. These query parameters are the additional information given to the server to process and respond to…

Continue ReadingConfigurable Services in Loklak Search