@@ -45,19 +45,32 @@ class SearchQuery(configuration: Configuration, featureExtractor: FeatureQuery)
45
45
46
46
lazy val externalToInternalFeature = internalFeatures.map(i => i.name -> i.internalName).toMap
47
47
48
- private def checkAndExecuteParsedQuery (ast : CombinatorialExpr , limit : Int ): Try [SearchHits ] = {
49
- val fields = collectFieldNames(ast )
48
+ private def checkAndExecuteParsedQuery (parsedQuery : de.upb.cs.swt.delphi.core.ql. Query , limit : Int ): Try [SearchHits ] = {
49
+ val fields = collectFieldNames(parsedQuery.expr )
50
50
51
51
val publicFieldNames = internalFeatures.map(i => i.name)
52
52
val invalidFields = fields.toSet.filter(f => ! publicFieldNames.contains(f))
53
53
54
54
if (invalidFields.size > 0 ) return Failure (new IllegalArgumentException (s " Unknown field name(s) used. ( ${invalidFields.mkString(" ," )}) " ))
55
55
56
56
val translatedFields = fields.toSet.map(externalToInternalFeature(_))
57
+ def getPrefix (in : String ) : String = {
58
+ if (in.contains(" *" )) {
59
+ in.substring(0 , in.indexOf(" *" ))
60
+ }
61
+ else {
62
+ in
63
+ }
64
+ }
65
+ val selectedFields = parsedQuery
66
+ .selections
67
+ .flatMap(f => internalFeatures.filter(i => i.name.startsWith(getPrefix(f.fieldName))))
68
+ .map(i => i.internalName)
69
+
57
70
58
71
val query = searchWithType(configuration.esProjectIndex)
59
- .query(translate(ast ))
60
- .sourceInclude(ArtifactTransformer .baseFields ++ translatedFields)
72
+ .query(translate(parsedQuery.expr ))
73
+ .sourceInclude(ArtifactTransformer .baseFields ++ translatedFields ++ selectedFields )
61
74
.limit(limit)
62
75
63
76
val response = client.execute {
@@ -154,8 +167,8 @@ class SearchQuery(configuration: Configuration, featureExtractor: FeatureQuery)
154
167
val parserResult = new Syntax (query.query).QueryRule .run()
155
168
parserResult match {
156
169
case Failure (e) => Failure (e)
157
- case Success (ast ) => {
158
- checkAndExecuteParsedQuery(ast , query.limit.getOrElse(defaultFetchSize)) match {
170
+ case Success (parsedQuery ) => {
171
+ checkAndExecuteParsedQuery(parsedQuery , query.limit.getOrElse(defaultFetchSize)) match {
159
172
case Failure (e) => Failure (e)
160
173
case Success (hits) => Success (ArtifactTransformer .transformResults(hits))
161
174
}
0 commit comments