本文整理匯總了Java中org.apache.lucene.queryParser.MultiFieldQueryParser.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java MultiFieldQueryParser.parse方法的具體用法?Java MultiFieldQueryParser.parse怎麽用?Java MultiFieldQueryParser.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.lucene.queryParser.MultiFieldQueryParser
的用法示例。
在下文中一共展示了MultiFieldQueryParser.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: searchIndex
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
/**
* 查詢索引
*
* @param keywords
* @return
* @throws Exception
*/
public List<Document> searchIndex(Integer typeId, String keywords) throws Exception {
// 1.init searcher
Analyzer analyzer = new PaodingAnalyzer();
IndexReader reader = IndexReader.open(typeId == appConfig.getGameTypeId() ? appConfig.getGameIndexDir()
: appConfig.getSoftIndexDir());
BooleanClause.Occur[] flags = new BooleanClause.Occur[] { BooleanClause.Occur.SHOULD,
BooleanClause.Occur.SHOULD };
Query query = MultiFieldQueryParser.parse(keywords, appConfig.getQueryFields(), flags, analyzer);
query = query.rewrite(reader);
// 2.search
List<Document> docs = new ArrayList<Document>();
Hits hits = (typeId == appConfig.getGameTypeId() ? gameSearcher.search(query, Sort.RELEVANCE) : softSearcher
.search(query, Sort.RELEVANCE));// searcher.search(query,
// Sort.RELEVANCE);
for (int i = 0; i < hits.length(); i++) {
docs.add(hits.doc(i));
}
// 3.return
reader.close();
return docs;
}
示例2: search
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
public List<Document> search (String queryString, SearchScope luceneFields) throws Exception {
// using stop analyzer in search
Analyzer analyzer = new StopAnalyzer(Version.LUCENE_30, new File(ApplicationConstants.STOP_WORD_FILE));
String[] fields = getSupportedFileds(luceneFields);
MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_30, fields, analyzer);
// scpaing special characters
queryString = QueryParser.escape(queryString);
Query query = parser.parse(queryString);
TopDocs topDocs = searcher.search(query, MAX_RESULT);
List<Document> documents = new ArrayList<Document>();
for(ScoreDoc scoreDocs: topDocs.scoreDocs) {
Document document = searcher.doc(scoreDocs.doc);
documents.add(document);
}
return documents;
}
示例3: skynetsearch
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
public Hits skynetsearch(String query, String Field, String indexPath) {
String indexfield = Field + ":";
String querytext = indexfield + query.trim();
Hits result = null;
try {
String[] search_fields = {Field};
//String indexPath = StorageHandler.GetDocIndexPath();
IndexSearcher searcher = new IndexSearcher(indexPath);
KeywordAnalyzer analyzer = new KeywordAnalyzer();
Query lucenequery = MultiFieldQueryParser.parse(query,
search_fields, analyzer);
// QueryParser queryparse = new QueryParser(query,analyzer);
// Query lucenequery = queryparse.parse(querytext);
result = searcher.search(lucenequery);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception ex) {
System.out.println(ex + "");
}
return result;
}
示例4: skynetsearchMulti
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
public Hits skynetsearchMulti(String query, String[] Field, String indexPath) {
Hits result = null;
try {
IndexSearcher searcher = new IndexSearcher(indexPath);
KeywordAnalyzer analyzer = new KeywordAnalyzer();
MultiFieldQueryParser multiparser = new MultiFieldQueryParser(Field, analyzer);
multiparser.setDefaultOperator(QueryParser.Operator.OR);
Query lucenequery = multiparser.parse(query);
result = searcher.search(lucenequery);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception ex) {
System.out.println(ex + "");
}
return result;
}
示例5: createFullTextQuery
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
private org.apache.lucene.search.Query createFullTextQuery(final String[] searchFields, final QueryFilter queryFilter,
final String searchString)
{
final MultiFieldQueryParser parser = new MultiFieldQueryParser(LUCENE_VERSION, searchFields, new ClassicAnalyzer(Version.LUCENE_31));
parser.setAllowLeadingWildcard(true);
org.apache.lucene.search.Query query = null;
try {
query = parser.parse(searchString);
} catch (final org.apache.lucene.queryParser.ParseException ex) {
final String errorMsg = "Lucene error message: "
+ ex.getMessage()
+ " (for "
+ this.getClass().getSimpleName()
+ ": "
+ searchString
+ ").";
if (queryFilter != null) {
queryFilter.setErrorMessage(errorMsg);
}
log.info(errorMsg);
return null;
}
return query;
}
示例6: search
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
public Hits search(String type, String qstr)
{
String queryStr = "(" + qstr + ") OR ("+TStransformer.STtransform(qstr)+")";
Hits hits = null;
try{
FSDirectory fsd = FSDirectory.getDirectory(QuickSearchConfig.getIndexDir() + "/" + type);
//RAMDirectory ramd = new RAMDirectory(QuickSearchConfig.getIndexDir() + "/" + type);
IndexSearcher indexSearcher = new IndexSearcher(fsd);
Query query = MultiFieldQueryParser.parse(queryStr, fields, flags, analyzer);
hits = indexSearcher.search(query);
}catch(Exception ex){
ex.printStackTrace();
}
return hits;
}
示例7: testSpecifiedOperator
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
public void testSpecifiedOperator() throws Exception {
Query query = MultiFieldQueryParser.parse(Version.LUCENE_41,
"lucene",
new String[]{"title", "subject"},
new BooleanClause.Occur[]{BooleanClause.Occur.MUST,
BooleanClause.Occur.MUST},
new SimpleAnalyzer());
Directory dir = TestUtil.getBookIndexDirectory();
IndexSearcher searcher = new IndexSearcher(
dir,
true);
TopDocs hits = searcher.search(query, 10);
assertTrue(TestUtil.hitsIncludeTitle(
searcher,
hits,
"Lucene in Action, Second Edition"));
assertEquals("one and only one", 1, hits.scoreDocs.length);
searcher.close();
dir.close();
}
示例8: search
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@DataProvider
public List<SearchResult> search(String searchText) throws Exception {
FullTextSession fullTextSession = Search.getFullTextSession(exampleDao
.getSession());
if (!indexRebuilded) {
indexRebuilded = true;
fullTextSession.createIndexer().startAndWait();
}
MultiFieldQueryParser parser = new MultiFieldQueryParser(
Version.LUCENE_31, new String[] { "label", "tags", "url",
"summary" }, new StandardAnalyzer(Version.LUCENE_31));
org.apache.lucene.search.Query luceneQuery = parser.parse(searchText);
FullTextQuery query = fullTextSession.createFullTextQuery(luceneQuery,
Example.class);
query.setFirstResult(0);
query.setMaxResults(100);
List<SearchResult> searchResults = new ArrayList<SearchResult>();
for (Example example : (List<Example>) query.list()) {
SearchResult searchResult = new SearchResult();
PropertyUtils.copyProperties(searchResult, example);
searchResults.add(searchResult);
}
return searchResults;
}
示例9: findByKeywords
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public List<User> findByKeywords(String keywords, SearchType searchType) {
MultiFieldQueryParser parser = new MultiFieldQueryParser(
Version.LUCENE_31,
new String[] { "names", USERNAME_FIELD, EMAIL_FIELD },
new StandardAnalyzer(Version.LUCENE_31));
keywords = escapeKeywords(keywords);
if (searchType == SearchType.START) {
keywords += "*";
}
if (searchType == SearchType.FUZZY) {
keywords += "~";
}
if (searchType == SearchType.FULL) {
String[] parts = keywords.split(" ");
StringBuilder sb = new StringBuilder();
for (String part : parts) {
sb.append(part + "* ");
}
keywords = sb.toString();
}
Query query;
try {
query = parser.parse(keywords);
} catch (ParseException e) {
log.warn("Problem parsing query", e);
return Collections.emptyList();
}
FullTextQuery ftq = getFullTextEntityManager().createFullTextQuery(
query, User.class);
ftq.setMaxResults(commonPageSize);
return ftq.getResultList();
}
示例10: parse
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
public static Query parse(String[] fields, Occur[] occurs, String value){
Query query = null;
try{
query = MultiFieldQueryParser.parse(BuguIndex.getInstance().getVersion(), value, fields, occurs, BuguIndex.getInstance().getAnalyzer());
}catch(ParseException ex){
logger.error("MultiFieldQueryParser can not parse the value " + value , ex);
}
return query;
}
示例11: multiFieldSearch
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
public TopScoreDocCollector multiFieldSearch(String[] queryStrings, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer, int lucHits){
escapeStrings(queryStrings);
Query query = null;
try {
query = MultiFieldQueryParser.parse(Version.LUCENE_36, queryStrings, fields, flags, analyzer);
} catch (ParseException e) {
e.printStackTrace();
}
return search(query, lucHits);
}
示例12: getQuery
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
protected Query getQuery()
{
String[] strs = queryword.split("AND");
ArrayList words = new ArrayList();
for(int i=0; i<strs.length; i++)
if(!strs[i].trim().equalsIgnoreCase(""))
{
String english="";
try {
english =remoteTranslation.Sentence("ce", strs[i].trim());
}catch (RemoteException reExc) {
LOG.warn("remote exception:"+StackTraceUtil.getStackTrace(reExc));
}
words.add(strs[i].trim() + " " + english);
}
String queryStr = null;
if(words.size()<1)
return null;
else
{
queryStr = "(" + (String)words.get(0) + ")";
for(int i=1; i<words.size(); i++)
queryStr += " AND " + "(" + (String)words.get(i) + ")";
}
Analyzer analyzer = new ChineseAnalyzer();
Query query = null;
try
{
query = MultiFieldQueryParser.parse(queryStr, fields, flags, analyzer);
}
catch(Exception ex){
ex.printStackTrace();
}
return query;
}
示例13: getQuery
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
protected Query getQuery()
{
String[] strs = queryword.split("AND");
ArrayList words = new ArrayList();
for(int i=0; i<strs.length; i++)
if(!strs[i].trim().equalsIgnoreCase(""))
{
//LOG.warn("re search:" + strs[i].trim());
words.add(strs[i].trim() + " " + TStransformer.STtransform(strs[i].trim()));
}
String queryStr = null;
if(words.size()<1)
return null;
else
{
queryStr = "(" + (String)words.get(0) + ")";
for(int i=1; i<words.size(); i++)
queryStr += " AND " + "(" + (String)words.get(i) + ")";
}
Analyzer analyzer = new ChineseAnalyzer();
Query query = null;
try
{
query = MultiFieldQueryParser.parse(queryStr, fields, flags, analyzer);
}
catch(Exception ex){
ex.printStackTrace();
}
return query;
}
示例14: getQuery
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
protected Query getQuery()
{
String[] strs = queryword.split("AND");
ArrayList words = new ArrayList();
for(int i=0; i<strs.length; i++)
if(!strs[i].trim().equalsIgnoreCase(""))
{
String english="";
try {
english =remoteTranslation.Sentence("ce", strs[i].trim());
}catch (RemoteException reExc) {
LOG.warn("remote exception:"+StackTraceUtil.getStackTrace(reExc));
}
words.add(strs[i].trim() + " " + english);
}
String queryStr = null;
if(words.size()<1)
return null;
else
{
queryStr = "(" + (String)words.get(0) + ")";
for(int i=1; i<words.size(); i++)
queryStr += " AND " + "(" + (String)words.get(i) + ")";
}
Analyzer analyzer = new ChineseAnalyzer();
Query query = null;
try
{
query = MultiFieldQueryParser.parse(Version.LUCENE_35, queryStr, fields, flags, analyzer);
}
catch(Exception ex){
ex.printStackTrace();
}
return query;
}
示例15: getQuery
import org.apache.lucene.queryParser.MultiFieldQueryParser; //導入方法依賴的package包/類
/**
* GetQuery Function
*/
protected Query getQuery()
{
String[] strs = queryword.split("AND");
ArrayList words = new ArrayList();
for(int i=0; i<strs.length; i++)
if(!strs[i].trim().equalsIgnoreCase(""))
{
words.add(strs[i].trim() + " " + TStransformer.STtransform(strs[i].trim()));
}
String queryStr = null;
if(words.size()<1)
return null;
else
{
queryStr = "(" + (String)words.get(0) + ")";
for(int i=1; i<words.size(); i++)
queryStr += " AND " + "(" + (String)words.get(i) + ")";
}
Analyzer analyzer = new ChineseAnalyzer();
Query query = null;
try
{
query = MultiFieldQueryParser.parse(Version.LUCENE_35, queryStr, fields, flags, analyzer);
}
catch(Exception ex){
ex.printStackTrace();
}
return query;
}