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


Java MultiFieldQueryParser类代码示例

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


MultiFieldQueryParser类属于org.apache.lucene.queryParser包,在下文中一共展示了MultiFieldQueryParser类的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;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:31,代码来源:SearchServiceImpl.java

示例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;
}
 
开发者ID:CoEIA,项目名称:DEM,代码行数:23,代码来源:LuceneSearcher.java

示例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;
}
 
开发者ID:mobilipia,项目名称:Deskera-HRMS,代码行数:26,代码来源:SearchBean.java

示例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;
}
 
开发者ID:mobilipia,项目名称:Deskera-HRMS,代码行数:18,代码来源:SearchBean.java

示例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;
}
 
开发者ID:micromata,项目名称:projectforge-webapp,代码行数:25,代码来源:BaseDao.java

示例6: getFullTextQueryForKeywordOnAllAnnotatedFields

import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入依赖的package包/类
public FullTextQuery getFullTextQueryForKeywordOnAllAnnotatedFields(String keyword) throws ParseException {

    String[] indexedFields = findAllIndexedFields(entity);

    final QueryParser parser = new MultiFieldQueryParser(Version.LUCENE_35, indexedFields, analyzer);
    parser.setAllowLeadingWildcard(true);

    // Add wildcards when not already in search
    if (!(StringUtils.containsAny(keyword, new char[] { '*', '?', ':' }) || keyword.startsWith("\"") && keyword.endsWith("\""))) {
      keyword = "*" + keyword + "*";
    }

    Query luceneQuery = parser.parse(keyword);
    FullTextQuery fullTextQuery = getFullTextQuery(luceneQuery);
    return fullTextQuery;
  }
 
开发者ID:BandwidthOnDemand,项目名称:bandwidth-on-demand,代码行数:17,代码来源:FullTextSearchContext.java

示例7: 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;
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:18,代码来源:ConsoleSearch.java

示例8: testDefaultOperator

import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入依赖的package包/类
public void testDefaultOperator() throws Exception {
  Query query = new MultiFieldQueryParser(Version.LUCENE_41,
                                          new String[]{"title", "subject"},
      new SimpleAnalyzer()).parse("development");

  Directory dir = TestUtil.getBookIndexDirectory();
  IndexSearcher searcher = new IndexSearcher(
                             dir,
                             true);
  TopDocs hits = searcher.search(query, 10);

  assertTrue(TestUtil.hitsIncludeTitle(
         searcher,
         hits,
         "Ant in Action"));

  assertTrue(TestUtil.hitsIncludeTitle(     //A
         searcher,                          //A
         hits,                              //A
         "Extreme Programming Explained")); //A
  searcher.close();
  dir.close();
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:24,代码来源:MultiFieldQueryParserTest.java

示例9: 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();
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:23,代码来源:MultiFieldQueryParserTest.java

示例10: IndexSearcher

import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入依赖的package包/类
public IndexSearcher() {
    try {
        searcher = new org.apache.lucene.search.IndexSearcher(new ClasspathDirectory());
    } catch (IOException e) {
        e.printStackTrace();
    }
    analyzer = new StandardAnalyzer(Version.LUCENE_31);
    parser = new MultiFieldQueryParser(Version.LUCENE_31, new String[]{"name","description"}, analyzer);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:10,代码来源:IndexSearcher.java

示例11: search

import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入依赖的package包/类
/**
 * 检索
 *
 * @param keyword
 */
public static void search(String keyword) throws Exception {

    IndexSearcher searcher = null;

    try {
        // 创建search
        searcher = getIndexSearcher();

        String[] fields = { "name", "author", "content" };
        QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_35, fields,
            new StandardAnalyzer(Version.LUCENE_35));
        queryParser.setDefaultOperator(QueryParser.AND_OPERATOR);
        Query query = queryParser.parse(keyword);

        // 查询
        TopDocs topDocs = searcher.search(query, MAX);

        ScoreDoc[] scoreDocs = topDocs.scoreDocs;
        logger.info("查询到条数=" + scoreDocs.length);

        for (ScoreDoc scoreDoc : scoreDocs) {
            Document doc = searcher.doc(scoreDoc.doc);
            logger.info("doc信息:" + "docId=" + scoreDoc.doc + "id=" + doc.get("id") + "author="
                        + doc.get("author") + "name=" + doc.get("name") + "content="
                        + doc.get("content"));
        }

    } catch (Exception e) {
        logger.error("查询失败:" + e.getMessage());
        throw e;
    }
}
 
开发者ID:cycman,项目名称:libooc,代码行数:38,代码来源:IndexUtil.java

示例12: multiFieldQuery

import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入依赖的package包/类
/**
     * 多条搜索
     * @param fields
     * @param value
     * @throws Exception
     */
    public static void multiFieldQuery( String[] fields, String value,List<Document>docs) throws Exception {
        try {

        	
            // 创建search
            IndexSearcher searcher = getIndexSearcher();


            QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_35, fields,
                    new StandardAnalyzer(Version.LUCENE_35));

            queryParser.setDefaultOperator(QueryParser.AND_OPERATOR);
            Query query = queryParser.parse(value);

            // 查询
            
            TopDocs topDocs = searcher.search(query, 1000);

            ScoreDoc[] scoreDocs = topDocs.scoreDocs;
            logger.info("查询到条数=" + scoreDocs.length);

            for (ScoreDoc scoreDoc : scoreDocs) {
                Document doc = searcher.doc(scoreDoc.doc);
//                logger.info("doc信息:" + " docId=" + scoreDoc.doc + " id=" + doc.get("id") + " author="
//                        + doc.get("author") + " name=" + doc.get("name") + " content="
//                        + doc.get("content"));
                docs.add(doc);
            }
        } catch (Exception e) {
            logger.error("termQuery查询失败");
            throw e;
        }
    }
 
开发者ID:cycman,项目名称:libooc,代码行数:40,代码来源:SearchUtil.java

示例13: loadModel

import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入依赖的package包/类
@Override
public void loadModel(String modelPath) throws IOException {
	docsSearcher = new IndexSearcher((new File(modelPath, "docs"))
			.getAbsolutePath());
	String[] fields = { "doc_id", "content", "user_id", "tag" };
	queryParser = new MultiFieldQueryParser(fields,
			new WhitespaceAnalyzer());
}
 
开发者ID:thunlp,项目名称:THUTag,代码行数:9,代码来源:ExpandRankKE.java

示例14: 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;
}
 
开发者ID:toulezu,项目名称:play,代码行数:29,代码来源:Main.java

示例15: 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();
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:41,代码来源:UserDaoJpa.java


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