blob: cb7d2af8d19ee832d64eb07a7d976920b859974e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.semantics.engine;
import java.util.Iterator;
import java.util.List;
import com.yahoo.prelude.query.Item;
import com.yahoo.prelude.query.PhraseItem;
/**
* The Matches referenced by a particular context name in a rule evaluation
*
* @author <a href="mailto:bratseth@yahoo-inc.com">Jon S Bratseth</a>
*/
public class ReferencedMatches {
private String contextName;
private List<Match> matches=new java.util.ArrayList<>(1);
public ReferencedMatches(String contextName) {
this.contextName=contextName;
}
public void addMatch(Match match) {
matches.add(match);
}
public String getContextName() { return contextName; }
public Iterator<Match> matchIterator() {
return matches.iterator();
}
/**
* Returns the item to insert from these referenced matches, or null if none
*
* @param label the label of the matches
*/
public Item toItem(String label) {
if (matches.size()==0) return null;
if (matches.size()==1) return matches.get(0).toItem(label);
PhraseItem phrase=new PhraseItem(); // TODO: Somehow allow AND items instead here
phrase.setIndexName(label);
for (Iterator<Match> i=matches.iterator(); i.hasNext(); ) {
phrase.addItem(i.next().toItem(label));
}
return phrase;
}
}
|