Requesting from Client Applications
Here, we'll explain how to use an Apache Solr instance from external sources.
Page Sections
Apache Solr API
By using various UI features in KandaSearch, you can easily register documents to the created Apache Solr instance and perform searches.
However, when it comes to building an actual search system, you'll need dedicated servers for registering documents and client application servers with user-friendly interfaces for search users to easily perform searches.
To utilize the Apache Solr instance on KandaSearch from these servers, you'll use the Apache Solr API.
The Apache Solr API is a REST-like API that allows you to add, update, and delete data.
With the search API, you can perform various types of searches such as keyword search, semantic search, facet, and highlight.
The client application calling the API can be implemented in various programming languages as long as it can send HTTP Requests and receive and parse HTTP Responses. Java is, of course, supported, but implementations are possible in many other languages including Python, Ruby, PHP, Go, C/C++, and C#.
Information about the Apache Solr API is extensively documented on the official Apache Solr website.
Preparation
KandaSearch's Apache Solr instances, by default, reject all external connections.
Therefore, it's necessary to pre-register the IP addresses of the PCs or servers from which you intend to send Apache Solr API requests in CIDR format.
You can configure the source IP address settings either during the creation of the Apache Solr instance or by selecting 'Settings' from the left-side menu of the instance view after creation, and then configuring the 'Allowed IP Ranges' section.
Once the configuration of 'Allowed IP Ranges' is completed, you should verify if the connection can be established from your PC or server.
For PCs, check if you can access the Apache Solr Admin UI from a browser (the URL is displayed in the instance overview).
For servers, you can use commands like wget to confirm if there is a response from the Apache Solr Admin UI.
Notes.
- Regardless of permission settings, pinging(ping command) the Apache Solr instance on KandaSearch does not work.
- If you cannot connect, please check if the port number (TCP 443) used for connecting to Solr is open in your firewall or other security settings, and also verify if there is any proxy configuration.
Example of API Usage
Here are a few examples of using the Apache Solr API with cURL commands.
Execution Environment:
- Using an instance from the Community plan.
- Subdomain name: projecttest-test-com (automatically generated from the following)
- Project name: projecttest
- Instance name: test-com
- Collection name: livedoornews
- Fields: id (file name), title (title), body (body), etc.
Keyword Search (No Keywords Specified)
curl 'https://projecttest-test-com.c.kandasearch.com/solr/livedoornews/select?q=*:*&rows=10&fl=id,score&defType=lucene'
Keyword Search (Specifying the keyword as 'コンピューター')
curl 'https://projecttest-test-com.c.kandasearch.com/solr/livedoornews/select?q=%E3%82%B3%E3%83%B3%E3%83%94%E3%83%A5%E3%83%BC%E3%82%BF%E3%83%BC&rows=10&fl=id,score,title,body&Type=lucene'
Indexing (Using a local JSON file named livedoor.json)
curl -X POST 'https://projecttest-test-com.c.kandasearch.com/solr/livedoornews/update?commit=true&indent=true' --data-binary @livedoor2.json -H 'Content-Type: text/json'
Delete All Documents
curl -X POST 'https://projecttest-test-com.c.kandasearch.com/solr/livedoornews/update?commit=true' -H 'Content-type:text/json;charset=utf-8' --data-binary '{"delete":{"query":"*:*"}}'
Sample Web Application
In KandaSearch, we provide sample web applications tailored to your Apache Solr instance environment.
The application is written in Java (using Spring Boot) and can be downloaded from the 'Search' of the instance view.
By using this source code as a reference, you can efficiently advance the development of your web application by understanding the access methods to the instance and making adjustments to the design, among other things.
The usage of the web application on local PCs such as Mac or WSL is as follows. To run this application, you need a Java 11 or higher runtime environment. Additionally, please note that semantic search is currently not supported.
- Log in to KandaSearch by clicking here.
- From the project list screen, click on the name of the target project. (To display the project list, click on the KandaSearch logo in the upper left corner of the screen.)
- From the project overview, click on the name of the target instance.
- Click on 'Search' from the left side menu of the instance view.
- Specify the collection, handler, unique key, and field names to display in the left pane of the search screen. (Click 'SEARCH' to confirm that no errors occur.)
- Click on 'DOWNLOAD WEBAPP (JAVA)' to download the application.
- Extract the downloaded zip file and copy it to an environment where Java can be executed.
- Inside the extracted folder, there is a war file. Execute the war file by specifying it in the format like
java -jar ks-search-client-1.1.4.war
. - For example, if you run Java from the terminal on Mac, access http://localhost:9090 from a browser like Chrome.
- The Java application sends HTTP Requests to the Apache Solr instance in KandaSearch, retrieves search results in HTTP Responses, and displays them in the browser.
Notes.
- To stop the Java program, enter Ctrl+C.
- By default, the port number used by this application is TCP 9090.
- For more details, please refer to the README.md included in the zip file.