本文整理汇总了Java中org.apache.lucene.queryparser.classic.QueryParser.Operator类的典型用法代码示例。如果您正苦于以下问题:Java Operator类的具体用法?Java Operator怎么用?Java Operator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Operator类属于org.apache.lucene.queryparser.classic.QueryParser包,在下文中一共展示了Operator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSimilarityQuery
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
public static String getSimilarityQuery(String searchPattern, Integer maxEditDistance, Operator operator) {
if (maxEditDistance == null) {
throw new IllegalArgumentException("maxEditDistance may not be null");
}
String cleanSearchPattern = StringUtils.clean(searchPattern);
if (!StringUtils.hasText(cleanSearchPattern)) {
throw new IllegalArgumentException("cleanSearchPattern may not be empty");
}
List<String> searchPatternFragments = getSearchPatternFragments(cleanSearchPattern);
StringBuilder similarityQuery = new StringBuilder();
for (String searchPatternFragment : searchPatternFragments) {
if (similarityQuery.length() > 0) {
similarityQuery.append(" ");
if (operator != null) {
similarityQuery.append(operator).append(" ");
}
}
similarityQuery.append(searchPatternFragment).append(FUZZY_PARAMETER_SUFFIX).append(maxEditDistance.toString());
}
return similarityQuery.toString().trim();
}
示例2: testGetAutocompleteQuery
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
@Test
public void testGetAutocompleteQuery() {
assertEquals(null, LuceneUtils.getAutocompleteQuery(null));
assertEquals("", LuceneUtils.getAutocompleteQuery(""));
assertEquals("alfresc*", LuceneUtils.getAutocompleteQuery("alfresc"));
assertEquals("alfresc*", LuceneUtils.getAutocompleteQuery("alfresc*"));
assertEquals("alfresco sha*", LuceneUtils.getAutocompleteQuery("alfresco-sha"));
assertEquals("alfresco sha1*", LuceneUtils.getAutocompleteQuery("alfresco-sha1"));
assertEquals("alfresco sha1*", LuceneUtils.getAutocompleteQuery("alfresco sha1"));
assertEquals("t es t*", LuceneUtils.getAutocompleteQuery("t' -_es**t"));
assertEquals("alfresc*", LuceneUtils.getAutocompleteQuery("alfresc", Operator.AND));
assertEquals("alfresc*", LuceneUtils.getAutocompleteQuery("alfresc*", Operator.AND));
assertEquals("alfresco AND sha*", LuceneUtils.getAutocompleteQuery("alfresco-sha", Operator.AND));
assertEquals("alfresco AND sha1*", LuceneUtils.getAutocompleteQuery("alfresco-sha1", Operator.AND));
assertEquals("alfresco AND sha1*", LuceneUtils.getAutocompleteQuery("alfresco sha1", Operator.AND));
assertEquals("t AND es AND t*", LuceneUtils.getAutocompleteQuery("t' -_es**t", Operator.AND));
}
示例3: testCJKSynonymsAND2
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
/** more complex synonyms with default AND operator */
public void testCJKSynonymsAND2() throws Exception {
BooleanQuery expected = new BooleanQuery();
expected.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.MUST);
BooleanQuery inner = new BooleanQuery(true);
inner.add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
inner.add(new TermQuery(new Term("field", "國")), BooleanClause.Occur.SHOULD);
expected.add(inner, BooleanClause.Occur.MUST);
BooleanQuery inner2 = new BooleanQuery(true);
inner2.add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
inner2.add(new TermQuery(new Term("field", "國")), BooleanClause.Occur.SHOULD);
expected.add(inner2, BooleanClause.Occur.MUST);
QueryParser qp = new QueryParser("field", new MockCJKSynonymAnalyzer());
qp.setDefaultOperator(Operator.AND);
assertEquals(expected, qp.parse("中国国"));
expected.setBoost(2.0f);
assertEquals(expected, qp.parse("中国国^2"));
}
示例4: makeSureCompositeQueriesCanBeAsked
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
@Test
public void makeSureCompositeQueriesCanBeAsked()
{
Index<Node> index = nodeIndex( LuceneIndexImplementation.EXACT_CONFIG );
Node neo = graphDb.createNode();
Node trinity = graphDb.createNode();
index.add( neo, "username", "[email protected]" );
index.add( neo, "sex", "male" );
index.add( trinity, "username", "[email protected]" );
index.add( trinity, "sex", "female" );
for ( int i = 0; i < 2; i++ )
{
assertThat( index.query( "username:*@matrix AND sex:male" ), contains( neo ) );
assertThat( index.query( new QueryContext( "username:*@matrix sex:male" ).defaultOperator( Operator.AND ) ), contains( neo ) );
assertThat( index.query( "username:*@matrix OR sex:male" ), contains( neo, trinity ) );
assertThat( index.query( new QueryContext( "username:*@matrix sex:male" ).defaultOperator( Operator.OR ) ), contains( neo, trinity ) );
restartTx();
}
index.delete();
}
示例5: testCJKSynonymsAND2
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
/** more complex synonyms with default AND operator */
public void testCJKSynonymsAND2() throws Exception {
BooleanQuery expected = new BooleanQuery();
expected.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.MUST);
BooleanQuery inner = new BooleanQuery(true);
inner.add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
inner.add(new TermQuery(new Term("field", "國")), BooleanClause.Occur.SHOULD);
expected.add(inner, BooleanClause.Occur.MUST);
BooleanQuery inner2 = new BooleanQuery(true);
inner2.add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
inner2.add(new TermQuery(new Term("field", "國")), BooleanClause.Occur.SHOULD);
expected.add(inner2, BooleanClause.Occur.MUST);
QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockCJKSynonymAnalyzer());
qp.setDefaultOperator(Operator.AND);
assertEquals(expected, qp.parse("中国国"));
expected.setBoost(2.0f);
assertEquals(expected, qp.parse("中国国^2"));
}
示例6: getAutocompleteQuery
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
public static String getAutocompleteQuery(String searchPattern, int enableWildcardMinChars, Operator operator) {
String cleanSearchPattern = StringUtils.clean(searchPattern);
if(StringUtils.hasText(cleanSearchPattern) && cleanSearchPattern.length() >= enableWildcardMinChars) {
List<String> searchPatternFragments = getSearchPatternFragments(cleanSearchPattern);
StringBuilder autocompleteQuery = new StringBuilder();
Iterator<String> searchPatternFragmentsIt = searchPatternFragments.iterator();
while (searchPatternFragmentsIt.hasNext()) {
if (autocompleteQuery.length() > 0) {
autocompleteQuery.append(" ");
if (operator != null) {
autocompleteQuery.append(Operator.AND).append(" ");
}
}
autocompleteQuery.append(searchPatternFragmentsIt.next());
if (!searchPatternFragmentsIt.hasNext()) {
autocompleteQuery.append(WILDCARD_SUFFIX);
}
}
cleanSearchPattern = autocompleteQuery.toString().trim();
}
return cleanSearchPattern;
}
示例7: getQuery
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
/**
* Nettoie la chaîne de recherche et autorise une recherche avec wildcard.
*
* A noter que si stemming ou truc tordu il y a, il faut quand même faire la recherche à la fois sur le champ stemmé
* et sur un champ non stemmé sinon le wildcard pourra ne pas renvoyer de résultat.
*/
public static String getQuery(String searchPattern, Operator operator) {
String cleanSearchPattern = StringUtils.cleanForQuery(searchPattern);
if(StringUtils.hasText(cleanSearchPattern)) {
List<String> searchPatternFragments = getSearchPatternFragments(cleanSearchPattern);
StringBuilder query = new StringBuilder();
for (String searchPatternFragment : searchPatternFragments) {
if (WILDCARD_SUFFIX.equals(searchPatternFragment)) {
// si c'est juste une *, on ne peut pas faire grand chose, passons...
continue;
}
if (query.length() > 0) {
query.append(" ");
if (operator != null) {
query.append(operator).append(" ");
}
}
query.append(searchPatternFragment);
}
cleanSearchPattern = query.toString().trim();
}
return cleanSearchPattern;
}
示例8: testGetSimilarityQuery
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
@Test
public void testGetSimilarityQuery() {
assertEquals("alfresc~2", LuceneUtils.getSimilarityQuery("alfresc", 2));
assertEquals("alfresco~2 sha~2", LuceneUtils.getSimilarityQuery("alfresco-sha", 2));
assertEquals("alfresco~2 sha1~2", LuceneUtils.getSimilarityQuery("alfresco-sha1", 2));
assertEquals("alfresco~2 sha1~2", LuceneUtils.getSimilarityQuery("alfresco sha1", 2));
assertEquals("t~2 es~2 t~2", LuceneUtils.getSimilarityQuery("t' -_es**t", 2));
assertEquals("alfresc~2", LuceneUtils.getSimilarityQuery("alfresc", 2, Operator.AND));
assertEquals("alfresco~2 AND sha~2", LuceneUtils.getSimilarityQuery("alfresco-sha", 2, Operator.AND));
assertEquals("alfresco~2 AND sha1~2", LuceneUtils.getSimilarityQuery("alfresco-sha1", 2, Operator.AND));
assertEquals("alfresco~2 AND sha1~2", LuceneUtils.getSimilarityQuery("alfresco sha1", 2, Operator.AND));
assertEquals("t~2 AND es~2 AND t~2", LuceneUtils.getSimilarityQuery("t' -_es**t", 2, Operator.AND));
}
示例9: testGetQuery
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
@Test
public void testGetQuery() {
assertEquals("elephant de test", LuceneUtils.getQuery("éléphant de test"));
assertEquals("elephant de* test*", LuceneUtils.getQuery("éléphant de* test*"));
assertEquals("elephant test*", LuceneUtils.getQuery("éléphant * test*"));
assertEquals("elephant OR de OR test", LuceneUtils.getQuery("éléphant de test", Operator.OR));
assertEquals("elephant OR de* OR test*", LuceneUtils.getQuery("éléphant de* test*", Operator.OR));
assertEquals("elephant OR test*", LuceneUtils.getQuery("éléphant * test*", Operator.OR));
}
示例10: getMultiFieldQueryParser
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
@Deprecated
private MultiFieldQueryParser getMultiFieldQueryParser(FullTextEntityManager fullTextEntityManager, String[] fields, Operator defaultOperator, Analyzer analyzer) {
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer);
parser.setDefaultOperator(defaultOperator);
return parser;
}
示例11: test
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的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);
}
示例12: testSynonyms
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
/** simple synonyms test */
public void testSynonyms() throws Exception {
BooleanQuery expected = new BooleanQuery(true);
expected.add(new TermQuery(new Term("field", "dogs")), BooleanClause.Occur.SHOULD);
expected.add(new TermQuery(new Term("field", "dog")), BooleanClause.Occur.SHOULD);
QueryParser qp = new QueryParser("field", new MockSynonymAnalyzer());
assertEquals(expected, qp.parse("dogs"));
assertEquals(expected, qp.parse("\"dogs\""));
qp.setDefaultOperator(Operator.AND);
assertEquals(expected, qp.parse("dogs"));
assertEquals(expected, qp.parse("\"dogs\""));
expected.setBoost(2.0f);
assertEquals(expected, qp.parse("dogs^2"));
assertEquals(expected, qp.parse("\"dogs\"^2"));
}
示例13: testSynonymsPhrase
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
/** forms multiphrase query */
public void testSynonymsPhrase() throws Exception {
MultiPhraseQuery expected = new MultiPhraseQuery();
expected.add(new Term("field", "old"));
expected.add(new Term[] { new Term("field", "dogs"), new Term("field", "dog") });
QueryParser qp = new QueryParser("field", new MockSynonymAnalyzer());
assertEquals(expected, qp.parse("\"old dogs\""));
qp.setDefaultOperator(Operator.AND);
assertEquals(expected, qp.parse("\"old dogs\""));
expected.setBoost(2.0f);
assertEquals(expected, qp.parse("\"old dogs\"^2"));
expected.setSlop(3);
assertEquals(expected, qp.parse("\"old dogs\"~3^2"));
}
示例14: testCJKSynonym
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
/** simple CJK synonym test */
public void testCJKSynonym() throws Exception {
BooleanQuery expected = new BooleanQuery(true);
expected.add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
expected.add(new TermQuery(new Term("field", "國")), BooleanClause.Occur.SHOULD);
QueryParser qp = new QueryParser("field", new MockCJKSynonymAnalyzer());
assertEquals(expected, qp.parse("国"));
qp.setDefaultOperator(Operator.AND);
assertEquals(expected, qp.parse("国"));
expected.setBoost(2.0f);
assertEquals(expected, qp.parse("国^2"));
}
示例15: testCJKSynonymsAND
import org.apache.lucene.queryparser.classic.QueryParser.Operator; //导入依赖的package包/类
/** synonyms with default AND operator */
public void testCJKSynonymsAND() throws Exception {
BooleanQuery expected = new BooleanQuery();
expected.add(new TermQuery(new Term("field", "中")), BooleanClause.Occur.MUST);
BooleanQuery inner = new BooleanQuery(true);
inner.add(new TermQuery(new Term("field", "国")), BooleanClause.Occur.SHOULD);
inner.add(new TermQuery(new Term("field", "國")), BooleanClause.Occur.SHOULD);
expected.add(inner, BooleanClause.Occur.MUST);
QueryParser qp = new QueryParser("field", new MockCJKSynonymAnalyzer());
qp.setDefaultOperator(Operator.AND);
assertEquals(expected, qp.parse("中国"));
expected.setBoost(2.0f);
assertEquals(expected, qp.parse("中国^2"));
}