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


Java Searcher.close方法代码示例

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


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

示例1: searchPage

import org.apache.lucene.search.Searcher; //导入方法依赖的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

示例2: selectAll

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public Result selectAll(Query query, String sortPrefix){
  try {
    BooleanQuery.setMaxClauseCount(20000);//zbog heap-a
    Searcher searcher = new IndexSearcher(indexPath);
    Hits hits;
    if (sortPrefix == null || "".equals(sortPrefix))
      hits = searcher.search(query);
    else {
      int sortType = SortField.STRING;
      if ("RN_sort".equals(sortPrefix))
        sortType = SortField.INT;
      hits = searcher.search(query, new Sort(
          new SortField(sortPrefix, sortType)));
    }
    
    int n = hits.length();
    int[] retVal = new int[n];
    List<String> invs = new ArrayList<String>();
    Field[] tmp = null;
    
    for (int i = 0; i < n; i++) {
      String recordID = hits.doc(i).get("ID");
      retVal[i] = Integer.parseInt(recordID);
      tmp = hits.doc(i).getFields("IN");
      if (tmp != null){
        for (int j = 0; j<tmp.length; j++){
          invs.add(tmp[j].stringValue());
        } 
      }
    }
    searcher.close();
    Result result = new Result();
    result.setRecords(retVal);
    result.setInvs(invs);
    return result;
  } catch (Exception ex) {
    log.fatal(ex);
    return null;
  }
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:41,代码来源:Retriever.java

示例3: select

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public int[] select(Query query, Filter filter, String sortPrefix){
  try {
    BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
    Searcher searcher = new IndexSearcher(indexPath);
    Hits hits;
    if (sortPrefix == null || "".equals(sortPrefix)){
       hits = searcher.search(query,filter);
    } else {
      int sortType = SortField.STRING;
      if ("RN_sort".equals(sortPrefix))
        sortType = SortField.INT;
      hits = searcher.search(query,filter, new Sort(
          new SortField(sortPrefix, sortType)));
 }
    int n = hits.length();
    int[] retVal = new int[n];
  
    for (int i = 0; i < n; i++) {
      String recordID = hits.doc(i).get("ID");
      retVal[i] = Integer.parseInt(recordID);
    }
    searcher.close();
    return retVal;
  } catch (Exception ex) {
    log.fatal(ex);
    return null;
  }
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:29,代码来源:Retriever.java

示例4: selectExpand

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public List<String> selectExpand(String query, String prefix,String text){
  try {
   WhitespaceAnalyzer sa= new WhitespaceAnalyzer();
   BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
   QueryParser p = new QueryParser("contents", sa);
   Query q = p.parse(query);
   Searcher searcher = new IndexSearcher(indexPath);
   StopWatch clock=new StopWatch();
   clock.start();
   Hits hits = searcher.search(q);
   int n = hits.length();
   List <String> expandList = new ArrayList<String>();
   Field[] tmp = null;
   String pom="";
    for (int i = 0; i < n; i++) {
      tmp = hits.doc(i).getFields(prefix);
      if (tmp != null){
        for (int j = 0; j<tmp.length; j++){
      	  pom=tmp[j].stringValue().replace("0start0 ", "");
      	  pom=pom.replace(" 0end0", "");
      	  if(pom.startsWith(text)&&(!expandList.contains(pom))){
      	     expandList.add(pom);
      	  }
        } 
      }
    }
    clock.stop();
    searcher.close();
    return expandList;
  } catch (Exception ex) {
    log.fatal(ex);
    return null;
  }
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:35,代码来源:Retriever.java

示例5: searchList

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
@Transactional(readOnly = true)
public List<Content> searchList(Directory dir, String queryString,String category,String workplace,
		Integer siteId, Integer channelId, Date startDate, Date endDate,
		int first, int max) 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);
		if (first < 0) {
			first = 0;
		}
		if (max < 0) {
			max = 0;
		}
		TopDocs docs = searcher.search(query, first + max);
		List<Integer> ids = LuceneContent.getResultList(searcher, docs,
				first, max);
		List<Content> contents = new ArrayList<Content>(ids.size());
		for (Object id : ids) {
			contents.add(contentMng.findById((Integer) id));
		}
		return contents;
	} finally {
		searcher.close();
	}
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:29,代码来源:LuceneContentSvcImpl.java

示例6: close

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
private static void close(Searcher searcher) throws SearchException {
   	if(searcher!=null){
   		try {
   			searcher.close();
		} catch (IOException e) {
			throw new SearchException(e);
		}
   	}
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:10,代码来源:LuceneSearchCollection.java

示例7: query

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
@Override
public <T> void query(
        @NonNull Collection<? super T> result,
        @NonNull Convertor<? super Document, T> convertor,
        @NullAllowed FieldSelector selector,
        @NullAllowed AtomicBoolean cancel,
        @NonNull Query... queries) throws IOException, InterruptedException {
    Parameters.notNull("queries", queries);   //NOI18N
    Parameters.notNull("convertor", convertor); //NOI18N
    Parameters.notNull("result", result);       //NOI18N   
    
    if (selector == null) {
        selector = AllFieldsSelector.INSTANCE;
    }
    
    lock.readLock().lock();
    try {
        final IndexReader in = getReader();
        if (in == null) {
            return;
        }
        final BitSet bs = new BitSet(in.maxDoc());
        final Collector c = new BitSetCollector(bs);
        final Searcher searcher = new IndexSearcher(in);
        try {
            for (Query q : queries) {
                if (cancel != null && cancel.get()) {
                    throw new InterruptedException ();
                }
                searcher.search(q, c);
            }
        } finally {
            searcher.close();
        }        
        for (int docNum = bs.nextSetBit(0); docNum >= 0; docNum = bs.nextSetBit(docNum+1)) {
            if (cancel != null && cancel.get()) {
                throw new InterruptedException ();
            }
            final Document doc = in.document(docNum, selector);
            final T value = convertor.convert(doc);
            if (value != null) {
                result.add (value);
            }
        }
    } finally {
        lock.readLock().unlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:MemoryIndex.java

示例8: queryDocTerms

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
@Override
public <S, T> void queryDocTerms(
        @NonNull Map<? super T, Set<S>> result,
        @NonNull Convertor<? super Document, T> convertor,
        @NonNull Convertor<? super Term, S> termConvertor,
        @NullAllowed FieldSelector selector,
        @NullAllowed AtomicBoolean cancel,
        @NonNull Query... queries) throws IOException, InterruptedException {
    Parameters.notNull("result", result);   //NOI18N
    Parameters.notNull("convertor", convertor);   //NOI18N
    Parameters.notNull("termConvertor", termConvertor); //NOI18N
    Parameters.notNull("queries", queries);   //NOI18N
    
    
    if (selector == null) {
        selector = AllFieldsSelector.INSTANCE;
    }

    lock.readLock().lock();
    try {
        final IndexReader in = getReader();
        if (in == null) {
            return;
        }
        final BitSet bs = new BitSet(in.maxDoc());
        final Collector c = new BitSetCollector(bs);
        final Searcher searcher = new IndexSearcher(in);
        final TermCollector termCollector = new TermCollector(c);
        try {
            for (Query q : queries) {
                if (cancel != null && cancel.get()) {
                    throw new InterruptedException ();
                }
                if (q instanceof TermCollector.TermCollecting) {
                    ((TermCollector.TermCollecting)q).attach(termCollector);
                } else {
                    throw new IllegalArgumentException (
                            String.format("Query: %s does not implement TermCollecting",    //NOI18N
                            q.getClass().getName()));
                }
                searcher.search(q, termCollector);
            }
        } finally {
            searcher.close();
        }

        for (int docNum = bs.nextSetBit(0); docNum >= 0; docNum = bs.nextSetBit(docNum+1)) {
            if (cancel != null && cancel.get()) {
                throw new InterruptedException ();
            }
            final Document doc = in.document(docNum, selector);
            final T value = convertor.convert(doc);
            if (value != null) {
                final Set<Term> terms = termCollector.get(docNum);
                if (terms != null) {
                    result.put (value, convertTerms(termConvertor, terms));
                }
            }
        }
    } finally {
        lock.readLock().unlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:64,代码来源:MemoryIndex.java

示例9: main

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public static void main(String[] args) {
   try {
     Searcher searcher = new IndexSearcher("index");
     Analyzer analyzer = new StandardAnalyzer();

     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
     while (true) {
System.out.print("Query: ");
String line = in.readLine();

if (line.length() == -1)
  break;

Query query = QueryParser.parse(line, "contents", analyzer);
System.out.println("Searching for: " + query.toString("contents"));

Hits hits = searcher.search(query);
System.out.println(hits.length() + " total matching documents");

final int HITS_PER_PAGE = 10;
for (int start = 0; start < hits.length(); start += HITS_PER_PAGE) {
  int end = Math.min(hits.length(), start + HITS_PER_PAGE);
  for (int i = start; i < end; i++) {
    Document doc = hits.doc(i);
    String path = doc.get("path");
    if (path != null) {
             System.out.println(i + ". " + path);
    } else {
             String url = doc.get("url");
      if (url != null) {
	System.out.println(i + ". " + url);
	System.out.println("   - " + doc.get("title"));
      } else {
	System.out.println(i + ". " + "No path nor URL for this document");
      }
    }
  }

  if (hits.length() > end) {
    System.out.print("more (y/n) ? ");
    line = in.readLine();
    if (line.length() == 0 || line.charAt(0) == 'n')
      break;
  }
}
     }
     searcher.close();

   } catch (Exception e) {
     System.out.println(" caught a " + e.getClass() +
		 "\n with message: " + e.getMessage());
   }
 }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:54,代码来源:SearchFiles.java

示例10: selectAll1

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
public Result selectAll1(String query, String sortPrefix)throws ParseException{
  try {
  	WhitespaceAnalyzer sa= new WhitespaceAnalyzer();
  	Searcher searcher = new IndexSearcher(indexPath);
      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);
      Hits hits;
    if (sortPrefix == null || "".equals(sortPrefix))
      hits = searcher.search(q);
    else {
      int sortType = SortField.STRING;
      if ("RN_sort".equals(sortPrefix))
        sortType = SortField.INT;
      hits = searcher.search(q, new Sort(
          new SortField(sortPrefix, sortType)));
    }
    
    int n = hits.length();
    int[] retVal = new int[n];
    List<String> invs = new ArrayList<String>();
    Field[] tmp = null;
    
    for (int i = 0; i < n; i++) {
      String recordID = hits.doc(i).get("ID");
      retVal[i] = Integer.parseInt(recordID);
      tmp = hits.doc(i).getFields("IN");
      if (tmp != null){
        for (int j = 0; j<tmp.length; j++){
          invs.add(tmp[j].stringValue());
        } 
      }
    }
    searcher.close();
    Result result = new Result();
    result.setRecords(retVal);
    result.setInvs(invs);
    return result;
  } catch (Exception ex) {
  	if (ex instanceof ParseException )
  		throw (ParseException)ex;
    log.fatal(ex);
    return null;
  }
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:47,代码来源:Retriever.java

示例11: generateConfidence

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static Map<String, Float> generateConfidence(final String indexFolder, String query, final String field,
		final int noOfPages, final String[] ignoreWordList) throws Exception {
	Map<String, Float> docNameScore = new HashMap<String, Float>();
	IndexReader reader = null;
	Analyzer analyzer = null;
	Searcher searcher = null;
	try {
		reader = IndexReader.open(FSDirectory.open(new File(indexFolder)), true); // only searching, so read-only=true
		searcher = new IndexSearcher(reader);
		analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
		QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, field, analyzer);
		if (query != null) {
			query = query.trim();
		} else {
			System.out.println("Wrong Query generated");
			return null;
		}
		parser.setAllowLeadingWildcard(true);

		BooleanQuery searchQuery = new BooleanQuery();
		Query matchQuery = parser.parse(query);
		searchQuery.add(matchQuery, BooleanClause.Occur.MUST);
		if (ignoreWordList != null) {
			for (String ignoreWord : ignoreWordList) {
				TermQuery notMatchClause = new TermQuery(new Term(field, ignoreWord.toLowerCase()));
				searchQuery.add(notMatchClause, BooleanClause.Occur.MUST_NOT);
			}
		}

		ScoreDoc[] scoreDocs = doPagingSearch(searcher, searchQuery, noOfPages);

		if (scoreDocs != null && scoreDocs.length > 0) {
			for (int i = 0; i < scoreDocs.length; i++) {
				Document document = searcher.doc(scoreDocs[i].doc);
				docNameScore.put(document.get("rowId"), calculateConfidenceScore(scoreDocs[i].score));
			}
		}
	} finally {
		if (reader != null) {
			reader.close();
		}
		if (analyzer != null) {
			analyzer.close();
		}
		if (searcher != null) {
			searcher.close();
		}
	}
	return docNameScore;
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:52,代码来源:SearchFiles.java

示例12: search

import org.apache.lucene.search.Searcher; //导入方法依赖的package包/类
/**
	 * Execute search using index.
	 * 
	 * @param indexPath
	 *            the index path
	 * @param queryString
	 *            the query string
	 * @return Returns an array of <code>SearchResultEntry</code> otherwise
	 *         null.
	 */
	public SearchResultEntry[] search(String queryString) {
		ArrayList<SearchResultEntry> result = new ArrayList<SearchResultEntry>();

		try {
			Searcher searcher = new IndexSearcher(indexPath);
			Analyzer analyzer = new StandardAnalyzer();

			String line = queryString;

			logger.debug("Query: " + line);
            QueryParser queryParser=new QueryParser("contents", analyzer);
            Query query = queryParser.parse(line);
            
			logger.debug("\nSearching for: '" + query.toString("contents")
					+ "'");
			Hits hits = searcher.search(query);
			logger.debug("Search result: " + hits.length()
					+ " total matching documents");

			for (int i = 0; i < hits.length(); i++) {
				Document doc = hits.doc(i);
				String path = doc.get("path");

				if (path != null) {
					logger.debug(i + ". " + path);
					// i'm interested only in concepts so filter out
					// non-concepts (HACK)
					// TODO this filter is here because of obsolete indexes -
					// there should be deleted
					if (path.indexOf(File.separator + "concepts"
							+ File.separator) >= 0) {
						result.add(new SearchResultEntry(doc
								.get("outlineLabel"), doc.get("conceptLabel"),
								doc.get("path")));
//						 logger.debug("path:\n"+doc.get("path"));
//						 logger.debug("modified:\n"+doc.get("modified"));
//						 logger.debug("notebook:\n"+doc.get("outlineLabel"));
//						 logger.debug("concept:\n"+doc.get("conceptLabel"));
					}

				} else {
					String url = doc.get("url");
					if (url != null) {
						logger.debug(i + ". " + url);
						logger.debug("   - " + doc.get("title"));
					} else {
						logger.debug(i + ". "
								+ "No path nor URL for this document");
					}
				}
			}
			searcher.close();

			return (SearchResultEntry[]) result
					.toArray(new SearchResultEntry[result.size()]);
		} catch (Exception e) {
			logger.error("Caught a " + e.getClass() + "\n with message: "
					+ e.getMessage(), e);
		}
		return null;
	}
 
开发者ID:dvorka,项目名称:mindraider,代码行数:72,代码来源:SearchEngine.java


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