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


Java MultiFieldQueryParser.setAllowLeadingWildcard方法代码示例

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


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

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

示例2: search

import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入方法依赖的package包/类
public SearchResult search(SearchCriteria criteria, IndexType indexType, int user_group_id) {
     SearchResult result = new SearchResult();
     int offset = criteria.getOffset();
     int count = criteria.getCount();
     result.setOffset(offset);

     IndexReader reader = null;
     try {
         reader = createIndexReader(indexType);
         Searcher searcher = new IndexSearcher(reader);
         Analyzer analyzer = new SubsonicAnalyzer();

         MultiFieldQueryParser queryParser = new MultiFieldQueryParser(LUCENE_VERSION, indexType.getFields(), analyzer, indexType.getBoosts());
queryParser.setAllowLeadingWildcard(true);
         Query query = queryParser.parse(criteria.getQuery());

         TopDocs topDocs = searcher.search(query, null, offset + count);
         result.setTotalHits(topDocs.totalHits);

         int start = Math.min(offset, topDocs.totalHits);
         int end = Math.min(start + count, topDocs.totalHits);
         for (int i = start; i < end; i++) {
             Document doc = searcher.doc(topDocs.scoreDocs[i].doc);
             switch (indexType) {
                 case SONG:
                 case ARTIST:
                 case ALBUM:
                     MediaFile mediaFile = mediaFileService.getMediaFile(Integer.valueOf(doc.get(FIELD_ID)), user_group_id);
                     addIfNotNull(mediaFile, result.getMediaFiles());
                     break;
                 case ARTIST_ID3:
                     Artist artist = artistDao.getArtist(Integer.valueOf(doc.get(FIELD_ID)));
                     addIfNotNull(artist, result.getArtists());
                     break;
                 case ALBUM_ID3:
                     Album album = albumDao.getAlbum(Integer.valueOf(doc.get(FIELD_ID)));
                     addIfNotNull(album, result.getAlbums());
                     break;
                 default:
                     break;
             }
         }

     } catch (Throwable x) {
         LOG.error("Failed to execute Lucene search.", x);
     } finally {
         FileUtil.closeQuietly(reader);
     }
     return result;
 }
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:51,代码来源:SearchService.java

示例3: search

import org.apache.lucene.queryParser.MultiFieldQueryParser; //导入方法依赖的package包/类
public SearchResult search(SearchCriteria criteria, IndexType indexType, int user_group_id) {
        SearchResult result = new SearchResult();
        int offset = criteria.getOffset();
        int count = criteria.getCount();
        result.setOffset(offset);

        IndexReader reader = null;
        try {
            reader = createIndexReader(indexType);
            Searcher searcher = new IndexSearcher(reader);
            Analyzer analyzer = new SubsonicAnalyzer();

            MultiFieldQueryParser queryParser = new MultiFieldQueryParser(LUCENE_VERSION, indexType.getFields(), analyzer, indexType.getBoosts());
			queryParser.setAllowLeadingWildcard(true);
			
            Query query = queryParser.parse(criteria.getQuery());
//          Query query = queryParser.parse(queryParser.escape(criteria.getQuery()));

            TopDocs topDocs = searcher.search(query, null, offset + count);
            result.setTotalHits(topDocs.totalHits);

            int start = Math.min(offset, topDocs.totalHits);
            int end = Math.min(start + count, topDocs.totalHits);
            for (int i = start; i < end; i++) {
                Document doc = searcher.doc(topDocs.scoreDocs[i].doc);
                switch (indexType) {
                    case SONG:
                    case ARTIST:
                    case ALBUM:
                        MediaFile mediaFile = mediaFileService.getMediaFile(Integer.valueOf(doc.get(FIELD_ID)), user_group_id);
                        addIfNotNull(mediaFile, result.getMediaFiles());
                        break;
                    case ARTIST_ID3:
                        Artist artist = artistDao.getArtist(Integer.valueOf(doc.get(FIELD_ID)));
                        addIfNotNull(artist, result.getArtists());
                        break;
                    case ALBUM_ID3:
                        Album album = albumDao.getAlbum(Integer.valueOf(doc.get(FIELD_ID)));
                        addIfNotNull(album, result.getAlbums());
                        break;
                    default:
                        break;
                }
            }

        } catch (Throwable x) {
            LOG.error("Failed to execute Lucene search.", x);
        } finally {
            FileUtil.closeQuietly(reader);
        }
        return result;
    }
 
开发者ID:MadMarty,项目名称:madsonic-server-5.1,代码行数:53,代码来源:SearchService.java


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