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


Java ParseException类代码示例

本文整理汇总了Java中org.apache.lucene.queryParser.ParseException的典型用法代码示例。如果您正苦于以下问题:Java ParseException类的具体用法?Java ParseException怎么用?Java ParseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getFieldQuery

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
/**
 *  Gets the fieldQuery attribute of the FieldExpansionQueryParser object
 *
 * @param  field               The field being processed
 * @param  queryText           The text in the field
 * @return                     The fieldQuery value
 * @exception  ParseException  If error
 */
protected Query getFieldQuery(String field, String queryText)
	 throws ParseException {

	// prtln("getFieldQuery( field: '" + field + "', queryText: '" + queryText + "'");

	// If a VirtualSearchFieldMapper is available and has a mapping for this field, use it:
	if (virtualSearchFieldMapper != null) {
		Query q = virtualSearchFieldMapper.getQuery(field, queryText);
		if (q != null)
			return q;
	}

	// Extract and store the terms in the default field once only - used for boosting
	if (field.equals(expansionFields[0])) {
		String[] tmp = queryText.split("\\s+");
		for (int i = 0; i < tmp.length; i++)
			terms.add(tmp[i]);
	}

	// Then perform the normal field query
	return super.getFieldQuery(field, queryText);
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:31,代码来源:FieldExpansionQueryParser.java

示例2: getDefaultOperator

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
public Operator getDefaultOperator() throws ParseException
{
	Operator o;

	if( this.defaultOperator.equalsIgnoreCase("and") )
	{
		o = Operator.AND;
	}
	else if( this.defaultOperator.equalsIgnoreCase("OR") )
	{
		o = Operator.OR;
	}
	else
	{
		throw new ParseException("Invalid Default Operator (AND/OR)");
	}

	return o;
}
 
开发者ID:equella,项目名称:Equella,代码行数:20,代码来源:ItemIndex.java

示例3: processArgument

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
@Override
protected boolean processArgument(String arg) throws CLIOException {
	try {
		Analyzer analyzer = PubMedIndexUtils.getGlobalAnalyzer();
		QueryParser parser = new QueryParser(PubMedIndexUtils.LUCENE_VERSION, PubMedIndexField.ABSTRACT.fieldName, analyzer);
		parser.setDefaultOperator(QueryParser.AND_OPERATOR);
		parser.setLowercaseExpandedTerms(false);
		PubMedIndexUtils.log("parsing query: %s", arg);
		Query q = parser.parse(arg);
		PubMedIndexUtils.log("query: %s", q);
		addClause(q);
		return false;
	}
	catch (ParseException e) {
		throw new CLIOException(e);
	}
}
 
开发者ID:Bibliome,项目名称:bibliome-java-utils,代码行数:18,代码来源:PubMedIndexSearcher.java

示例4: search

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
public Map<String, Integer> search(String word, String field, int maxSearch) {
    if (indexSearcher == null) {
        initialize(index);
    }
    Map<String, Integer> verbFreqs = new HashMap<>();
    QueryParser queryParser = new QueryParser(Version.LUCENE_36, field, analyzer);
    try {
        Query query = queryParser.parse(word);
        TopDocs topDocs = indexSearcher.search(query, maxSearch);
        ScoreDoc[] doc = topDocs.scoreDocs;
        for (int i = 0; i < maxSearch && i < doc.length; ++i) {
            int documentId = doc[i].doc;
            Document document = indexSearcher.doc(documentId);
            String verb = document.get(VERB);
            String frequency = document.get(FREQ);
            verbFreqs.put(verb, Integer.parseInt(frequency));
        }
    } catch (ParseException | IOException e) {
        log.warn("Error searching Lucene index.", e);
    }
    return verbFreqs;
}
 
开发者ID:clearwsd,项目名称:clearwsd,代码行数:23,代码来源:LuceneWrapper.java

示例5: select

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
/**
  * Executes a select query.
  * @param query The Lucene query
  * @return An array of record IDs; an empty array if an error occured
* @throws IOException 
  */
 public int[] select(String query, String sortPrefix)  throws ParseException{
   try {
     WhitespaceAnalyzer sa= new WhitespaceAnalyzer();
     BooleanQuery.setMaxClauseCount(20000);//zbog heap-a
     QueryParser p = new QueryParser("KW", sa);
     p.setDefaultOperator(QueryParser.Operator.AND); //default operator je AND a ne OR kao sto je inace inicijalno
     Query q = p.parse(query);
     return select(q, sortPrefix);
   } catch (Exception ex) {
   	if (ex instanceof ParseException )
   		throw (ParseException)ex;
     log.warn(ex);
     return new int[0];
   }
 }
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:22,代码来源:Retriever.java

示例6: search

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
/**
 * Search in documents
 */
private static void search(Directory index, Analyzer analyzer, String str) throws ParseException, CorruptIndexException,
		IOException {
	IndexReader reader = IndexReader.open(index);
	IndexSearcher searcher = new IndexSearcher(reader);
	TopScoreDocCollector collector = TopScoreDocCollector.create(NUM_HITS, true);
	//Query q = new QueryParser(Config.LUCENE_VERSION, DOC_FIELD, analyzer).parse(str);
	Query q = new WildcardQuery(new Term(DOC_FIELD, str));
	System.out.println("Query: " + q);

	searcher.search(q, collector);
	ScoreDoc[] hits = collector.topDocs().scoreDocs;

	System.out.println("Found " + hits.length + " hits.");

	for (int i = 0; i < hits.length; ++i) {
		int docId = hits[i].doc;
		Document d = searcher.doc(docId);
		System.out.println((i + 1) + ". " + d.get(DOC_FIELD));
	}

	searcher.close();
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:26,代码来源:SearchDemo.java

示例7: makeQueryFromKeywords

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
public Query makeQueryFromKeywords(List<WeightString> keywords, int n)
throws ParseException {
  StringBuilder queryString = new StringBuilder();
  for (int i = 0; i < n && i < keywords.size(); i++) {
    if (i > 0)
      queryString.append(' ');
    queryString.append(keywords.get(i).text);
    queryString.append('^');
    queryString.append(String.format("%.2f",
        Math.log(keywords.get(i).weight + 1)));
  }
  if (queryString.length() == 0)
    queryString.append("a");
  Query q = queryParser.parse(queryString.toString());
  return q;
}
 
开发者ID:thunlp,项目名称:THUTag,代码行数:17,代码来源:KnnTagSuggest.java

示例8: makeQueryFromKeywords

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
public Query makeQueryFromKeywords(List<WeightString> keywords, int n)
		throws ParseException {
	StringBuilder queryString = new StringBuilder();
	for (int i = 0; i < n && i < keywords.size(); i++) {
		if (i > 0)
			queryString.append(' ');
		queryString.append(keywords.get(i).text);
		queryString.append('^');
		queryString.append(String.format("%.2f", Math
				.log(keywords.get(i).weight + 1)));
	}
	if (queryString.length() == 0)
		queryString.append("a");
	Query q = queryParser.parse(queryString.toString());
	return q;
}
 
开发者ID:thunlp,项目名称:THUTag,代码行数:17,代码来源:ExpandRankKE.java

示例9: search

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
public static void search(String indexDir, String q)
	throws IOException, ParseException {
	
	Directory dir = FSDirectory.open(new File(indexDir));
	IndexSearcher is = new IndexSearcher(dir);
	
	QueryParser parser = new QueryParser(Version.LUCENE_30, "contents", 
			new StandardAnalyzer(Version.LUCENE_30));
	Query query = parser.parse(q);
	
	long start = System.currentTimeMillis();
	TopDocs hits = is.search(query, 10);
	long end = System.currentTimeMillis();
	
	System.out.println(" document(s) (in " + (end - start) + " milliseconds) that matched query '" +
				q + "':" + ("Found " + hits.totalHits));
	
	for(ScoreDoc scoreDoc : hits.scoreDocs) {
		Document doc = is.doc(scoreDoc.doc);
		System.out.println(doc.get("fullpath"));
	}
	
	is.close();
}
 
开发者ID:tensorchen,项目名称:rrs,代码行数:25,代码来源:Searcher.java

示例10: jj_consume_token

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
private Token jj_consume_token(int kind) throws ParseException {
	Token oldToken;
	if ((oldToken = token).next != null)
		token = token.next;
	else
		token = token.next = token_source.getNextToken();
	jj_ntk = -1;
	if (token.kind == kind) {
		jj_gen++;
		if (++jj_gc > 100) {
			jj_gc = 0;
			for (int i = 0; i < jj_2_rtns.length; i++) {
				JJCalls c = jj_2_rtns[i];
				while (c != null) {
					if (c.gen < jj_gen)
						c.first = null;
					c = c.next;
				}
			}
		}
		return token;
	}
	token = oldToken;
	jj_kind = kind;
	throw generateParseException();
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:27,代码来源:QueryParser.java

示例11: listVertices

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
public List<Integer> listVertices(String expression) {
    try {
        List<Integer> results = new ArrayList<>();
        IndexReader reader = IndexReader.open(vertexIndex);
        IndexSearcher searcher = new IndexSearcher(reader);
        ScoreDoc[] hits = searcher.search(queryParser.parse(expression), MAX_QUERY_HITS).scoreDocs;

        for (int i = 0; i < hits.length; ++i) {
            int docId = hits[i].doc;
            Document foundDoc = searcher.doc(docId);
            results.add(Integer.parseInt(foundDoc.get(ID_STRING)));
        }

        searcher.close();
        reader.close();
        return results;
    } catch (IOException | ParseException | NumberFormatException exception) {
        logger.log(Level.WARNING, "Error while listing vertices. Returning empty array.", exception);
        return new ArrayList<>();
    }
}
 
开发者ID:ashish-gehani,项目名称:SPADE,代码行数:22,代码来源:Graph.java

示例12: createIndex

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
@Transactional(readOnly = true)
public Integer createIndex(Integer siteId, Integer channelId,
		Date startDate, Date endDate, Integer startId, Integer max,
		Directory dir) throws IOException, ParseException {
	boolean exist = IndexReader.indexExists(dir);
	IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(
			Version.LUCENE_30), !exist, IndexWriter.MaxFieldLength.LIMITED);
	try {
		if (exist) {
			LuceneContent.delete(siteId, channelId, startDate, endDate,
					writer);
		}
		Integer lastId = luceneContentDao.index(writer, siteId, channelId,
				startDate, endDate, startId, max);
		writer.optimize();
		return lastId;
	} finally {
		writer.close();
	}
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:21,代码来源:LuceneContentSvcImpl.java

示例13: searchPage

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
@Transactional(readOnly = true)
public Pagination searchPage(Directory dir, String queryString,String category,String workplace,
		Integer siteId, Integer channelId, Date startDate, Date endDate,
		int pageNo, int pageSize) throws CorruptIndexException,
		IOException, ParseException {
	Searcher searcher = new IndexSearcher(dir);
	try {
		Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
		Query query = LuceneContent.createQuery(queryString,category,workplace, siteId,
				channelId, startDate, endDate, analyzer);
		TopDocs docs = searcher.search(query, pageNo * pageSize);
		Pagination p = LuceneContent.getResultPage(searcher, docs, pageNo,
				pageSize);
		List<?> ids = p.getList();
		List<Content> contents = new ArrayList<Content>(ids.size());
		for (Object id : ids) {
			contents.add(contentMng.findById((Integer) id));
		}
		p.setList(contents);
		return p;
	} finally {
		searcher.close();
	}
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:25,代码来源:LuceneContentSvcImpl.java

示例14: buildFilter

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
@org.hibernate.search.annotations.Factory
public Filter buildFilter(){
	QueryParser qp = new QueryParser(Version.LUCENE_CURRENT,field, analyzer);
	Query q;
	try {
		if(allowLuceneSyntax)
			q = qp.parse(value);
		else
			q = qp.parse(QueryParser.escape(value));
	} catch (ParseException e) {
		org.webdsl.logging.Logger.error("Error while parsing query in field filter: ");
		org.webdsl.logging.Logger.error("EXCEPTION",e);
		q = new TermQuery(new Term(field, value));
	}
	Filter filter = new QueryWrapperFilter(q);
	filter = new CachingWrapperFilter( filter );
	return filter;
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:19,代码来源:FieldConstraintFilter.java

示例15: getCollectionFilters

import org.apache.lucene.queryParser.ParseException; //导入依赖的package包/类
/**
 * Set up the filters for collections - this is for searching within collections.
 * 
 * @param collection - to search within
 * @return - created filter
 * @throws ParseException
 */
private List<Filter> getCollectionFilters(InstitutionalCollection collection) throws ParseException
{
	List<Filter> filters = new LinkedList<Filter>();
	
       //isolate the collection root
	Term t = new Term("collection_root_id", NumericUtils.longToPrefixCoded(collection.getTreeRoot().getId()));
	Query subQuery = new TermQuery( t );
	filters.add(new QueryWrapperFilter(subQuery));
	
	
	//isolate the range of children
	subQuery = NumericRangeQuery.newLongRange("collection_left_value", collection.getLeftValue(), collection.getRightValue(), true, true);
	filters.add(new QueryWrapperFilter(subQuery));
    return filters;
}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:23,代码来源:DefaultInstitutionalItemSearchService.java


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