当前位置: 首页>>代码示例>>Java>>正文


Java QueryParser.parse方法代码示例

本文整理汇总了Java中org.apache.lucene.queryparser.classic.QueryParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java QueryParser.parse方法的具体用法?Java QueryParser.parse怎么用?Java QueryParser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.queryparser.classic.QueryParser的用法示例。


在下文中一共展示了QueryParser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteIndexesByField

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
@Override
public void deleteIndexesByField(String field) {
    if (!isNullOrEmpty(field)) {
        try {
            Query query;
            QueryParser parser = new QueryParser(Version.LUCENE_4_9, field, analyzer);
            parser.setAllowLeadingWildcard(true);
            try {
                query = parser.parse("*");
            } catch (ParseException e) {
                throw new IndexingException(errorMessage(
                        "could not remove full-text index for value " + field, 0));
            }

            synchronized (this) {
                indexWriter.deleteDocuments(query);
                commit();
            }
        } catch (IOException ioe) {
            throw new IndexingException(errorMessage(
                    "could not remove full-text index for value " + field, 0));
        } catch (VirtualMachineError vme) {
            handleVirtualMachineError(vme);
        }
    }
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:27,代码来源:LuceneService.java

示例2: main

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	IndexReader reader = DirectoryReader.open(FSDirectory.open(Paths.get(INDEX_DIRECTORY)));
	IndexSearcher indexSearcher = new IndexSearcher(reader);

	Analyzer analyzer = new StandardAnalyzer();
	QueryParser queryParser = new QueryParser(FIELD_CONTENTS, analyzer);
	String searchString = "shakespeare";
	Query query = queryParser.parse(searchString);

	TopDocs results = indexSearcher.search(query, 5);
	ScoreDoc[] hits = results.scoreDocs;

	int numTotalHits = results.totalHits;
	System.out.println(numTotalHits + " total matching documents");

	for(int i=0;i<hits.length;++i) {
		int docId = hits[i].doc;
		Document d = indexSearcher.doc(docId);
		System.out.println((i + 1) + ". " + d.get("path") + " score=" + hits[i].score);
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:22,代码来源:SearchFiles.java

示例3: search

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
public SearchResult search(String index, String queryString, int page) {
    SearchResult searchResult = null;

    try {
        IndexReader reader = DirectoryReader.open(FSDirectory.open(Paths.get(Properties.getProperties().getProperty(Values.INDEX_LOCATION, Values.DEFAULT_INDEX_LOCATION))));
        IndexSearcher searcher = new IndexSearcher(reader);
        Analyzer analyzer = new StandardAnalyzer();

        // Search over the titles only for the moment
        QueryParser parser = new QueryParser(index, analyzer);
        Query query = parser.parse(queryString);

        searchResult = this.doPagingSearch(reader, searcher, query, queryString, page);
        reader.close();
    }
    catch(Exception ex) {}

    return searchResult;
}
 
开发者ID:boyter,项目名称:freemoz,代码行数:20,代码来源:Searcher.java

示例4: synTokenQuery

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
private void synTokenQuery(String search, final int numbOfResults, final double minLuceneScore,
		Map<String, Float> result, IndexSearcher searcher) throws ParseException, IOException {

	QueryParser parser = new QueryParser(Version.LUCENE_46, "surfaceFormTokens",
			new StandardAnalyzer(Version.LUCENE_46));

	search = QueryParser.escape(search);

	Query q = parser.parse(search);
	/*
	 * Works only in String field!!
	 */
	// Query q = new FuzzyQuery(new Term("surfaceFormTokens",
	// QueryParser.escape(search)), 2);

	TopDocs top = searcher.search(q, numbOfResults);

	for (ScoreDoc doc : top.scoreDocs) {
		if (doc.score >= minLuceneScore) {
			final String key = searcher.doc(doc.doc).get("conceptID");
			if (result.getOrDefault(key, 0f) < doc.score) {
				result.put(key, doc.score);
			}
		}
	}
}
 
开发者ID:ag-sc,项目名称:JLink,代码行数:27,代码来源:LuceneRetrieval.java

示例5: Search

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
/**
 * 查询方法
 * @throws IOException 
 * @throws CorruptIndexException 
 * @throws ParseException 
 */
public List Search(String searchString,LuceneResultCollector luceneResultCollector) throws CorruptIndexException, IOException, ParseException{
	//方法一:
	
	System.out.println(this.indexSettings.getAnalyzer().getClass()+"----分词选择");
	QueryParser q = new QueryParser(Version.LUCENE_44, "summary", this.indexSettings.getAnalyzer());
	String search = new String(searchString.getBytes("ISO-8859-1"),"UTF-8"); 
	System.out.println(search+"----------搜索的词语dd");
	Query query = q.parse(search);
	//方法二:
	/*
	Term t = new Term("title", searchString);
	TermQuery query = new TermQuery(t);
	*/
	System.out.println(query.toString()+"--------query.tostring");
	ScoreDoc[] docs = this.indexSearcher.search(query,100).scoreDocs;
	System.out.println("一共有:"+docs.length+"条记录");
	List result = luceneResultCollector.collect(docs, this.indexSearcher);
	return result;
}
 
开发者ID:zhangjikai,项目名称:sdudoc,代码行数:26,代码来源:LuceneIndexSearch.java

示例6: getQuery

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  String text = DOMUtils.getText(e);
  try {
    Query q = null;
    if (unSafeParser != null) {
      //synchronize on unsafe parser
      synchronized (unSafeParser) {
        q = unSafeParser.parse(text);
      }
    } else {
      String fieldName = DOMUtils.getAttribute(e, "fieldName", defaultField);
      //Create new parser
      QueryParser parser = createQueryParser(fieldName, analyzer);
      q = parser.parse(text);
    }
    q.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
    return q;
  } catch (ParseException e1) {
    throw new ParserException(e1.getMessage());
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:UserInputQueryBuilder.java

示例7: query

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
/**
 * Returns the Lucene {@link Query} represented by the specified
 * {@link Search} and key filter.
 *
 * @param expression
 *            the expression
 * @param command
 *            the command
 * @return a Lucene {@link Query}
 */
private Query query(String expression, ReadCommand command) {
	try {
		QueryParser queryParser = new QueryParser("query", this.indexOptions.search.defaultAnalyzer);
		queryParser.setDateResolution(Resolution.SECOND);
		Query searchQuery = queryParser.parse(expression);
		
		return searchQuery;
	} catch (ParseException e) {
		// TODO Auto-generated catch block
		throw new FhirIndexException(e);
	}

	// TODO: mejorar las busquedas por tipo
	// Optional<Query> maybeKeyRangeQuery = query(command);
	// if (maybeKeyRangeQuery.isPresent()) {
	// BooleanQuery.Builder builder = new BooleanQuery.Builder();
	// builder.add(maybeKeyRangeQuery.get(), FILTER);
	// builder.add(searchQuery, MUST);
	// return builder.build();
	// } else {
	// }
}
 
开发者ID:jmiddleton,项目名称:cassandra-fhir-index,代码行数:33,代码来源:FhirIndexService.java

示例8: queryIndex

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
public static LuceneSearchResult queryIndex(String keyword, int offset, int pagesize){
	// 查询
	List<Query> querys = new ArrayList<>();
	if (keyword!=null && keyword.trim().length()>0) {
		try {
			//Analyzer analyzer = new SmartChineseAnalyzer();
			Analyzer analyzer = new IKAnalyzer();
			QueryParser parser = new QueryParser(ExcelUtil.KEYWORDS, analyzer);
			Query shopNameQuery = parser.parse(keyword);
			querys.add(shopNameQuery);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	LuceneSearchResult result = search(querys, offset, pagesize);
	return result;
}
 
开发者ID:xuxueli,项目名称:xxl-search,代码行数:18,代码来源:LuceneUtil.java

示例9: getExplicitFieldQuery

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
/**
 * Gets the lucene query for explicit lookup field
 * @param analyzer
 * @param fieldName
 * @param fieldValue
 * @param fieldID
 * @param locale
 * @return
 */
@Override
protected Query getExplicitFieldQuery(Analyzer analyzer,
		String fieldName, String fieldValue, Integer fieldID, Locale locale) {
	Query query= null;
	QueryParser queryParser = new QueryParser(fieldName, analyzer);
	//adds the type criteria
	String externalFieldQueryString = fieldValue + 
		" AND " + LuceneUtil.EXTERNAL_INDEX_FIELDS.FIELDID + 
		LuceneSearcher.FIELD_NAME_VALUE_SEPARATOR + fieldID;
	try {
		query = queryParser.parse(externalFieldQueryString);
	} catch (ParseException e) {
		LOGGER.error("Parsing the external lookups query string fieldName " + fieldName + " fieldValue '" + fieldValue + "' failed with " + e.getMessage());
		LOGGER.debug(ExceptionUtils.getStackTrace(e));
	}
	return query;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:27,代码来源:ExternalListSearcher.java

示例10: getNoExplicitFieldQuery

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
/**
 * Preprocess the toBeProcessedString when no field is specified
 * @param analyzer
 * @param toBeProcessedString
 * @param locale
 * @return
 */
@Override
public Query getNoExplicitFieldQuery(Analyzer analyzer, String toBeProcessedString, Locale locale) {
	Query query = null;
	String queryString = searchNoExplicitField(analyzer, toBeProcessedString, locale);
	if (queryString!=null && queryString.trim().length()>0) {
		QueryParser queryParser = new QueryParser(LuceneUtil.getFieldName(SystemFields.ISSUENO), analyzer);
		LOGGER.debug("List matches found for no explicit field " + queryString);
		try {
			query = queryParser.parse(queryString);
		} catch (ParseException e) {
			LOGGER.warn("Parsing without explicit field for " + queryParser + " field failed with " + e.getMessage());
			LOGGER.debug(ExceptionUtils.getStackTrace(e));
		}
	}
	return query;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:24,代码来源:AbstractListFieldSearcher.java

示例11: getNoExlplicitFieldQuery

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
/**
 * Gets the lucene query when no field is specified,
 * that means search the entire localized index by label, default localized or locale 
 * @param analyzer
 * @param toBeProcessedString
 * @param fieldID
 * @param locale
 * @return
 */
@Override
protected Query getNoExlplicitFieldQuery(Analyzer analyzer,
		String toBeProcessedString, Locale locale) {
	QueryParser queryParser = new QueryParser(getLabelFieldName(), analyzer);
	Query query = null;
	try {
		//search for both localized and not localized value
		query = queryParser.parse(getLabelFieldName()+ LuceneSearcher.FIELD_NAME_VALUE_SEPARATOR + toBeProcessedString +
				" OR " + locale.toString() + LuceneSearcher.FIELD_NAME_VALUE_SEPARATOR + toBeProcessedString +
				" OR " + LuceneUtil.LIST_INDEX_FIELDS_LOCALIZED.DEFAULT_LOCALIZED + LuceneSearcher.FIELD_NAME_VALUE_SEPARATOR + toBeProcessedString);
	} catch (ParseException e) {
		LOGGER.error("Parsing the no field query string for fieldValue '" + toBeProcessedString + "' failed with " + e.getMessage());
		LOGGER.debug(ExceptionUtils.getStackTrace(e));
	}
	return query;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:26,代码来源:LocalizedListSearcher.java

示例12: getNoExplicitFieldQuery

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
/**
 * Preprocess the toBeProcessedString when no field is specified
 * @param analyzer
 * @param toBeProcessedString
 * @param locale
 * @return
 */
@Override
public Query getNoExplicitFieldQuery(Analyzer analyzer, String toBeProcessedString, Locale locale) {
	Query query = null;
	String workItemsFound = searchNoExplicitField(analyzer, toBeProcessedString, locale);
	if (workItemsFound!=null && !workItemsFound.equals(toBeProcessedString)) {
		QueryParser queryParser = new QueryParser(LuceneUtil.getFieldName(SystemFields.ISSUENO), analyzer);
		String queryString = LuceneUtil.getFieldName(SystemFields.ISSUENO) +
				LuceneSearcher.FIELD_NAME_VALUE_SEPARATOR + workItemsFound;
		LOGGER.debug(getLuceneFieldName() + " workItems found : " + workItemsFound);
		try {
			query = queryParser.parse(queryString);
		} catch (ParseException e) {
			LOGGER.warn("Parsing without explicit field the " + getLuceneFieldName() +  "  for " + queryString + " field failed with " + e.getMessage());
			LOGGER.debug(ExceptionUtils.getStackTrace(e));
		}
	}
	return query;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:26,代码来源:AbstractAssociatedFieldSearcher.java

示例13: _fullTextQueryClauseFor

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
@SuppressWarnings("resource")
private Query _fullTextQueryClauseFor(final IndexDocumentFieldID fieldId,
									  final String text) {
	IndexDocumentFieldConfig<?> fieldCfg = _fieldsConfigSet.getConfigFor(fieldId);
	Analyzer analyzer = fieldCfg.isLanguageDependent() ? new LuceneLanguageDependentAnalyzer(_fieldsConfigSet)	// language dependant analyzer
												   	   : new StandardAnalyzer(LuceneConstants.VERSION);			// StandardAnalyzer!!! 
	Query outQry = null;
	QueryParser qp = new QueryParser(LuceneConstants.VERSION,
									 fieldId.asString(),
									 analyzer);	
	try {
		String luceneTextQry = Strings.customized("{}:{}",
												  fieldId.asString(),text);
		outQry = qp.parse(luceneTextQry);
	} catch(ParseException parseEx) {
		log.error("Error parsing the term text search filter: {}",parseEx.getMessage(),
																  parseEx);
	}
	return outQry;
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:21,代码来源:LuceneSearchQuery.java

示例14: query

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
Query query( String keyOrNull, Object value, QueryContext contextOrNull )
{
    if ( value instanceof Query )
    {
        return (Query) value;
    }

    QueryParser parser = new QueryParser( keyOrNull, analyzer );
    parser.setAllowLeadingWildcard( true );
    parser.setLowercaseExpandedTerms( toLowerCase );
    if ( contextOrNull != null && contextOrNull.getDefaultOperator() != null )
    {
        parser.setDefaultOperator( contextOrNull.getDefaultOperator() );
    }
    try
    {
        return parser.parse( value.toString() );
    }
    catch ( ParseException e )
    {
        throw new RuntimeException( e );
    }
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:24,代码来源:IndexType.java

示例15: getNoFieldQuerySearchableField

import org.apache.lucene.queryparser.classic.QueryParser; //导入方法依赖的package包/类
/**
 * Gets the lucene query when no field is specified 
 * @param analyzer
 * @param toBeProcessedString
 * @param fieldID
 * @param locale
 * @return
 */
protected Query getNoFieldQuerySearchableField(Analyzer analyzer,
		String toBeProcessedString, Integer fieldID, Locale locale) {
	BooleanQuery booleanQuery = new BooleanQuery();
	IExternalLookupLucene externalLookupField = (IExternalLookupLucene)FieldTypeManager.getFieldTypeRT(fieldID);
	String[] searchableFields = externalLookupField.getSearchableFieldNames();
	if (searchableFields!=null && searchableFields.length>0) {
		for (String searchableField : searchableFields) {
			QueryParser queryParser = new QueryParser(searchableField, analyzer);
			Query externalLookupFieldQuery = null;
			String externalFieldQueryString = toBeProcessedString + 
					" AND " + LuceneUtil.EXTERNAL_INDEX_FIELDS.FIELDID + 
					LuceneSearcher.FIELD_NAME_VALUE_SEPARATOR + fieldID;
			try {
				externalLookupFieldQuery = queryParser.parse(toBeProcessedString);
				booleanQuery.add(externalLookupFieldQuery, BooleanClause.Occur.SHOULD);
			} catch (ParseException e) {
				LOGGER.error("Parsing the external lookups query string for fieldValue '" + externalFieldQueryString + "' failed with " + e.getMessage());
				LOGGER.debug(ExceptionUtils.getStackTrace(e));
			}
		}
	}
	return booleanQuery;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:32,代码来源:ExternalListSearcher.java


注:本文中的org.apache.lucene.queryparser.classic.QueryParser.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。