Add parent node to results containing query.

This commit is contained in:
adam-m 2011-12-29 13:50:14 -05:00
parent 777ed02452
commit accf9a6133
2 changed files with 41 additions and 3 deletions

View File

@ -159,7 +159,7 @@ public class KeywordSearchSimpleTopComponent extends TopComponent implements Key
* Overwrite when you want to change default persistence type. Default * Overwrite when you want to change default persistence type. Default
* persistence type is PERSISTENCE_ALWAYS * persistence type is PERSISTENCE_ALWAYS
* *
* @return TopComponent.PERSISTENCE_ALWAYS * @return TopComponent.PERSISTENCE_NEVER
*/ */
@Override @Override
public int getPersistenceType() { public int getPersistenceType() {

View File

@ -122,7 +122,7 @@ public class RegexQuery implements KeywordSearchQuery {
Node rootNode = null; Node rootNode = null;
if (things.size() > 0) { if (things.size() > 0) {
Children childThingNodes = Children childThingNodes =
Children.create(new RegexResultChildFactory(things), true); Children.create(new RegexResultQueryChildFactory(regexQuery, things), true);
rootNode = new AbstractNode(childThingNodes); rootNode = new AbstractNode(childThingNodes);
} else { } else {
@ -137,6 +137,44 @@ public class RegexQuery implements KeywordSearchQuery {
} }
/**
* factory produces top level result nodes showing query used
*/
class RegexResultQueryChildFactory extends ChildFactory<KeyValueThing> {
Collection<String> queries;
Collection<KeyValueThing> things;
RegexResultQueryChildFactory(Collection<String>queries, Collection<KeyValueThing> things) {
this.queries = queries;
this.things = things;
}
RegexResultQueryChildFactory(String query, Collection<KeyValueThing> things) {
queries = new ArrayList<String>();
queries.add(query);
this.things = things;
}
@Override
protected boolean createKeys(List<KeyValueThing> toPopulate) {
int id = 0;
for (String query : queries) {
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
map.put("Query", query);
toPopulate.add(new KeyValueThing(query, map, ++id));
}
return true;
}
@Override
protected Node createNodeForKey(KeyValueThing thing) {
return new KeyValueNode(thing, Children.create(new RegexResultChildFactory(things), true));
}
}
/** /**
* factory produces top level result nodes showing *exact* regex match result * factory produces top level result nodes showing *exact* regex match result
*/ */