本文整理汇总了Java中org.apache.lucene.queryParser.QueryParser.setAllowLeadingWildcard方法的典型用法代码示例。如果您正苦于以下问题:Java QueryParser.setAllowLeadingWildcard方法的具体用法?Java QueryParser.setAllowLeadingWildcard怎么用?Java QueryParser.setAllowLeadingWildcard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.queryParser.QueryParser
的用法示例。
在下文中一共展示了QueryParser.setAllowLeadingWildcard方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: query
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
Query query( String keyOrNull, Object value, QueryContext contextOrNull )
{
if ( value instanceof Query )
{
return (Query) value;
}
QueryParser parser = new QueryParser( Version.LUCENE_30, keyOrNull, analyzer );
parser.setAllowLeadingWildcard( true );
parser.setLowercaseExpandedTerms( toLowerCase );
if ( contextOrNull != null && contextOrNull.getDefaultOperator() != null )
{
parser.setDefaultOperator( contextOrNull.getDefaultOperator() );
}
try
{
return parser.parse( value.toString() );
}
catch ( ParseException e )
{
throw new RuntimeException( e );
}
}
示例2: getFullTextQueryForKeywordOnAllAnnotatedFields
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的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;
}
示例3: createSearchInfoQuery
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
Query createSearchInfoQuery( SearchQuery searchQuery, Analyzer analyzer )
throws ParseException
{
TermQuery infoQuery =
new TermQuery(new Term(DOC_TYPE, DocType.INFO.toString()));
BooleanQuery query = new BooleanQuery();
query.add(infoQuery, Occur.MUST);
Query textQuery = createFreeTextQuery(searchQuery, analyzer);
if (textQuery != null) {
query.add(textQuery, Occur.MUST);
}
Query maturityQuery = createMaturityQuery(searchQuery);
if (maturityQuery != null) {
query.add(maturityQuery, Occur.MUST);
}
Query licenseQuery = createLicenseQuery(searchQuery);
if (licenseQuery != null) {
query.add(licenseQuery, Occur.MUST);
}
QueryParser parser = new QueryParser(Version.LUCENE_35, NAME, analyzer);
parser.setAllowLeadingWildcard(true);
Query docQuery = parser.parse(query.toString());
return docQuery;
}
示例4: createFreeTextQuery
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
private Query createFreeTextQuery( SearchQuery searchQuery,
String fieldName, Analyzer analyzer ) throws ParseException
{
List<String> freeTextQueryString =
createFreeTextQueryString(searchQuery, fieldName, analyzer);
if (freeTextQueryString.isEmpty()) {
return null;
}
BooleanQuery query = new BooleanQuery();
QueryParser parser = new QueryParser(Version.LUCENE_35, NAME, analyzer);
parser.setAllowLeadingWildcard(true);
for (String textQuery : freeTextQueryString) {
Query tokenQuery = parser.parse(textQuery);
query.add(tokenQuery, Occur.MUST);
}
return query;
}
示例5: getLuceneQuery
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public Query getLuceneQuery() {
QueryParser qp = new QueryParser(SearchConstants.version, fieldName, SearchConstants.analyzer);
if (value.startsWith("*")) {
qp.setAllowLeadingWildcard(true);
}
Query parse = null;
try {
parse = qp.parse(value);
} catch (ParseException e) {
e.printStackTrace();
}
return parse;
// return new TermQuery(new Term(fieldName, value));
}
示例6: getChatFilePathFast
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
private Set<String> getChatFilePathFast() throws IOException {
Set<String> result = new HashSet<String>();
try {
Directory directory = FSDirectory.open(new File(
this.panel.getCaseFacade().getCaseIndexFolderLocation()
));
IndexSearcher searcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser(Version.LUCENE_30,
IndexingConstant.CHAT_AGENT, new StopAnalyzer(Version.LUCENE_30));
parser.setAllowLeadingWildcard(true);
Query query = parser.parse(panel.getAgent());
TopDocs topDocs = searcher.search(query, 5000);
for(ScoreDoc scoreDoc: topDocs.scoreDocs) {
Document document = searcher.doc(scoreDoc.doc);
String chatFile = document.get(IndexingConstant.CHAT_FILE);
if ( chatFile != null && !chatFile.trim().isEmpty()) {
chatFile = this.panel.getCaseFacade().getFullPath(chatFile);
final File path = new File(chatFile);
result.add(path.getName());
}
}
searcher.close();
} catch (ParseException ex) {
Logger.getLogger(ChatRefreshTask.class.getName()).log(Level.SEVERE, null, ex);
}
return result;
}
示例7: search
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
@Test
// 1000 times: 2973 mills.
// 1000 times: 2927 mills.
// 1000 times: 2967 mills.
//
// 10000 times: 21268 mills.
// verified: ok
public void search() throws Exception {
createCommonDaoImpl();
//
FullTextSession fullTextSession = Search.getFullTextSession(sessionFactory.openSession());
// StopAnalyzer 完全相同才能找到資料,同=,無法查中文
// StandardAnalyzer 能找到資料,同like
Analyzer analyzer = new KeywordAnalyzer();
// Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_34);
QueryParser parser = new QueryParser(Version.LUCENE_31, "id", analyzer);
parser.setAllowLeadingWildcard(true);
parser.setLowercaseExpandedTerms(true);
//
// name:Marry
// name:瑪莉
// String search = String.Format("name:{0} AND title:{1}", "中国建设银行",
// "doc1");
StringBuilder lql = new StringBuilder();
// #issue: 大寫找不到???
// lql.append("id:*a*");
// lql.append("audit:*sys*");
lql.append("names:*a*");
org.apache.lucene.search.Query luceneQuery = parser.parse(lql.toString());
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, DogPoImpl.class);
//
List result = null;
int count = 1;
long beg = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
result = fullTextQuery.list();
}
long end = System.currentTimeMillis();
System.out.println(count + " times: " + (end - beg) + " mills. ");
System.out.println(result.size() + ", " + result);
assertNotNull(result);
}
示例8: getQuery
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
private Query getQuery(final String field, final String query) throws ParseException {
final QueryParser queryParser = new QueryParser(LUCENE_VERSION, field, analyzer);
queryParser.setAllowLeadingWildcard(true);
queryParser.setDefaultOperator(QueryParser.Operator.AND);
return queryParser.parse(query);
}
示例9: loadItemsFast
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
private Set<ImagePathAndId> loadItemsFast(int from, int size) throws IOException {
Set<ImagePathAndId> files = new HashSet<ImagePathAndId>();
int counter = 0;
try {
Directory directory = FSDirectory.open(new File(this.caseFacade.getCaseIndexFolderLocation()));
IndexSearcher searcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser(Version.LUCENE_30, IndexingConstant.DOCUMENT_TYPE, new StopAnalyzer(Version.LUCENE_30));
parser.setAllowLeadingWildcard(true);
Query query = parser.parse(IndexingConstant.fromDocumentTypeToString(IndexingConstant.DOCUMENT_GENERAL_TYPE.IMAGE));
TopDocs topDocs = searcher.search(query, 500000);
for(ScoreDoc scoreDoc: topDocs.scoreDocs) {
Document document = searcher.doc(scoreDoc.doc);
String imageExtension = document.get(IndexingConstant.FILE_MIME);
if ( imageExtension != null && !imageExtension.trim().isEmpty() &&
Arrays.asList(imageExtensions).contains(imageExtension ) ) {
String fullpath = "";
int id = Integer.parseInt(document.get(IndexingConstant.DOCUMENT_ID));
if ( IndexingConstant.isImageDocument(document) ) {
String path = document.get(IndexingConstant.FILE_PATH);
if ( path.contains(this.aCase.getCaseName() + File.separator + ApplicationConstants.CASE_ARCHIVE_FOLDER) )
fullpath = path;
else
fullpath = this.caseFacade.getFullPath(document.get(IndexingConstant.FILE_PATH));
}
if ( ! fullpath.isEmpty() ) {
counter++;
if ( files.size() >= size)
break;
if ( counter >= from ) {
files.add(new ImagePathAndId(fullpath, Integer.valueOf(id)));
}
}
}
}
searcher.close();
} catch (ParseException ex) {
Logger.getLogger(ChatRefreshTask.class.getName()).log(Level.SEVERE, null, ex);
}
return files;
}
示例10: getNumberOfImagesFast
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
private int getNumberOfImagesFast() throws IOException {
int numberOfImages = 0;
try {
Directory directory = FSDirectory.open(new File(
this.caseFacade.getCaseIndexFolderLocation()
));
IndexSearcher searcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser(Version.LUCENE_30,
IndexingConstant.DOCUMENT_TYPE, new StopAnalyzer(Version.LUCENE_30));
parser.setAllowLeadingWildcard(true);
Query query = parser.parse(IndexingConstant.fromDocumentTypeToString(IndexingConstant.DOCUMENT_GENERAL_TYPE.IMAGE));
TopDocs topDocs = searcher.search(query, 500000);
for(ScoreDoc scoreDoc: topDocs.scoreDocs) {
Document document = searcher.doc(scoreDoc.doc);
String imageExtension = document.get(IndexingConstant.FILE_MIME);
if ( imageExtension != null && !imageExtension.trim().isEmpty() &&
Arrays.asList(imageExtensions).contains(imageExtension ) ) {
String fullpath = "";
if ( IndexingConstant.isImageDocument(document) ) {
String path = document.get(IndexingConstant.FILE_PATH);
if ( path.contains(this.aCase.getCaseName() + File.separator + ApplicationConstants.CASE_ARCHIVE_FOLDER) )
fullpath = path;
else
fullpath = this.caseFacade.getFullPath(document.get(IndexingConstant.FILE_PATH));
}
if ( ! fullpath.isEmpty() ) {
numberOfImages++;
}
}
}
searcher.close();
} catch (ParseException ex) {
Logger.getLogger(ChatRefreshTask.class.getName()).log(Level.SEVERE, null, ex);
}
return numberOfImages;
}
示例11: getAllEmailMessagesFast
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
private void getAllEmailMessagesFast(final String path, final String constant, final String type) throws IOException {
List<Integer> ids = new ArrayList<Integer>();
try {
Directory directory = FSDirectory.open(new File(
this.panel.getCaseFacade().getCaseIndexFolderLocation()
));
IndexSearcher searcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser(Version.LUCENE_30,
IndexingConstant.DOCUMENT_TYPE, new StopAnalyzer(Version.LUCENE_30));
parser.setAllowLeadingWildcard(true);
Query query = parser.parse("email");
TopDocs topDocs = searcher.search(query, 100000);
for(ScoreDoc scoreDocs: topDocs.scoreDocs) {
Document document = searcher.doc(scoreDocs.doc);
String emailPath = document.get(constant);
if ( emailPath != null && !emailPath.trim().isEmpty()) {
if ( emailPath.endsWith(path) ) {
final EmailItem item = (EmailItem) ItemFactory.newInstance(document, panel.getCaseFacade(), false);
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JTableUtil.addRowToJTable(panel.getTable(), item.getFullDisplayData());
}
});
ids.add(Integer.valueOf(item.getDocumentId()));
}
}
}
searcher.close();
} catch (ParseException ex) {
Logger.getLogger(ChatRefreshTask.class.getName()).log(Level.SEVERE, null, ex);
}
this.panel.setResultIds(ids);
}
示例12: displayChatSessionFast
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
private void displayChatSessionFast() throws IOException {
try {
Directory directory = FSDirectory.open(new File(
this.panel.getCaseFacade().getCaseIndexFolderLocation()
));
IndexSearcher searcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser(Version.LUCENE_30,
IndexingConstant.CHAT_AGENT, new StopAnalyzer(Version.LUCENE_30));
parser.setAllowLeadingWildcard(true);
Query query = parser.parse(panel.getAgent());
TopDocs topDocs = searcher.search(query, 5000);
for(ScoreDoc scoreDoc: topDocs.scoreDocs) {
final Document document = searcher.doc(scoreDoc.doc);
String chatFile = document.get(IndexingConstant.CHAT_FILE);
if ( chatFile != null && !chatFile.trim().isEmpty()) {
if ( chatFile.endsWith(this.fileName) ) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
ChatItem item = (ChatItem) ItemFactory.newInstance(document, panel.getCaseFacade()
, false);
Object[] data = new Object[] {item.getFrom(), item.getTo(), item.getMessageText(),
item.getDate()};
JTableUtil.addRowToJTable(panel.getTable(), data);
}
});
}
}
}
searcher.close();
} catch (ParseException ex) {
Logger.getLogger(ChatRefreshTask.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例13: getExtensionFreqFast
import org.apache.lucene.queryParser.QueryParser; //导入方法依赖的package包/类
private Map<String,Double> getExtensionFreqFast() throws IOException {
Map<String,Double> map = new HashMap<String,Double>();
try {
Directory directory = FSDirectory.open(new File(
this.caseFacade.getCaseIndexFolderLocation()
));
IndexSearcher searcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser(Version.LUCENE_30,
IndexingConstant.DOCUMENT_TYPE, new StopAnalyzer(Version.LUCENE_30));
parser.setAllowLeadingWildcard(true);
Query query = parser.parse("file");
TopDocs topDocs = searcher.search(query, 100000);
for(ScoreDoc scoreDoc: topDocs.scoreDocs) {
Document document = searcher.doc(scoreDoc.doc);
String filePath = document.get(IndexingConstant.FILE_PATH);
if ( filePath != null && !filePath.trim().isEmpty()) {
final File path = new File(filePath);
String ext = FileUtil.getExtension(path);
if ( ext == null || ext.length() > 6) // no more extension than 5 character!
continue;
ext = ext.toLowerCase();
if ( map.get(ext) == null ){
map.put(ext, 1.0);
}
else
map.put(ext, map.get(ext) + 1);
}
}
searcher.close();
} catch (ParseException ex) {
Logger.getLogger(ChatRefreshTask.class.getName()).log(Level.SEVERE, null, ex);
}
return map ;
}