温哥华compass卡 的@searchableschema属性是什么意思

grails、Searchable问题:报此错的原因是因为文件缓存空间冲突;
12:38:48,484 [localhost-startStop-1] ERROR StackTrace
- Full Stack Trace:
org.compass.core.engine.SearchEngineException: Failed to rename index [C:\Documents and Settings\Administrator\.grails\projects\talentExchange\searchable-index\production/index/t_base] to [C:\Documents and Settings\Administrator\.grails\projects\talentExchange\searchable-index\production\index\t_base-copy0]
at org.compass.core.lucene.engine.store.FSDirectoryStore.beforeCopyFrom(FSDirectoryStore.java:157)
at org.compass.core.lucene.engine.store.DefaultLuceneSearchEngineStore.copyFrom(DefaultLuceneSearchEngineStore.java:616)
at org.compass.core.lucene.engine.store.DefaultLuceneSearchEngineStore.copyFrom(DefaultLuceneSearchEngineStore.java:602)
at org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager$ReplaceIndexOperationCallback$1$1.run(DefaultLuceneSearchEngineIndexManager.java:298)
at org.compass.core.lucene.engine.manager.IndexHoldersCache.doUnderCacheLock(IndexHoldersCache.java:126)
at org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager$ReplaceIndexOperationCallback$1.doInTransaction(DefaultLuceneSearchEngineIndexManager.java:294)
at org.compass.core.impl.DefaultCompass$CompassTransactionContext.execute(DefaultCompass.java:423)
at org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager$ReplaceIndexOperationCallback.secondStep(DefaultLuceneSearchEngineIndexManager.java:290)
at org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager.doOperate(DefaultLuceneSearchEngineIndexManager.java:248)
at org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager.doReplaceIndex(DefaultLuceneSearchEngineIndexManager.java:266)
at org.compass.core.lucene.engine.manager.DefaultLuceneSearchEngineIndexManager.replaceIndex(DefaultLuceneSearchEngineIndexManager.java:261)
at org.compass.gps.impl.SingleCompassGps.doIndex(SingleCompassGps.java:118)
at org.compass.gps.impl.AbstractCompassGps.index(AbstractCompassGps.java:154)
at org.compass.gps.impl.AbstractCompassGps.index(AbstractCompassGps.java:128)
at grails.plugin.searchable.internal.compass.CompassGpsUtils.index(CompassGpsUtils.java:49)
at SearchableGrailsPlugin$_closure3.doCall(SearchableGrailsPlugin.groovy:158)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
一、 执行grails install-searchable-config 只有执行此命令后会在当前项目grails-app/conf/中创建一个文件打开Searchable.groovy
二、 修改searchable.groovy
compassConnection = new File(
"${userHome}/.grails/projects/${appName}/searchable-index/${grailsEnv}"
).absolutePath
String path =
System.getProperty("user.dir")
//ApplicationContext.getResource("/");
MD5Codec.encode(path);
compassConnection = new File(
"${userHome}/.grails/projects/${appName}/searchable-index/${grailsEnv}${path}"
).absolutePath
grails中的cache
Grails中数据的保存、更新和删除。
grails searchable 使用
grails默认全局gorm配置
关于404报错的问题
Java ee中常见400等错误出现原因 总结
grails动态加载gsp
Grails Searchable Plugin
grails把数字数组改成字符串数组
没有更多推荐了,Compass - Java Search Engine Framework
Compass is an
project built on top of
aiming at simplifying the integration of search into any Java application.
Documentation搜索引擎Compass的例子
Product 搜索实体类 可以对应数据库里的表
package com.ym.compass.
import org.compass.annotations.I
import org.compass.annotations.S
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableP
import org.compass.annotations.S
//标识为搜索实体
@Searchable
public class Product {
public Product(){
public Product(String id){
public Product(String id, String name, int price, String saler,
String descripiton) {
this.name =
this.price =
this.saler =
this.descripiton =
@SearchableId
//compass 要求每个搜索实体类都要具有一个标识属性,这点和Hibernate很相似
public String getId() {
public void setId(String id) {
* Index.UN_TOKENIZED 不对该Field进行分词 但是建立索引 该属性已过时,建议采用NOT_ANALYZED
* Index.TOKENIZED 先分词后索引
该属性已过时,建议采用ANALYZED
* Index.NOT_ANALYZED
不分词但建立索引
* Index.ANALYZED
分词并且建立索引
*Index.NO 不分词不建立索引
没有索引就不会查询这个字段
//设置收索属性 分词并建立索引
//Store默认值为YES
boost的默认值为1用于设置属性在索引中的重要性
@SearchableProperty (index= Index.ANALYZED,store=Store.YES,boost=1)
public String getName() {
public void setName(String name) {
this.name =
@SearchableProperty
public int getPrice() {
public void setPrice(int price) {
this.price =
@SearchableProperty
public String getSaler() {
public void setSaler(String saler) {
this.saler =
@SearchableProperty (index=Index.ANALYZED,store=Store.YES)
public String getDescripiton() {
public void setDescripiton(String descripiton) {
this.descripiton =
******************************************************
ProductSearchBean
真正实现Compass搜索的类
package com.ym.compass.service.
import java.util.ArrayL
import java.util.L
import org.compass.annotations.config.CompassAnnotationsC
import org.compass.core.C
import org.compass.core.CompassE
import org.compass.core.CompassH
import org.compass.core.CompassQuery.SortD
import org.compass.core.CompassQuery.SortPropertyT
import org.compass.core.CompassQueryB
import org.compass.core.CompassS
import org.compass.core.CompassT
import org.compass.core.config.CompassE
import com.ym.compass.bean.P
import com.ym.compass.bean.QueryR
import com.ym.compass.service.ProductS
public class ProductSearchBean implements ProductSearch {
private Compass compass =
public ProductSearchBean() {
// 编程式配置 也可以使用配置文件
compass = new CompassAnnotationsConfiguration()
.setSetting(CompassEnvironment.CONNECTION,
"file://indexfile")
// .setSetting(CompassEnvironment.CONNECTION, "ram://index")
// //在内存中建立索引
.setSetting("compass.engine.analyzer.default.type",
"net.paoding.analysis.analyzer.PaodingAnalyzer")
//进行加亮处理 如把关键字变成红色
.setSetting(
"compass.engine.highlighter.default.formatter.simp.pre",
"&font color='red'&")
.setSetting(
"compass.engine.highlighter.default.formatter.simp.post",
"&/font&")
.addScan("com.ym.compass.bean").buildCompass();//扫描包下面的实体类 如果发现@Searchable就会当作搜索实体类
} catch (CompassException
e.printStackTrace();
public QueryResult&Product& search(String keyWord, int firstIndex,
int maxResult) {
QueryResult&Product& qr = new QueryResult&Product&();
CompassSession session =
CompassTransaction tx =
session = compass.openSession();
tx = session.beginTransaction();
CompassHits hits = session.find(keyWord);
List&Product& products = new ArrayList&Product&();
int length = firstIndex + maxR
if (length & hits.length()) {
length = hits.length();
for (int i = firstI i & i++) {
Product product = (Product) hits.data(i);
product.setDescripiton(hits.highlighter(i).fragment(
"descripiton"));
products.add(product);
qr.setResults(products);
qr.setTotal(hits.length());
hits.close();
} catch (CompassException e) {
e.printStackTrace();
tx.rollback();
} finally {
if (session != null && !session.isClosed())
session.close();
* 高级查询
销售员为“yang”的商品里面包含关键字的商品
public QueryResult&Product& search(String keyWord, String saler,
int firstIndex, int maxResult) {
QueryResult&Product& qr = new QueryResult&Product&();
CompassSession session =
CompassTransaction tx =
session = compass.openSession();
tx = session.beginTransaction();
// 查询指定类型的匹配记录,并按照什么排序
CompassQueryBuilder queryBuilder = session.queryBuilder();
CompassHits hits = queryBuilder.bool()
.addMust(queryBuilder.spanEq("saler", saler))
.addMust(queryBuilder.queryString(keyWord).toQuery())
.toQuery().addSort("price", SortPropertyType.INT, SortDirection.REVERSE)
// 等同于效果 sql
where saler=yang and (xxx like ?) order by price desc
List&Product& products = new ArrayList&Product&();
int length = firstIndex + maxR
if (length & hits.length()) {
length = hits.length();
for (int i = firstI i & i++) {
Product product = (Product) hits.data(i);
//把描述中 有关键字的部分 特殊处理 变成红色
product.setDescripiton(hits.highlighter(i).fragment(
"descripiton"));
product.setName(hits.highlighter(i).fragment(
products.add(product);
qr.setResults(products);
qr.setTotal(hits.length());
hits.close();
} catch (CompassException e) {
e.printStackTrace();
tx.rollback();
} finally {
if (session != null && !session.isClosed())
session.close();
public void destroy() {
compass.close();
public void buildIndex() {
CompassSession session =
CompassTransaction tx =
session = compass.openSession();
tx = session.beginTransaction();
Product p1 = new Product("1", "红豆经典衬衫", 150, "汤姆", "经典舒适衬衫 大品牌你懂的");
session.create(p1);
Product p2 = new Product("5", "红豆内衣", 50, "杰克", "经典舒适衬衫 大品牌你懂的");
session.create(p2);
Product p3 = new Product("8", "联想笔记本", 150, "汤姆", "经典商务本,不要错过哦");
session.create(p3);
Product p4 = new Product("11", "文具笔记本", 10, "琼斯", "书写流畅");
session.create(p4);
Product p5 = new Product("17", "红豆", 8, "汤姆", "红豆冰淇淋很好吃的哦");
session.create(p5);
tx.commit();
} catch (CompassException e) {
e.printStackTrace();
tx.rollback();
} finally {
if (session != null && !session.isClosed())
session.close();
public void deleteIndex(Product product) {
CompassSession session =
CompassTransaction tx =
session = compass.openSession();
tx = session.beginTransaction();
session.delete(product);
tx.commit();
} catch (CompassException e) {
e.printStackTrace();
tx.rollback();
} finally {
if (session != null && !session.isClosed())
session.close();
先删除再新增
public void updateIndex(Product product) {
CompassSession session =
CompassTransaction tx =
session = compass.openSession();
tx = session.beginTransaction();
session.delete(product);
session.save(product);
} catch (CompassException e) {
e.printStackTrace();
tx.rollback();
} finally {
if (session != null && !session.isClosed())
session.close();
详细代码见附件,是在eclipse下一个可以通过Junit运行的工程。 解压密码:123
dic目录下是庖丁分词器的字典,paoding-dic-home.properties文件指定字典的存放位置
(7.4 MB)下载次数: 54
没有更多推荐了,基于JAVA的LUCENE的COMPASS框架说明、使用案例技术文档_百度文库
您的浏览器Javascript被禁用,需开启后体验完整功能,
享专业文档下载特权
&赠共享文档下载特权
&100W篇文档免费专享
&每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
基于JAVA的LUCENE的COMPASS框架说明、使用案例技术文档
阅读已结束,下载本文需要
定制HR最喜欢的简历
下载文档到电脑,同时保存到云知识,更方便管理
加入VIP
还剩26页未读,
定制HR最喜欢的简历
你可能喜欢菜鸟程序员一名,码农路上磕磕绊绊。。。。
Compass(汤阳光)
1. Hibernate 和 Compass 从总体上进行对比. Hibernate: 是ORM框架,面向对象的操作.提供从对象 到表,从表到对象服务.是对JDBC的一种封装.通过Session,提供save()/delete()/update()/get /load()/hql/QBC等方法.Hibernate.cfg.xml 配置数据库链接信息,声明映射文件,和其他配置..hbm.xml 对象到表,属性到列的对应关系.Compass: 是 OSEM/Compass.从对象到 document,从 document 到对象.是对 Lucene
API 的一种封装.通过 CompassSession.提供save()/delete()/update()/get/load()/queryString/Query等方 法.Compass.cfg.xml 配置链接信息(索引目录),声明映射文件,和其他配置.pom.xml 对象到document,属性到field的对应关系.2. 在使用上进行对比. Hibernate: Hibernate.cfg.xml Configuration①编程方式:cfg. = new Configuation(); cfg.setPropxxx(); cfg.setPropxxx(); … ② 配置文件Cfg = new Configration().configure(); Cfg.configure(“/hibernate.cfg.xml”); ③Hbm.xml使 用.hbm.xml文件(XML文件)注解Compass: 主 配置CompassConfiguration①编程方式Cfg = new CompassConfiguration() Cfg.set(“key”,”value”); … ② 配置文件Cfg.configure(); //cfg.configure(“/compass.cfg.xml”); ③ 映射文件:XML文件注解3.API的对比 Hibernate: Fg = new Configuration().configure(); Sf = cfg.buildSessionFactory(); Session = sf.openSession(); Tx = session.beginTransaction(); //do something //session.save/update/delete/…..() Tx.commit(); Session.close(); Compass: Cfg = new CompassConfiguration().configure(); Compass = cfg.buildCompass(); CompassSession session = compass.openSession(); CompassTransaction tx = session.beginTransaction(); //do something //session.save/update/delete/….() Tx.commit(); Session.close(); 4.API:
Configuration --& CompassConfiguration SessionFactory --& Compass Session --& CompassSession Transaction --& CompassTransaction5.Session方法: 保 存: save() --& create()删除:delete() --& delete()Update() --& save()saveOrUpdate() --& save()get/load() --& get/load()6.Compass 是使用过程 1)导入 jar包 2)对映射文件进行配置.这里采用的是注解 方式. @Searchable在对象类前注释.@SearchableId在对象的ID属性上注释.@SearchableProperty(store = Store.YES, index = Index.ANALYZED, boost = 2.0F)在对象的普通属性上注释.store = Store.YES是否存储index = Index.ANALYZED是否建立索引boost = 2.0F对排序起到作用.3)加载相关的配置文件 private C
public void init() {
CompassConfiguration cfg = new CompassConfiguration();
cfg.setConnection("./indexPath/");// 连接信息
cfg.addClass(Article.class);// 声明映射信息
// cfg.setSetting("key", "value");//其他配置
compass = cfg.buildCompass();
} 4)创建索引
CompassSession session = compass.openSession();
CompassTransaction tx = session.beginTransaction();
session.create(article);
tx.commit();
session.close(); 5)搜 索
List&Article& list = new ArrayList&Article&();
CompassSession session = compass.openSession();
CompassTransaction tx = session.beginTransaction();
CompassHits hits = session.find(queryString);
for (int i = 0; i & hits.length(); i++) {
Article article = (Article) hits.data(i);
list.add(article);
tx.commit();
session.close();
通过上面实例行程序的编写,可以和昨天学习的 luncene 形成鲜明的对比.不过,老师说了,就像学习 Hibernate 一样,JDBC 没有学习好 Hibernate 是不可能学好的.同样 luncene ,基础没有学习好,Compass 是不可能学习好的,就算会用,也不能理解.不能达到一定的高度.所以,学习要了解的深入一些.不能只是皮毛.
传智播客--luncene(汤阳光)
记录汤阳光OA视频每集的要点
没有更多推荐了,

我要回帖

更多关于 广汽菲克jeepcompass 的文章

 

随机推荐