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


Java Searcher类代码示例

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


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

示例1: addField

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
public boolean addField(String recID, String prefix, String value){
   try {
	   Searcher searcher = new IndexSearcher(indexPath);
	   Query q=new TermQuery(new Term("ID",recID));
	   Hits hits=searcher.search(q);
	   if ((hits==null)||(hits.length()!=1)){
		   return false;
	   }   
	   Document doc=hits.doc(0);
	   IndexWriter iw = getIndexWriter(); 
	   Field f=new Field(prefix,value, Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.NO);
	   doc.add(f);
	   iw.updateDocument(new Term("ID", recID), doc);
	} catch (IOException ex) {
	   log.fatal(ex);
	   return false;
	 }
	 return true;
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:20,代码来源:BulkIndexer.java

示例2: addField

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
public boolean addField(String recID, String prefix, String value){
  try {
   Searcher searcher = new IndexSearcher(indexPath);
   Query q=new TermQuery(new Term("ID",recID));
   Hits hits=searcher.search(q);
   if ((hits==null)||(hits.length()!=1)){
	   return false;
   }   
   Document doc=hits.doc(0);
   IndexWriter iw = getIndexWriter(); 
   Field f=new Field(prefix,value, Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.NO);
   doc.add(f);
   iw.updateDocument(new Term("ID", recID), doc);
   iw.close();
} catch (IOException ex) {
   log.fatal(ex);
   return false;
 }
 return true;
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:21,代码来源:Indexer.java

示例3: deleteField

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
public void deleteField(String recID, String prefix, String value){
   try {
	   Searcher searcher = new IndexSearcher(indexPath);
	   Query q=new TermQuery(new Term("ID",recID));
	   Hits hits=searcher.search(q);
	   if ((hits==null)||(hits.length()!=1)){
		   log.fatal("greska pri brisanju polja. Zapis: "+recID);
		   return ;   
	   }   
	   
	   Document doc=hits.doc(0);
	   Field [] fields=doc.getFields(prefix);
	   IndexWriter iw = getIndexWriter(); 
	   doc.removeFields(prefix);
	   for(int i=0;i<fields.length;i++){
		   if(!fields[i].stringValue().equals(value)){
			   doc.add(fields[i]);
		   } 
	   }
	   iw.updateDocument(new Term("ID", recID), doc);
	   iw.close();
	} catch (IOException ex) {
	   log.fatal(ex);
	 }
	 
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:27,代码来源:Indexer.java

示例4: getResultList

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
public static List<Integer> getResultList(Searcher searcher, TopDocs docs,
		int first, int max) throws CorruptIndexException, IOException {
	List<Integer> list = new ArrayList<Integer>(max);
	ScoreDoc[] hits = docs.scoreDocs;
	if (first < 0) {
		first = 0;
	}
	if (max < 0) {
		max = 0;
	}
	int last = first + max;
	int len = hits.length;
	if (last > len) {
		last = len;
	}
	for (int i = first; i < last; i++) {
		Document d = searcher.doc(hits[i].doc);
		list.add(Integer.valueOf(d.getField(ID).stringValue()));
	}
	return list;
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:22,代码来源:LuceneContent.java

示例5: 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

示例6: incomingLinks

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
public Set<String> incomingLinks(final String page) throws IOException, PageStoreException {
  if (_dir == null) {
    return Collections.emptySet();
  }
  try {
    return doReadOperation(new ReadOperation<Set<String>>() {
      public Set<String> execute(final IndexReader reader, final Searcher searcher, final Analyzer analyzer) throws IOException, ParseException {
        final String pageEscaped = escape(URIUtil.encodeWithinPath(page));
        Set<String> results = Sets.newLinkedHashSet(Iterables.transform(query(reader, createAnalyzer(), searcher, FIELD_OUTGOING_LINKS, pageEscaped, false), SearchMatch.TO_PAGE_NAME));
        results.remove(page);
        return results;
      }
    }, false);
  }
  catch (QuerySyntaxException ex) {
    throw new NoQueryPerformedException(ex);
  }
}
 
开发者ID:CoreFiling,项目名称:reviki,代码行数:19,代码来源:LuceneSearcher.java

示例7: search

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
public Set<SearchMatch> search(final String queryString, final boolean provideExtracts, final boolean singleWiki) throws IOException, QuerySyntaxException {
  if (_dir == null || queryString == null || queryString.trim().length() == 0) {
    return Collections.emptySet();
  }
  return doReadOperation(new ReadOperation<Set<SearchMatch>>() {
    public Set<SearchMatch> execute(final IndexReader reader, final Searcher searcher, final Analyzer analyzer) throws IOException, ParseException {
      LinkedHashSet<SearchMatch> results = new LinkedHashSet<SearchMatch>();
      // Prefer path, then title then content matches (match equality is on page name)
      for (String field : ALL_SEARCH_FIELDS) {
        if (field.equals(FIELD_PATH_LOWER)) {
          final Query query = new WildcardQuery(new Term(FIELD_PATH_LOWER, "*" + queryString.toLowerCase() + "*"));
          results.addAll(doQuery(reader, analyzer, searcher, field, provideExtracts, query));
        }
        else {
          results.addAll(query(reader, analyzer, searcher, field, queryString, provideExtracts));
        }
      }
      return orderResults(results);
    }
  }, !singleWiki);
}
 
开发者ID:CoreFiling,项目名称:reviki,代码行数:22,代码来源:LuceneSearcher.java

示例8: getProperty

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
private String getProperty(final String propertyName) throws IOException {
  if (_dir == null) {
    return null;
  }
  try {
    return doReadOperation(new ReadOperation<String>() {
      public String execute(final IndexReader reader, final Searcher searcher, final Analyzer analyzer) throws IOException, ParseException {
        Hits hits = searcher.search(new TermQuery(new Term(FIELD_PROPERTY_KEY, propertyName)));
        Iterator<?> iterator = hits.iterator();
        if (iterator.hasNext()) {
          return ((Hit) iterator.next()).get(FIELD_PROPERTY_VALUE);
        }
        return null;
      }
    }, false);
  }
  catch (QuerySyntaxException ex) {
    throw new NoQueryPerformedException(ex);
  }
}
 
开发者ID:CoreFiling,项目名称:reviki,代码行数:21,代码来源:LuceneSearcher.java

示例9: getSearcher

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
/**
 * Returns a Lucene Searcher that can be used to execute queries. Lucene
 * can handle index reading even while updates occur. However, in order
 * for index changes to be reflected in search results, the reader must
 * be re-opened whenever the modificationDate changes.<p>
 * <p/>
 * The location of the index is the "index" subdirectory in [jiveHome].
 *
 * @return a Searcher that can be used to execute queries.
 */
public Searcher getSearcher() throws IOException {
    synchronized (indexerAnalyzer) {
        if (searcherReader == null) {
            if (searchDirectory != null && IndexReader.indexExists(searchDirectory)) {
                searcherReader = IndexReader.open(searchDirectory);
                searcher = new IndexSearcher(searcherReader);
            }
            else {
                // Log warnings.
                if (searchDirectory == null) {
                    Log.warn("Search " +
                            "directory not set, you must rebuild the index.");
                }
                else if (!IndexReader.indexExists(searchDirectory)) {
                    Log.warn("Search " +
                            "directory " + searchDirectory + " does not appear to " +
                            "be a valid search index. You must rebuild the index.");
                }
                return null;
            }
        }
    }
    return searcher;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:35,代码来源:ChatSearchManager.java

示例10: NearSpans

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
public NearSpans(SpanNearQuery query, IndexReader reader, Searcher searcher)
  throws IOException 
{
  this.query = query;
  this.slop = query.getSlop();
  this.inOrder = query.isInOrder();

  SpanQuery[] clauses = query.getClauses(); // initialize spans & list
  for (int i = 0; i < clauses.length; i++) {
    SpansCell cell =  // construct clause spans
                     new SpansCell(clauses[i].getSpans(reader, searcher), i);
    ordered.add(cell); // add to ordered
  }

  similarity = searcher.getSimilarity();
}
 
开发者ID:CDLUC3,项目名称:dash-xtf,代码行数:17,代码来源:NearSpans.java

示例11: OrNearSpans

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
public OrNearSpans(SpanOrNearQuery query, IndexReader reader,
                   Searcher searcher)
  throws IOException 
{
  this.query = query;
  this.slop = query.getSlop();
  this.penalizeOutOfOrder = query.penalizeOutOfOrder();

  SpanQuery[] clauses = query.getClauses();
  nClauses = clauses.length;
  cells = new ArrayList(nClauses);
  for (int i = 0; i < nClauses; i++)
    cells.add(new SpansCell(clauses[i].getSpans(reader, searcher), i));

  similarity = searcher.getSimilarity();
}
 
开发者ID:CDLUC3,项目名称:dash-xtf,代码行数:17,代码来源:OrNearSpans.java

示例12: LuceneResultSet

import org.apache.lucene.search.Searcher; //导入依赖的package包/类
/**
 * Wrap a lucene seach result with node support
 * 
 * @param hits Hits
 * @param searcher Searcher
 * @param nodeService nodeService
 * @param tenantService tenant service
 * @param searchParameters SearchParameters
 * @param config - lucene config
 */
public LuceneResultSet(Hits hits, Searcher searcher, NodeService nodeService, TenantService tenantService, SearchParameters searchParameters,
        LuceneConfig config)
{
    super();
    this.hits = hits;
    this.searcher = searcher;
    this.nodeService = nodeService;
    this.tenantService = tenantService;
    this.searchParameters = searchParameters;
    this.config = config;
    prefetch = new BitSet(hits.length());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:LuceneResultSet.java

示例13: 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

示例14: 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

示例15: 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


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