當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。