本文整理了Java中org.apache.lucene.index.Term.<init>()
方法的一些代码示例,展示了Term.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Term.<init>()
方法的具体详情如下:
包路径:org.apache.lucene.index.Term
类名称:Term
方法名:<init>
[英]Constructs a Term with the given field and empty text. This serves two purposes: 1) reuse of a Term with the same field. 2) pattern for a query.
[中]用给定字段和空文本构造一个术语。这有两个目的:1)重复使用同一字段中的术语。2) 查询的模式。
代码示例来源:origin: neo4j/neo4j
private static void addIfAssigned( BooleanQuery.Builder builder, long node, String field )
{
if ( node != -1 )
{
builder.add( new TermQuery( new Term( field, "" + node ) ), Occur.MUST );
}
}
代码示例来源:origin: apache/nifi
private BooleanQuery buildLineageQuery(final Collection<String> flowFileUuids) {
// Create a query for all Events related to the FlowFiles of interest. We do this by adding all ID's as
// "SHOULD" clauses and then setting the minimum required to 1.
final BooleanQuery lineageQuery;
if (flowFileUuids == null || flowFileUuids.isEmpty()) {
lineageQuery = null;
} else {
lineageQuery = new BooleanQuery();
for (final String flowFileUuid : flowFileUuids) {
lineageQuery.add(new TermQuery(new Term(SearchableFields.FlowFileUUID.getSearchableFieldName(), flowFileUuid)), Occur.SHOULD);
}
lineageQuery.setMinimumNumberShouldMatch(1);
}
return lineageQuery;
}
代码示例来源:origin: stanfordnlp/CoreNLP
@Override
public Map<Integer, Set<E>> getPatternsForAllTokens(String sentId) {
try {
TermQuery query = new TermQuery(new Term("sentid", sentId));
TopDocs tp = searcher.search(query,1);
if (tp.totalHits > 0) {
for (ScoreDoc s : tp.scoreDocs) {
int docId = s.doc;
Document d = searcher.doc(docId);
byte[] st = d.getBinaryValue("patterns").bytes;
ByteArrayInputStream baip = new ByteArrayInputStream(st);
ObjectInputStream ois = new ObjectInputStream(baip);
return (Map<Integer, Set<E>>) ois.readObject();
}
} else
throw new RuntimeException("Why no patterns for sentid " + sentId + ". Number of documents in index are " + size());
}catch(IOException e){
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
return null;
}
代码示例来源:origin: neo4j/neo4j
@Test
public void testStringQueryVsQueryObject()
{
Index<Node> index = nodeIndex( LuceneIndexImplementation.FULLTEXT_CONFIG );
Node node = graphDb.createNode();
index.add( node, "name", "Mattias Persson" );
for ( int i = 0; i < 2; i++ )
{
assertContains( index.query( "name:Mattias AND name:Per*" ), node );
assertContains( index.query( "name:mattias" ), node );
assertContains( index.query( new TermQuery( new Term( "name", "mattias" ) ) ), node );
restartTx();
}
assertNull( index.query( new TermQuery( new Term( "name", "Mattias" ) ) ).getSingle() );
}
代码示例来源:origin: SciGraph/SciGraph
@Test
public void testTermQuery() throws Exception {
TermQuery query = new TermQuery(new Term(NodeProperties.LABEL, "formation"));
TopDocs docs = searcher.search(query, Integer.MAX_VALUE);
assertThat(docs.totalHits, is(1));
}
代码示例来源:origin: hibernate/hibernate-search
@Test
public void testExtractFieldNameFromPrefixQuery() {
PrefixQuery query = new PrefixQuery( new Term( "stringField", "foo*" ) );
assertFieldNames( query, FieldType.STRING, "stringField" );
}
代码示例来源:origin: querydsl/querydsl
protected Query stringContains(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
verifyArguments(operation);
Path<?> path = getPath(operation.getArg(0));
String field = toField(path);
String[] terms = convertEscaped(path, operation.getArg(1), metadata);
if (terms.length > 1) {
BooleanQuery bq = new BooleanQuery();
for (String s : terms) {
bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST);
}
return bq;
}
return new WildcardQuery(new Term(field, "*" + terms[0] + "*"));
}
代码示例来源:origin: languagetool-org/languagetool
@Override
public long getTotalTokenCount() {
LuceneSearcher luceneSearcher = getLuceneSearcher(1);
try {
RegexpQuery query = new RegexpQuery(new Term("totalTokenCount", ".*"));
TopDocs docs = luceneSearcher.searcher.search(query, 1000); // Integer.MAX_VALUE might cause OOE on wrong index
if (docs.totalHits == 0) {
throw new RuntimeException("Expected 'totalTokenCount' meta documents not found in 1grams index: " + luceneSearcher.directory);
} else if (docs.totalHits > 1000) {
throw new RuntimeException("Did not expect more than 1000 'totalTokenCount' meta documents: " + docs.totalHits + " in " + luceneSearcher.directory);
} else {
long result = 0;
for (ScoreDoc scoreDoc : docs.scoreDocs) {
long tmp = Long.parseLong(luceneSearcher.reader.document(scoreDoc.doc).get("totalTokenCount"));
if (tmp > result) {
// due to the way FrequencyIndexCreator adds these totalTokenCount fields, we must not sum them,
// but take the largest one:
result = tmp;
}
}
return result;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: larsga/Duke
Query termQuery;
if (fuzzy_search && isFuzzy(fieldName))
termQuery = new FuzzyQuery(new Term(fieldName, term));
else
termQuery = new TermQuery(new Term(fieldName, term));
parent.add(termQuery, required ? Occur.MUST : Occur.SHOULD);
代码示例来源:origin: apache/nifi
flowFileIdQuery = null;
} else {
flowFileIdQuery = new BooleanQuery();
for (final String flowFileUuid : flowFileUuids) {
flowFileIdQuery.add(new TermQuery(new Term(SearchableFields.FlowFileUUID.getSearchableFieldName(), flowFileUuid)), Occur.SHOULD);
final TopDocs uuidQueryTopDocs = searcher.getIndexSearcher().search(flowFileIdQuery, MAX_QUERY_RESULTS);
final long searchEnd = System.nanoTime();
代码示例来源:origin: oracle/opengrok
@Test
@ConditionalRun(RepositoryInstalled.MercurialInstalled.class)
public void testGetContext_4args() throws Exception {
TermQuery q1 = new TermQuery(new Term("hist", "dummy"));
StringWriter sw = new StringWriter();
assertTrue(new HistoryContext(q1).getContext(parent, base, path, sw, null));
q2.add(new Term("hist", "dummy"));
q2.add(new Term("hist", "program"));
sw = new StringWriter();
assertTrue(new HistoryContext(q2.build()).getContext(parent, base, path, sw, null));
TermQuery q3 = new TermQuery(new Term("hist", "term_does_not_exist"));
sw = new StringWriter();
assertFalse(new HistoryContext(q3).getContext(parent, base, path, sw, null));
q4.add(new TermQuery(new Term("hist", "small")), Occur.SHOULD);
q4.add(new TermQuery(new Term("hist", "target")), Occur.SHOULD);
sw = new StringWriter();
assertTrue(new HistoryContext(q4.build()).getContext(parent, base, path, sw, null));
代码示例来源:origin: stanfordnlp/CoreNLP
for(String en2: en.getValue()){
if(!processedKey || !stopWords.contains(en2.toLowerCase()))
builder.add(new BooleanClause(new TermQuery(new Term(en.getKey(), en2)), BooleanClause.Occur.MUST));
TopDocs tp = searcher.search(query, Integer.MAX_VALUE);
Set<String> sentids = new HashSet<>();
if (tp.totalHits > 0) {
代码示例来源:origin: neo4j/neo4j
@Override
public Query get( String key, Object value )
{
// TODO we do value.toString() here since initially #addToDocument didn't
// honor ValueContext, and changing it would mean changing store format.
return new TermQuery( new Term( exactKey( key ), value.toString() ) );
}
代码示例来源:origin: querydsl/querydsl
protected Query like(Operation<?> operation, QueryMetadata metadata) {
verifyArguments(operation);
Path<?> path = getPath(operation.getArg(0));
String field = toField(path);
String[] terms = convert(path, operation.getArg(1));
if (terms.length > 1) {
BooleanQuery bq = new BooleanQuery();
for (String s : terms) {
bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST);
}
return bq;
}
return new WildcardQuery(new Term(field, terms[0]));
}
代码示例来源:origin: stackoverflow.com
Query query = new TermQuery(new Term(GRAMMED_WORDS_FIELD, term));
Sort sort = new Sort(COUNT_FIELD, true);
TopDocs docs = autoCompleteSearcher.search(query, null, 5, sort);
List<String> suggestions = new ArrayList<String>();
for (ScoreDoc doc : docs.scoreDocs) {
wordsMap.put(word, sourceReader.docFreq(new Term(
fieldToAutocomplete, word)));
代码示例来源:origin: querydsl/querydsl
protected Query in(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
Path<?> path = getPath(operation.getArg(0));
String field = toField(path);
@SuppressWarnings("unchecked") //this is the expected type
Constant<Collection<?>> expectedConstant = (Constant<Collection<?>>) operation.getArg(1);
Collection<?> values = expectedConstant.getConstant();
BooleanQuery bq = new BooleanQuery();
if (Number.class.isAssignableFrom(path.getType())) {
for (Object value : values) {
TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value)));
bq.add(eq, Occur.SHOULD);
}
} else {
for (Object value : values) {
String[] str = convert(path, value);
bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
}
}
return bq;
}
代码示例来源:origin: oracle/opengrok
@Test
public void testIsEmpty() {
TermQuery q1 = new TermQuery(new Term("refs", "isEmpty"));
TermQuery q2 = new TermQuery(new Term("defs", "isEmpty"));
TermQuery q3 = new TermQuery(new Term("hist", "isEmpty"));
BooleanQuery.Builder q4 = new BooleanQuery.Builder();
q4.add(q1, Occur.MUST);
q4.add(q2, Occur.MUST);
BooleanQuery.Builder q5 = new BooleanQuery.Builder();
q5.add(q2, Occur.MUST);
q5.add(q3, Occur.MUST);
// The queries that don't contain a "hist" term are considered empty.
assertTrue(new HistoryContext(q1).isEmpty());
assertTrue(new HistoryContext(q2).isEmpty());
assertFalse(new HistoryContext(q3).isEmpty());
assertTrue(new HistoryContext(q4.build()).isEmpty());
assertFalse(new HistoryContext(q5.build()).isEmpty());
}
代码示例来源:origin: neo4j/neo4j
searcher.search( new TermQuery( new Term( field, termsRef ) ), collector );
代码示例来源:origin: soabase/exhibitor
public QueryBuilder pathExact(String path)
{
Term term = new Term(FieldNames.PATH, path);
queries.add(new TermQuery(term));
return this;
}
代码示例来源:origin: querydsl/querydsl
protected Query stringContains(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
verifyArguments(operation);
Path<?> path = getPath(operation.getArg(0));
String field = toField(path);
String[] terms = convertEscaped(path, operation.getArg(1), metadata);
if (terms.length > 1) {
BooleanQuery bq = new BooleanQuery();
for (String s : terms) {
bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST);
}
return bq;
}
return new WildcardQuery(new Term(field, "*" + terms[0] + "*"));
}
内容来源于网络,如有侵权,请联系作者删除!