当前位置:首页 » 软件开发
开发技术指南» 文章正文
    引言: Suppose you are searching the We
 

 

    摘要:user interfaces often end up a series of tightly integrated components that are hard to build, maintain, and test. but it doesnt have to be that way! in this article, youll learn about a technique for......
    摘要: the strategy, template method, and bridge patterns one of the great benefits of object-oriented programming is polymorphism; i.e., the ability to send a message to an object without knowi......


QueryParser Rules

suppose you are searching the web for pages that contain both the words java and net but not the word dot. what if search engines made you type in something like the following for this simple query?

java and net not dot

this article assumes you have some basic understanding of lucene, including building and querying an index. you may want to take a look back at the lucene intro published in july on java.net. the focus here is on lucenes queryparser, providing an in-depth look at its capabilities and caveats. 【程序编程相关:你知道数据大小吗?

booleanquery query = new booleanquery(); query.add(new termquery(new term("contents","java")), true, false); query.add(new termquery(new term("contents", "net")), true, false); query.add(new termquery(new term("contents", "dot")), false, true);

that would be a real drag. thankfully, google, nutch, and other search engines are friendlier than that, allowing you to enter something much more succinct: 【推荐阅读:小议局部类

using queryparser 【扩展信息:BeanShell

first well see what is involved to use queryparser in an application. then, lucenes query api is shown in relation to the corresponding queryparser syntax. elaboration on the details of queryparser syntax is then followed by how queryparsers features can be customized.

using queryparser is quite straightforward. three things are needed: an expression, the default field name to use for unqualified fields in the expression, and an analyzer to pieces of the expression.

field-selection qualifiers are discussed in the query syntax section. analysis, specific to query parsing, is covered in the "analysis paralysis" section. for a more detailed look at lucene analyzers, refer to the lucene intro article.

now, lets parse an expression:

string humanquery = gethumanquery(); query query = queryparser.parse(humanquery, "contents", new standardanalyzer());

once youve obtained a query object, searching is done the same as if the query had been created directly through the api. from the intro article, here is a full method to search an existing index with a user-entered query string, and display the results to the console:


...   下一页
    摘要:the last ten years of software development have seen the rise of the internet and open standards, most prominently html. to most non-technical people, web pages (just html over a tcp/ip connection) ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE