In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "what is the use of Solr". In daily operation, I believe many people have doubts about the use of Solr. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what is the use of Solr?" Next, please follow the editor to study!
As the search engine function has the functional requirements for improving the user experience in the portal community, which involves a large number of functional requirements for search engines in the portal community, there are centralized solutions to choose from:
1. Based on Lucene own encapsulation to achieve on-site search. The workload and expansibility are large, so it is not adopted.
two。 Call the API of Google and Baidu to realize intra-site search. The binding with the third-party search engine is too dead to meet the needs of later business expansion and will not be adopted for the time being.
3. Realize intra-site search based on Compass+Lucene. It is suitable for indexing database-driven application data, especially to replace the traditional like'% expression%' to index fields such as varchar or clob. It is a worthwhile scheme to realize intra-site search. However, we still need to do a certain degree of encapsulation in distributed processing and interface encapsulation, which is not used for the time being.
4. Realize intra-site search based on Solr. The encapsulation and expansibility are good, and a more complete solution is provided, so this scheme is adopted in the portal community, and the Compass scheme is added later.
1. Introduction to Solr
Solr is a Lucene-based Java search engine server. Solr provides flat search, hit eye-catching display, and supports a variety of output formats (including XML/XSLT and JSON formats). It is easy to install and configure and comes with a HTTP-based management interface. Solr has been used in many large websites, which is more mature and stable. Solr wraps and extends Lucene, so Solr basically follows the relevant terminology of Lucene. More importantly, the indexes created by Solr are fully compatible with the Lucene search engine library. With proper configuration of Solr, coding may be required in some cases, and Solr can read and use indexes built into other Lucene applications. In addition, many Lucene tools (such as Nutch, Luke) can also use indexes created by Solr.
2. Installation and configuration of Solr under Tomcat
Because Solr is based on java development, Solr can be easily deployed in both windows and Linux. However, because Solr provides some shell scripts for testing, management and maintenance, it is recommended to install it on Linux during production deployment and can be used in windows during testing.
The following is explained by the installation and configuration of Solr under Linux, which is similar to windows.
Wget http://apache.mirror.phpchina.com/tomcat/tomcat-6/v6.0.16/bin/apache-tomcat-6.0.16.zip
Unzip apache-tomcat-6.0.16.zip
Mv apache-tomcat-6.0.16 / opt/tomcat
Chmod 755 / opt/tomcat/bin/*
Wget http://apache.mirror.phpchina.com/lucene/solr/1.2/apache-solr-1.2.0.tgz
Tar zxvf apache-solr-1.2.0.tgz
The most troublesome thing about the installation and configuration of Solr is the understanding and configuration of solr.solr.home. There are three main types.
Based on the current path
Cp apache-solr-1.2.0/dist/apache-solr-1.2.0.war / opt/tomcat/webapps/solr.war
Mkdir / opt/solr-tomcat
Cp-r apache-solr-1.2.0/example/solr/ / opt/solr-tomcat/
Cd / opt/solr-tomcat
/ opt/tomcat/bin/startup.sh
Because in this case (with no solr.solr.home environment variable or JNDI set), Solr looks for. / solr, so you need to switch to / opt/solr-tomcat at startup
Based on environment variable solr.solr.home
Add the following environment variable to the current user's environment variable (.bash _ profile) or / opt/tomcat/catalina.sh
Export JAVA_OPTS= "$JAVA_OPTS-Dsolr.solr.home=/opt/solr-tomcat/solr"
JNDI-based configuration
Mkdir-p / opt/tomcat/conf/Catalina/localhost
Touch / opt/tomcat/conf/Catalina/localhost/solr.xml, which is as follows:
Visit the solr management interface http://ip:port/solr
3. Solr principle
Solr provides standard http interface to add, delete, modify and query the index of the data. In Solr, users start indexing and searching by sending HTTP requests to Solr Web applications deployed in servlet containers. The Solr accepts the request, determines the appropriate SolrRequestHandler to use, and then processes the request. The response is returned in the same way through HTTP. The default configuration returns a standard XML response for Solr, or you can configure an alternate response format for Solr.
You can pass four different index requests to the Solr index servlet:
Add/update allows you to add or update documents to Solr. These additions and updates cannot be searched until they have been submitted.
Commit tells Solr that all changes made since the last commit should be searchable.
Optimize reconstructs Lucene's files to improve search performance. It is usually better to perform an optimization after the index is complete. If updates are frequent, optimizations should be arranged when usage is low. An index can run normally without optimization. Optimization is a time-consuming process.
Delete can be specified through id or query. Delete by id will delete the document with the specified id; delete by query will delete all documents returned by the query.
A typical Add request message
TWINX2048-3200PRO CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory-Retail Corsair Microsystems Inc. Electronics memory CAS latency 2,2-3-3-6 timing, 2.75v, unbuffered, heat-spreader 1855 true VS1GB400C3 CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory-Retail Corsair Microsystems Inc. Electronics memory 74.99 7 true
A typical search result message:
0 6100 *, score true content: "faceted browsing" 1.058217 http://localhost/myBlog/solr-rocks-again.html Solr is Great solr Lucene,enterprise,search,greatness Solr has some really great features, like faceted browsing and replication Solr has some really great features, like faceted browsing and replication 2007-01-07T05:04:00.000Z solr,lucene,enterprise,search Greatness 8 Solr is Great http://localhost/myBlog/solr-rocks-again.html Solr has some really great features, like faceted browsing and replication
For detailed instructions on the use of solr, please refer to
Http://wiki.apache.org/solr/FrontPage
4. Solr test usage
The installation package for Solr contains the relevant test samples, and the path is in apache-solr-1.2.0/example/exampledocs
1. Use the shell script (curl) to test the operation of Solr:
Cd apache-solr-1.2.0/example/exampledocs
Vi post.sh, modify the value of URL variable URL= http://localhost:8080/solr/update according to the ip and port of tomcat
. / post.sh * .xml #
two。 Use Solr's java package to test the operation of Solr:
Check out help: java-jar post.jar-help
Submit test data:
Java-Durl= http://localhost:8080/solr/update-Ddata=files-jar post.jar. Xml
Take the addition of index fields liangchuan and url as examples to illustrate the use of index commands in Solr.
1) modify the schema of solr to configure the description of the field that needs to be indexed:
Vi / opt/solr-tomcat/solr/conf/schema.xml, add the following in
2) create a xml test file for adding index requests
Touch / root/apache-solr-1.2.0/example/exampledocs/liangchuan.xml, which is as follows:
Liangchuan000 Solr, the Enterprise Search Server Apache Software Foundation liangchuan's solr "hello,world" test http://www.google.com
3) submit an index request
Cd apache-solr-1.2.0/example/exampledocs
. / post.sh liangchuan.xml
4) query
Http://localhost:8080/solr/admin query through the administrator interface of solr
Or pass the curl test:
Export URL= "http://localhost:8080/solr/select/"
Curl "$URL?indent=on&q=liangchuan&fl=*,score"
5. Description of Solr query condition parameters
Example of parameter description
Q
The query used to search in Solr. You can include sorting information by appending a semicolon and the name of an indexed and unbroken field. The default sort is score desc, which refers to sorting in descending order of score.
Q=myField:Java AND otherField:developerWorks; date asc
This query searches for the two specified fields and sorts the results based on a date field.
Start specifies the initial offset to the result set. Can be used to paginate the results. The default value is 0.
Start=15
Returns the result starting from the 15th result.
Rows returns the maximum number of documents. The default value is 10. Rows=25
Fq provides an optional filter query. Query results are limited to only the results returned by the search filter query. Filtered queries are cached by Solr. They are useful for improving the speed of complex queries.
Any valid query that can be passed with the Q parameter, except for sorting information.
Hl when hl=true, the snippet is prominently displayed in the query response. The default is false. See the Solr Wiki section on the eye-catching display parameters for more options hl=true
Fl specifies the Field set that should be returned in the document results as a comma-separated list. The default is "*", which refers to all fields. "score" means that scoring should also be returned.
*, score
The query condition parameter Q of Solr has the same format as Lucene
6. Solr usage patterns in the portal community
If you need to use solr in the portal community, you can use the following pattern:
For the existing data in the original system or the large amount of data that needs to be indexed
Directly adopt the interface mode of calling solr through http, which is inefficient. Using solr's own support for csv, export the data to csv format, and then call solr's csv interface http://localhost:8080/solr/update/csv.
New data to the system
First assemble the data that needs to be indexed into xml format, and then use httpclient to submit the data to solr's http interface, such as
Http://localhost:8080/solr/update
At this point, the study on "what is the use of Solr" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.