How to configure the index location of compass as relative path

Source: Internet
Author: User

Compass is a Java project encapsulated by Lucene, which makes full-text retrieval very easy in spring and hibernate environments and greatly improves the efficiency. Therefore, in myblog, I also used compass as the full-text index. You can find the compass configuration from the petclinic in the samples of compass. Classpath: ORG/Compass/sample/petclinic. cmd. xml Classpath: petclinic. CPM. xml File: // $ {user. Home}/Compass/petclinic Org. Compass. Spring. transaction. springsynctransactionfactory The index location configured here is the absolute path of the system. Most people may want the index to be placed in a sub-directory of the project, that is, the relative path. However File: // $ {user. Home}/Compass/petclinic Is /Compass/petclinic This is not acceptable. At the beginning, I modified it like this. In fact, let's take a look at the source code of localcompassbean to know how to do it. If (this. compasssettings! = NULL) {config. getsettings (). addsettings (this. compasssettings );}...... if (config. getsettings (). getsetting (compassenvironment. connection) = NULL & connection! = NULL) {config. getsettings (). setsetting (compassenvironment. connection, connection. getFile (). getabsolutepath ();} You can see that if compass is configured when you configure compasssettings. engine. in connection, compass will use the value you configured, that is, the absolute path. If you do not configure it, the connection value will be read, and the connection type is Org. springframework. core. io. resource, which is a spring-encapsulated Resource class. There are many access methods for file classpath, so you can use the relative path here. Remove the compass. Engine. Connection configuration in compasssettings, and add the connection configuration to implement the relative path. For example, the configuration in myblog Classpath: COM/jdkcn/compass /Lucene/Indexes Org. Compass. Spring. transaction. springsynctransactionfactory After the webapp is started, compass will create an index under the/Lucene/indexes directory of your app.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.