-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexer_search_prefix.scala
48 lines (37 loc) · 1 KB
/
indexer_search_prefix.scala
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
import scala.io._
import scala.util.matching.Regex
object indexer_search_prefix extends App{
def apply(path:String): Map[String, Vector[String]]=
{
val file=Source.fromFile(path)
val lines=file.getLines().toList
//println(lines.length)
//for(i<-lines)
//println(i)
file.close
lines.map(_.split(" "))
.flatMap(x => x.drop(1).map(y => (y, x(0))))
.groupBy(_._1)
.map(p => (p._1, p._2.map(_._2).toVector))
}
println("Search your prefix here: ")
var s=readLine()
var m=apply("/home/practo/search_scala/indexingdoc").filter(x=> prefix(x._1 , s))
//m.foreach{i => println(i)}
//println(m.size)
m.keys.foreach{ i => println(i) }
if(m.size==0)println("No record found")
def prefix(str:String , pattern:String):Boolean=
{
var flag:Boolean=true
//val numberPattern: Regex = pattern.r
str.startsWith(pattern) match {
case true =>
flag=true
case false =>
flag=false
}
if(flag) return true
else return false
}
}