本文整理匯總了Java中org.apache.lucene.queryparser.classic.QueryParser.setAllowLeadingWildcard方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryParser.setAllowLeadingWildcard方法的具體用法?Java QueryParser.setAllowLeadingWildcard怎麽用?Java QueryParser.setAllowLeadingWildcard使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.lucene.queryparser.classic.QueryParser
的用法示例。
在下文中一共展示了QueryParser.setAllowLeadingWildcard方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deleteIndexesByField
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@Override
public void deleteIndexesByField(String field) {
if (!isNullOrEmpty(field)) {
try {
Query query;
QueryParser parser = new QueryParser(Version.LUCENE_4_9, field, analyzer);
parser.setAllowLeadingWildcard(true);
try {
query = parser.parse("*");
} catch (ParseException e) {
throw new IndexingException(errorMessage(
"could not remove full-text index for value " + field, 0));
}
synchronized (this) {
indexWriter.deleteDocuments(query);
commit();
}
} catch (IOException ioe) {
throw new IndexingException(errorMessage(
"could not remove full-text index for value " + field, 0));
} catch (VirtualMachineError vme) {
handleVirtualMachineError(vme);
}
}
}
示例2: EclExpressionHandler
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
/**
* Instantiates a new ecl expression handler.
*
* @param terminology the terminology
* @param version the version
* @throws Exception the exception
*/
public EclExpressionHandler(String terminology, String version)
throws Exception {
// instantiate the index searcher
String indexDir =
ConfigUtility.getExpressionIndexDirectoryName(terminology, version);
Directory dirFile = new NIOFSDirectory(new File(indexDir));
indexSearcher = new IndexSearcher(DirectoryReader.open(dirFile));
// instantiate the modified SQS lucene converter
converter = new ExpressionConstraintToLuceneConverter();
// instantiate the query parser
queryParser =
new QueryParser(EclConceptFieldNames.ID, new StandardAnalyzer());
queryParser.setAllowLeadingWildcard(true);
// compute the internal functions from the modified SQS lucene converter
// NOTE: Kept out of Converter to minimize SQS code modification
for (final ExpressionConstraintToLuceneConverter.InternalFunction internalFunction : ExpressionConstraintToLuceneConverter.InternalFunction
.values()) {
internalFunctionPatternMap.put(internalFunction,
Pattern.compile(".*(" + internalFunction + "\\(([^\\)]+)\\)).*"));
}
}
示例3: query
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
Query query( String keyOrNull, Object value, QueryContext contextOrNull )
{
if ( value instanceof Query )
{
return (Query) value;
}
QueryParser parser = new QueryParser( 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 );
}
}
示例4: query
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public Query query(Schema schema) {
if (query == null) {
throw new IllegalArgumentException("Query statement required");
}
try {
Analyzer analyzer = schema.getAnalyzer();
QueryParser queryParser = new QueryParser(defaultField, analyzer);
queryParser.setAllowLeadingWildcard(true);
queryParser.setLowercaseExpandedTerms(false);
Query luceneQuery = queryParser.parse(query);
luceneQuery.setBoost(boost);
return luceneQuery;
} catch (ParseException e) {
throw new RuntimeException("Error while parsing lucene syntax query", e);
}
}
示例5: test
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@Test
public void test () throws ParseException
{
final QueryParser aQP = new QueryParser ("", PDLucene.createAnalyzer ());
aQP.setDefaultOperator (Operator.AND);
aQP.setAllowLeadingWildcard (true);
final Query aQuery = aQP.parse ("(allfields:*9905* AND allfields:*leckma*) AND NOT deleted:(*)");
System.out.println (aQuery.getClass () + " -- " + aQuery);
}
示例6: create
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
private QueryExpression create(Request request, ResourceDefinition resourceDefinition) throws InvalidQueryException {
String queryString;
if (request.getCardinality() == Request.Cardinality.INSTANCE) {
String idPropertyName = resourceDefinition.getIdPropertyName();
queryString = String.format("%s:%s", idPropertyName, request.<String>getProperty(idPropertyName));
} else {
queryString = request.getQueryString();
}
QueryExpression queryExpression;
if (queryString != null && !queryString.isEmpty()) {
QueryParser queryParser = new QueryParser(Version.LUCENE_48, "name", new KeywordAnalyzer());
queryParser.setLowercaseExpandedTerms(false);
queryParser.setAllowLeadingWildcard(true);
Query query;
try {
query = queryParser.parse((String) escape(queryString));
} catch (ParseException e) {
throw new InvalidQueryException(e.getMessage());
}
LOG.info("LuceneQuery: {}", query);
queryExpression = create(query, resourceDefinition);
} else {
queryExpression = new AlwaysQueryExpression();
}
// add query properties to request so that they are returned
request.addAdditionalSelectProperties(queryExpression.getProperties());
return queryExpression;
}
示例7: main
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@SuppressWarnings("resource")
public static void main(String[] args) throws Exception {
final Directory dir = new RAMDirectory();
final Analyzer analyzer = new WhitespaceAnalyzer();
final IndexWriterConfig conf = new IndexWriterConfig(analyzer);
final IndexWriter writer = new IndexWriter(dir, conf);
addDocument(writer, "brown fox and a red dog");
addDocument(writer, "only red dog");
addDocument(writer, "no red animals here");
writer.close();
final QueryParser qp = new QueryParser(TEXT_FIELD, analyzer);
qp.setAllowLeadingWildcard(true);
final DirectoryReader reader = DirectoryReader.open(dir);
final LeafReader leaf = reader.leaves().get(0).reader(); // We only have one segment
IndexUtils.printFieldTerms(leaf, TEXT_FIELD, COLOR_FIELD, ANIMAL_FIELD);
IndexUtils.printFieldTermsWithInfo(leaf, COLOR_FIELD, ANIMAL_FIELD);
final IndexSearcher searcher = new IndexSearcher(reader);
search(searcher, qp.parse("color:red"));
System.out.println();
search(searcher, qp.parse("animal:fox"));
System.out.println();
searchForBrownFox(searcher);
System.out.println();
search(searcher, qp.parse("animal:* AND color:*"));
System.out.println();
search(searcher, qp.parse("animal:* AND color:red"));
System.out.println();
reader.close();
}
示例8: main
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@SuppressWarnings("resource")
public static void main(String[] args) throws Exception {
final Directory dir = new RAMDirectory();
final Analyzer analyzer = new WhitespaceAnalyzer();
final IndexWriterConfig conf = new IndexWriterConfig(analyzer);
final IndexWriter writer = new IndexWriter(dir, conf);
addDocument(writer, "quick rosy brown fox and a pale violet red dog", 1, 2, 2, 1, 6, 3, 7, 1, 8, 1);
addDocument(writer, "only red dog", 1, 1);
addDocument(writer, "man with red pale face", 2, 1);
writer.close();
final QueryParser qp = new QueryParser(TEXT_FIELD, analyzer);
qp.setAllowLeadingWildcard(true);
final DirectoryReader reader = DirectoryReader.open(dir);
final LeafReader leaf = reader.leaves().get(0).reader(); // We only have one segment
IndexUtils.printFieldTerms(leaf, TEXT_FIELD, COLOR_FIELD);
IndexUtils.printFieldTermsWithInfo(leaf, COLOR_FIELD);
System.out.println();
final IndexSearcher searcher = new IndexSearcher(reader);
search(searcher, qp.parse("color:" + ANY_ANNOTATION_TERM));
System.out.println();
search(searcher, qp.parse("color:pale"));
System.out.println();
searchForColoredFox(searcher);
System.out.println();
reader.close();
}
示例9: main
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@SuppressWarnings("resource")
public static void main(String[] args) throws Exception {
final Directory dir = new RAMDirectory();
final Analyzer analyzer = new WhitespaceAnalyzer();
final IndexWriterConfig conf = new IndexWriterConfig(analyzer);
final IndexWriter writer = new IndexWriter(dir, conf);
addDocument(writer, "brown fox and a red dog");
addDocument(writer, "only red dog");
addDocument(writer, "no red animals here");
writer.close();
final QueryParser qp = new QueryParser(TEXT_FIELD, analyzer);
qp.setAllowLeadingWildcard(true);
final DirectoryReader reader = DirectoryReader.open(dir);
final LeafReader leaf = reader.leaves().get(0).reader(); // We only have one segment
IndexUtils.printFieldTerms(leaf, TEXT_FIELD, COLOR_FIELD, ANIMAL_FIELD);
IndexUtils.printFieldTermsWithInfo(leaf, COLOR_FIELD, ANIMAL_FIELD);
System.out.println();
final IndexSearcher searcher = new IndexSearcher(reader);
search(searcher, qp.parse("animal:" + AnyAnnotationTokenFilter.ANY_ANNOTATION_TERM + " AND color:"
+ AnyAnnotationTokenFilter.ANY_ANNOTATION_TERM));
System.out.println();
search(searcher, qp.parse("animal:" + AnyAnnotationTokenFilter.ANY_ANNOTATION_TERM + " AND color:red"));
System.out.println();
searchForRedAnimal(searcher);
System.out.println();
reader.close();
}
示例10: main
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@SuppressWarnings("resource")
public static void main(String[] args) throws Exception {
final Directory dir = new RAMDirectory();
final Analyzer analyzer = createAnalyzer();
final IndexWriterConfig conf = new IndexWriterConfig(analyzer);
final IndexWriter writer = new IndexWriter(dir, conf);
addDocument(writer, "brown fox and a red dog");
addDocument(writer, "only red dog");
addDocument(writer, "no red animals here");
writer.close();
final QueryParser qp = new QueryParser(TEXT_FIELD, analyzer);
qp.setAllowLeadingWildcard(true);
final DirectoryReader reader = DirectoryReader.open(dir);
final LeafReader leaf = reader.leaves().get(0).reader(); // We only have one segment
IndexUtils.printFieldTerms(leaf, TEXT_FIELD, COLOR_FIELD, ANIMAL_FIELD);
IndexUtils.printFieldTermsWithInfo(leaf, COLOR_FIELD, ANIMAL_FIELD);
final IndexSearcher searcher = new IndexSearcher(reader);
search(searcher, qp.parse("color:red"));
System.out.println();
search(searcher, qp.parse("animal:fox"));
System.out.println();
searchForBrownFox(searcher);
System.out.println();
search(searcher, qp.parse("animal:* AND color:*"));
System.out.println();
search(searcher, qp.parse("animal:* AND color:red"));
System.out.println();
reader.close();
}
示例11: buildQueryFromText
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
private static Query buildQueryFromText(String field, IndexSchema schema, String query) {
QueryParser queryParser = new QueryParser(Version.LUCENE_45, field, schema.getQueryAnalyzer());
queryParser.setAllowLeadingWildcard(false);
queryParser.setLowercaseExpandedTerms(false);
queryParser.setTimeZone(TimeZone.getDefault());
queryParser.setAnalyzeRangeTerms(true);
try {
return queryParser.parse(query);
} catch (org.apache.lucene.queryparser.classic.ParseException e) {
throw new RuntimeException(e);
}
}
示例12: buildSearchQuery
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
public Query buildSearchQuery(String queryString) {
QueryParser parser = new TaxonomyQueryParser(defaultTaxonomyField, this.iaViewSearchAnalyser);
parser.setAllowLeadingWildcard(true);
Query searchQuery;
try {
searchQuery = parser.parse(queryString);
} catch (ParseException e) {
throw new TaxonomyException(TaxonomyErrorType.INVALID_CATEGORY_QUERY, e);
}
return searchQuery;
}
示例13: checkCategoryQueryValidity
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
public void checkCategoryQueryValidity(String qry) {
QueryParser parser = new QueryParser("CATEGORY", this.iaViewSearchAnalyser);
parser.setAllowLeadingWildcard(true);
try {
parser.parse(qry);
} catch (ParseException e) {
throw new TaxonomyException(TaxonomyErrorType.INVALID_CATEGORY_QUERY, e);
}
}
示例14: parseConstraint
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
protected org.apache.lucene.search.Query parseConstraint(String q) {
Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_4_9);
QueryParser parser = new QueryParser(Version.LUCENE_4_9, schemaMapper.defaultField(), analyzer);
parser.setDefaultOperator(QueryParser.Operator.OR);
parser.setAllowLeadingWildcard(true);
try {
org.apache.lucene.search.Query result = parser.parse(q);
return result;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
示例15: searchByIndex
import org.apache.lucene.queryparser.classic.QueryParser; //導入方法依賴的package包/類
@Override
public Set<NitriteId> searchByIndex(String field, String searchString) {
IndexReader indexReader = null;
try {
QueryParser parser = new QueryParser(Version.LUCENE_4_9, field, analyzer);
parser.setAllowLeadingWildcard(true);
Query query = parser.parse("*" + searchString + "*");
indexReader = DirectoryReader.open(indexDirectory);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
TopScoreDocCollector collector = TopScoreDocCollector.create(MAX_SEARCH, true);
indexSearcher.search(query, collector);
TopDocs hits = collector.topDocs(0, MAX_SEARCH);
Set<NitriteId> keySet = new LinkedHashSet<>();
if (hits != null) {
ScoreDoc[] scoreDocs = hits.scoreDocs;
if (scoreDocs != null) {
for (ScoreDoc scoreDoc : scoreDocs) {
Document document = indexSearcher.doc(scoreDoc.doc);
String jsonId = document.get(CONTENT_ID);
NitriteId nitriteId = keySerializer.readValue(jsonId, NitriteId.class);
keySet.add(nitriteId);
}
}
}
return keySet;
} catch (IOException | ParseException e) {
throw new IndexingException(errorMessage(
"could not search on full-text index", 0), e);
} finally {
try {
if (indexReader != null) indexReader.close();
} catch (IOException ignored) {
// ignored
}
}
}