MSA*_*MSA 2 java lucene configuration solr
我想使用MySql数据库实现Solr提供的拼写检查功能,但我不明白如何.
这是我想要做的基本流程.
我有一个简单的inputText(在JSF中),如果我输入单词shwo,应该显示对OutputLabel的响应.
首先,我使用以下工具和框架:
JBoss应用服务器6.1.
Eclipse
JPA
JSF(Primefaces)
我到目前为止所做的步骤:
步骤1: 从以下网址下载Solr服务器:http://lucene.apache.org/solr/downloads.html 提取内容.
第2步: 添加到Envoierment变量(您有solr服务器的地方):
solr.solr.home=D:\JBOSS\solr-4.4.0\solr-4.4.0\example\solr
Run Code Online (Sandbox Code Playgroud)
第3步:
打开solr war并向solr.war\WEB-INF\web.xml添加env-entry - (简单方法)
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>D:\JBOSS\solr-4.4.0\solr-4.4.0\example\solr</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
Run Code Online (Sandbox Code Playgroud)
或导入项目变更和战争.
第4步:
浏览器:localhost:8080/solr/
出现solr控制台.到目前为止一切运作良好.
我发现一些有用的代码(我的意见)返回:
[collection1] webapp =/solr path =/spell params = {spellcheck = on&q = whatever&wt = javabin&qt =/spell&version = 2&spellcheck.build = true} hits = 0 status = 0 QTime = 16
以下是从上面给出结果的代码:
SolrServer solr;
try {
solr = new CommonsHttpSolrServer("http://localhost:8080/solr");
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/spell");
params.set("q", "whatever");
params.set("spellcheck", "on");
params.set("spellcheck.build", "true");
QueryResponse response = solr.query(params);
SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse();
if (!spellCheckResponse.isCorrectlySpelled()) {
for (Suggestion suggestion : spellCheckResponse.getSuggestions()) {
System.out.println("original token: " + suggestion.getToken() + " - alternatives: " + suggestion.getAlternatives());
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我还在data-config.xml中添加了
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource" name="altadict"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/myproject"
user="root"
password=""
/>
<document name="myproject">
<entity name="myproject" query="SELECT * FROM words">
<field column="Id" name="Id" />
<field column="Cuvint" name="Cuvint" />
<field column="TradDiac" name="TradDiac" />
<field column="Explicatie" name="Explicatie" />
<field column="TipCuvint" name="TipCuvint" />
<field column="ItalicParant" name="ItalicParant" />
</entity>
</document>
</dataConfig>
Run Code Online (Sandbox Code Playgroud)
schema.xml中
<field name="Id" type="tlong" indexed="true" stored="true" required="true"/>
<field name="Cuvint" type="string" indexed="true" stored="true" required="true"/>
<field name="TradDiac" type="string" indexed="true" stored="true" required="true"/>
<field name="Explicatie" type="string" indexed="true" stored="true"/>
<field name="TipCuvint" type="string" indexed="true" stored="true" required="true"/>
<field name="ItalicParant" type="string" indexed="true" stored="true"/>
Run Code Online (Sandbox Code Playgroud)
solrconfig.xml中
<!-- altadict Request Handler -->
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="df">Cuvint</str>
<str name="spellcheck.dictionary">default</str>
<str name="spellcheck">on</str>
<str name="spellcheck.extendedResults">true</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.maxResultsForSuggest">5</str>
<str name="spellcheck.collate">true</str>
<str name="spellcheck.collateExtendedResults">true</str>
<str name="spellcheck.maxCollationTries">10</str>
<str name="spellcheck.maxCollations">5</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFieldType">string</str> <!-- Replace with Field Type of your schema -->
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">examplew</str> <!-- Replace with field name as per your scheme -->
<str name="spellcheckIndexDir">./spellchecker</str>
<str name="buildOnOptimize">true</str>
<str name="buildOnCommit">true</str>
</lst>
<!-- a spellchecker that uses a different distance measure -->
<lst name="spellchecker">
<str name="name">jarowinkler</str>
<str name="field">spell</str>
<str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str>
<str name="spellcheckIndexDir">./spellchecker2</str>
</lst>
</searchComponent>
Run Code Online (Sandbox Code Playgroud)
和libs
问题:
1.如何通过我的数据库建立数据库连接并搜索内容以查看是否有任何可匹配的单词?
2.如何进行配置.(solr-config.xml,shema.xml等)?
3.如何从我的视图(xhtml)发送一个字符串,以便solr服务器知道他要查找的内容?
4.如何从Cuvine数据库专栏中获得正确的单词,例如wodr我希望solr返回单词.
我阅读了有关solr的所有信息,但目前还不清楚:
链接:主页:http:
//lucene.apache.org/solr/
主页教程:http: //lucene.apache.org/solr/4_4_0/tutorial.html
Solr Wiki:
http: //wiki.apache.org/solr/Solrj ---官方solrj文档
http://wiki.apache.org/solr/SpellCheckComponent
Solr config:http : //wiki.apache.org/solr/SolrConfigXml http://www.installationpage.com/solr/solr-configuration-tutorial-schema-solrconfig-xml/ http://wiki.apache.org/ Solr的/ SchemaXml
StackOverflow证明: Solr你的意思是(拼写检查组件)
Solr数据库集成:
http://www.slideshare.net/th0masr/integrating-the-solr-search-engine
http://www.cabotsolutions.com/2009/05/using-solr-lucene-for-full-text -Search与- MySQL的-DB /
Solr拼写检查:
http://docs.lucidworks.com/display/solr/Spell+Checking
http://searchhub.org/2010/08/31/getting-started-spell-checking-with-apache-lucene-and -solr/
http://techiesinsight.blogspot.ro/2012/06/using-solr-spellchecker-from-java.html
http://blog.websolr.com/post/2748574298/spellcheck-with-solr-spellcheckcomponent
如何在SolrJ中使用SpellingResult类
我真的需要你的帮助.退休.
1.如何与我的数据库建立数据库连接并搜索内容以查看是否有任何可匹配的单词?
您需要将数据从MySql索引到Solr.
这可以通过构建应用程序来完成,以从MySql读取记录并将数据提供给Solr.
或者,正如已经回答了使用数据导入处理程序(DIH),这将使能让你连接到MySQL和负荷数据和索引成Solr的.此外,使您可以执行增量更新
2.如何进行配置.(solr-config.xml,shema.xml等)?
拼写检查器的字段应标记为文本分析.
由于您的字段标记为字符串,因此没有标记化.
Schema.xml的
<field name="Cuvint" type="text" indexed="true" stored="true" required="true"/>
Run Code Online (Sandbox Code Playgroud)
此外,对于solrconfig.xml,请替换您要考虑拼写建议的字段
<str name="field">examplew</str> <!-- Replace with field name as per your scheme -->
Run Code Online (Sandbox Code Playgroud)
检查示例.
3.如何从我的视图(xhtml)发送一个字符串,以便solr服务器知道他要查找的内容?
通常,我们在Solr请求中结合搜索和拼写建议来实现此功能.
当我们没有从Solr获得任何结果时,我们检查拼写检查建议是否可用并显示为Did you mean建议此外,我们不会等待拼写建议,而是向用户提供阻止往返服务器的提前输入建议.
4.如何从Cuvine数据库专栏中获得正确的单词,例如wodr我希望solr返回单词.
检查示例以配置拼写检查,这应该提供建议.
| 归档时间: |
|
| 查看次数: |
14020 次 |
| 最近记录: |