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


Java Occur.MUST属性代码示例

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


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

示例1: _queryClauseJoinFor

private static Occur _queryClauseJoinFor(final QueryClauseOccur occur) {
	Occur outOccur = null;
	switch(occur) {
	case MUST:
		outOccur = Occur.MUST;
		break;
	case MUST_NOT:
		outOccur = Occur.MUST_NOT;
		break;
	case SHOULD:
		outOccur = Occur.SHOULD;
		break;
	default:
		throw new IllegalArgumentException();
	}
	return outOccur;
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:17,代码来源:LuceneSearchQuery.java

示例2: createUsagesQuery

static Query createUsagesQuery(
        final @NonNull String resourceName,
        final @NonNull Set<? extends ClassIndexImpl.UsageType> mask,
        final @NonNull Occur operator) {
    Parameters.notNull("resourceName", resourceName);
    Parameters.notNull("mask", mask);
    Parameters.notNull("operator", operator);
    if (operator == Occur.SHOULD) {
        final BooleanQuery query = new BooleanQuery ();
        for (ClassIndexImpl.UsageType ut : mask) {
            final Query subQuery = new WildcardQuery(
                DocumentUtil.referencesTerm (
                    resourceName,
                    EnumSet.of(ut),
                    false));
            query.add(subQuery, operator);
        }
        return query;
    } else if (operator == Occur.MUST) {
        return new WildcardQuery(
            DocumentUtil.referencesTerm (
                resourceName,
                mask,
                false));
    } else {
        throw new IllegalArgumentException();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:QueryUtil.java

示例3: testHighlightingCommonTermsQuery

public void testHighlightingCommonTermsQuery() throws Exception {
  Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
  CommonTermsQuery query = new CommonTermsQuery(Occur.MUST, Occur.SHOULD, 3);
  query.add(new Term(FIELD_NAME, "this"));
  query.add(new Term(FIELD_NAME, "long"));
  query.add(new Term(FIELD_NAME, "very"));

  searcher = newSearcher(reader);
  TopDocs hits = searcher.search(query, 10);
  assertEquals(2, hits.totalHits);
  QueryScorer scorer = new QueryScorer(query, FIELD_NAME);
  Highlighter highlighter = new Highlighter(scorer);

  Document doc = searcher.doc(hits.scoreDocs[0].doc);
  String storedField = doc.get(FIELD_NAME);

  TokenStream stream = TokenSources.getAnyTokenStream(searcher
      .getIndexReader(), hits.scoreDocs[0].doc, FIELD_NAME, doc, analyzer);
  Fragmenter fragmenter = new SimpleSpanFragmenter(scorer);
  highlighter.setTextFragmenter(fragmenter);
  String fragment = highlighter.getBestFragment(stream, storedField);
  assertEquals("Hello <B>this</B> is a piece of text that is <B>very</B> <B>long</B> and contains too much preamble and the meat is really here which says kennedy has been shot", fragment);
  
  doc = searcher.doc(hits.scoreDocs[1].doc);
  storedField = doc.get(FIELD_NAME);

  stream = TokenSources.getAnyTokenStream(searcher
      .getIndexReader(), hits.scoreDocs[1].doc, FIELD_NAME, doc, analyzer);
  highlighter.setTextFragmenter(new SimpleSpanFragmenter(scorer));
  fragment = highlighter.getBestFragment(stream, storedField);
  assertEquals("<B>This</B> piece of text refers to Kennedy at the beginning then has a longer piece of text that is <B>very</B>", fragment);
}
 
开发者ID:europeana,项目名称:search,代码行数:32,代码来源:HighlighterTest.java

示例4: requiredOccur

private static Occur requiredOccur() {
    return random().nextBoolean() ? Occur.MUST : Occur.FILTER;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:3,代码来源:NestedHelperTests.java

示例5: testCommonTermsQueryHighlight

public void testCommonTermsQueryHighlight() throws IOException {
  Directory dir = newDirectory();
  IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET)));
  FieldType type = new FieldType(TextField.TYPE_STORED);
  type.setStoreTermVectorOffsets(true);
  type.setStoreTermVectorPositions(true);
  type.setStoreTermVectors(true);
  type.freeze();
  String[] texts = {
      "Hello this is a piece of text that is very long and contains too much preamble and the meat is really here which says kennedy has been shot",
      "This piece of text refers to Kennedy at the beginning then has a longer piece of text that is very long in the middle and finally ends with another reference to Kennedy",
      "JFK has been shot", "John Kennedy has been shot",
      "This text has a typo in referring to Keneddy",
      "wordx wordy wordz wordx wordy wordx worda wordb wordy wordc", "y z x y z a b", "lets is a the lets is a the lets is a the lets" };
  for (int i = 0; i < texts.length; i++) {
    Document doc = new Document();
    Field field = new Field("field", texts[i], type);
    doc.add(field);
    writer.addDocument(doc);
  }
  CommonTermsQuery query = new CommonTermsQuery(Occur.MUST, Occur.SHOULD, 2);
  query.add(new Term("field", "text"));
  query.add(new Term("field", "long"));
  query.add(new Term("field", "very"));
 
  FastVectorHighlighter highlighter = new FastVectorHighlighter();
  IndexReader reader = DirectoryReader.open(writer, true);
  IndexSearcher searcher = newSearcher(reader);
  TopDocs hits = searcher.search(query, 10);
  assertEquals(2, hits.totalHits);
  FieldQuery fieldQuery  = highlighter.getFieldQuery(query, reader);
  String[] bestFragments = highlighter.getBestFragments(fieldQuery, reader, hits.scoreDocs[0].doc, "field", 1000, 1);
  assertEquals("This piece of <b>text</b> refers to Kennedy at the beginning then has a longer piece of <b>text</b> that is <b>very</b> <b>long</b> in the middle and finally ends with another reference to Kennedy", bestFragments[0]);

  fieldQuery  = highlighter.getFieldQuery(query, reader);
  bestFragments = highlighter.getBestFragments(fieldQuery, reader, hits.scoreDocs[1].doc, "field", 1000, 1);
  assertEquals("Hello this is a piece of <b>text</b> that is <b>very</b> <b>long</b> and contains too much preamble and the meat is really here which says kennedy has been shot", bestFragments[0]);

  reader.close();
  writer.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:42,代码来源:FastVectorHighlighterTest.java

示例6: randomOccur

private static Occur randomOccur(Random random) {
  return random.nextBoolean() ? Occur.MUST : Occur.SHOULD;
}
 
开发者ID:europeana,项目名称:search,代码行数:3,代码来源:CommonTermsQueryTest.java

示例7: buildFrontierQuery

/**
 * This method returns a query based on a frontier set of edge ids
 * 
 * @param collectorTerms - the terms that represent the edge ids for the current frontier.
 * @param frontierSize 
 * @return a query that represents the next hops in the graph. 
 */
public FrontierQuery buildFrontierQuery(BytesRefHash collectorTerms, Integer frontierSize) {
	// TODO: pick a non-public interface.. and still support the distributed graph stuff.
	if (collectorTerms == null || collectorTerms.size() == 0) {
		// return null if there are no terms (edges) to traverse.
		return null;
	} else {
		// Create a query
		BooleanQuery frontierQuery = new BooleanQuery();
		// Optionally use the automaton based query
		// TODO: see if we should dynamically select this based
		// Based on the frontier size.
		if (useAutn) {
			// TODO: re-enable the autn compilation of graph frontier query
			//          // build an automaton based query for the frontier.
			//          Automaton autn = buildAutomaton(collectorTerms);
			//          AutomatonQuery autnQuery = new AutomatonQuery(new Term(fromField), autn);
			//          BooleanClause autnClause = new BooleanClause(autnQuery, Occur.MUST);
			//          frontierQuery.add(autnClause);
		} else {
			// Iterate and build a booleanQuery with many clauses for the query.
			BooleanQuery edgeQuery = new BooleanQuery(true);
			for (int i = 0 ; i < collectorTerms.size(); i++) {
				BytesRef ref = new BytesRef();
				collectorTerms.get(i, ref);
				// TODO: Do I need turn it into a string? it would be nice to use the bytesref instead.
				// In previous testing, if i didn't resolve it to a utf8 string, it didn't work..
				// edgeQuery.add(new TermQuery(new Term(fromField, ref)), Occur.SHOULD);
				edgeQuery.add(new TermQuery(new Term(fromField, ref.utf8ToString())), Occur.SHOULD);
			}
			BooleanClause edgeClause = new BooleanClause(edgeQuery, Occur.MUST);
			frontierQuery.add(edgeClause);
		}

		// If there is a filter to be used while crawling the graph, add that.
		if (traversalFilter != null) {
			frontierQuery.add(traversalFilter, Occur.MUST);
		} 
		// return the new query. 
		FrontierQuery fq = new FrontierQuery(frontierQuery, frontierSize);
		return fq;
	}
}
 
开发者ID:kwatters,项目名称:solrgraph,代码行数:49,代码来源:GraphQuery.java

示例8: must

public WebDSLFacet must(){
    occur = Occur.MUST;
    return this;
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:4,代码来源:WebDSLFacet.java

示例9: toOccur

public static Occur toOccur(boolean required, boolean prohibited) {
	if(required && !prohibited)		return Occur.MUST;
	if(!required && !prohibited)	return Occur.SHOULD;
	if(!required && prohibited)		return Occur.MUST_NOT;
	throw new RuntimeException("invalid Occur definition (required and prohibited)");
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:6,代码来源:OccurUtil.java


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