Skip to content

Commit

Permalink
Include raaga and taala aliases during solr indexing
Browse files Browse the repository at this point in the history
related to #145
- change field attribute to multivalued
- modify indexing of types with aliases ie taalas, raagas, taals, etc
  • Loading branch information
darad committed Jul 24, 2014
1 parent 96ab581 commit be4b5d1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
27 changes: 18 additions & 9 deletions carnatic/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,11 @@ def search(name):
query = "module_s:carnatic AND doctype_s:search AND title_t:(%s)" % name
results = solr.search(query, rows=100)
ret = collections.defaultdict(list)
klass_map = {"instrument": carnatic.models.Instrument,
"raaga": carnatic.models.Raaga,
"taala": carnatic.models.Taala,
"concert": carnatic.models.Concert,
"artist": carnatic.models.Artist,
"work": carnatic.models.Work,
"composer": carnatic.models.Composer}
for d in results.docs:
type = d["type_s"]
id = d["object_id_i"]
id = int(id)
klass = klass_map.get(type)
klass = get_klassmap().get(type)
if klass:
instance = klass.objects.get(pk=id)
ret[type].append(instance)
Expand All @@ -49,14 +42,22 @@ def autocomplete(term):
params['wt'] = 'json'
params['q'] = term
params['fq'] = "module_s:carnatic"
params['fl'] = "title_txt,type_s,object_id_i"
path = 'suggest/?%s' % pysolr.safe_urlencode(params, True)
response = solr._send_request('get', path)
res = json.loads(response)
check = res.get("response", {})
docs = check.get("docs", [])
ret = []
for d in docs:
ret.append(d["title_t"])
type = d["type_s"]
id = int(d["object_id_i"])
if type in ["raaga", "taala"]:
cls = get_klassmap().get(type)
obj = cls.objects.get(pk=id)
ret.append(obj.name)
else :
ret.append(d["title_txt"][0])
return ret[:5]

def get_similar_concerts(works, raagas, taalas, artists):
Expand Down Expand Up @@ -111,3 +112,11 @@ def similar_recordings(mbid):
else:
return []

def get_klassmap():
return {"instrument": carnatic.models.Instrument,
"raaga": carnatic.models.Raaga,
"taala": carnatic.models.Taala,
"concert": carnatic.models.Concert,
"artist": carnatic.models.Artist,
"work": carnatic.models.Work,
"composer": carnatic.models.Composer}
27 changes: 17 additions & 10 deletions data/management/commands/solrimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ class Command(BaseCommand):
solr = pysolr.Solr(settings.SOLR_URL)

def make_search_data(self, module, data, etype, namefield):
insert = [{"id": "%s_%s" % (etype, i.pk),
"object_id_i": i.pk,
"type_s": etype,
"module_s": module,
"title_t": getattr(i, namefield),
"doctype_s": "search"
} for i in data]
insert = []
for i in data:
doc = { "id": "%s_%s" % (etype, i.pk),
"object_id_i": i.pk,
"type_s": etype,
"module_s": module,
"title_txt": getattr(i, namefield),
"doctype_s": "search"
}
if etype in ["raaga", "taala", "laya", "raag", "taal"]:
aliases = [alias.name for alias in i.aliases.all()]
aliases.append(doc.get("title_txt"))
doc.update({"title_txt": aliases})
insert.append(doc)
return insert

def create_carnatic_search_index(self):
Expand All @@ -46,14 +53,14 @@ def create_carnatic_search_index(self):
concerts = carnatic.models.Concert.objects.all()
raagas = carnatic.models.Raaga.objects.all()
taalas = carnatic.models.Taala.objects.all()

insertinstr = self.make_search_data("carnatic", instruments, "instrument", "name")
insertartist = self.make_search_data("carnatic", artists, "artist", "name")
insertcomposer = self.make_search_data("carnatic", composers, "composer", "name")
insertwork = self.make_search_data("carnatic", works, "work", "title")
insertconcert = self.make_search_data("carnatic", concerts, "concert", "title")
insertraaga = self.make_search_data("carnatic", raagas, "raaga", "name")
inserttaala = self.make_search_data("carnatic", taalas, "taala", "name")
insertraaga = self.make_search_data("carnatic", raagas, "raaga", "common_name")
inserttaala = self.make_search_data("carnatic", taalas, "taala", "common_name")

self.solr.add(insertinstr)
self.solr.add(insertartist)
Expand Down
12 changes: 6 additions & 6 deletions solr/collection1/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

<dynamicField name="random_*" type="random" />

<field name="title_suggest" type="text_suggest" indexed="true" stored="false"/>
<field name="title_suggest_edge" type="text_suggest_edge" indexed="true" stored="false"/>
<field name="title_suggest_ngram" type="text_suggest_ngram" indexed="true" stored="false"/>
<field name="title_suggest" type="text_suggest" indexed="true" stored="false" multiValued="true"/>
<field name="title_suggest_edge" type="text_suggest_edge" indexed="true" stored="false" multiValued="true"/>
<field name="title_suggest_ngram" type="text_suggest_ngram" indexed="true" stored="false" multiValued="true"/>

<copyField source="title_t" dest="title_suggest" />
<copyField source="title_t" dest="title_suggest_edge" />
<copyField source="title_t" dest="title_suggest_ngram" />
<copyField source="title_txt" dest="title_suggest" />
<copyField source="title_txt" dest="title_suggest_edge" />
<copyField source="title_txt" dest="title_suggest_ngram" />
</fields>
<uniqueKey>id</uniqueKey>

Expand Down
2 changes: 1 addition & 1 deletion solr/collection1/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@
<str name="echoParams">explicit</str>
<str name="defType">edismax</str>
<str name="rows">10</str>
<str name="fl">title_t,score</str>
<str name="fl">title_txt,score</str>
<str name="qf">title_suggest^30 title_suggest_ngram^50.0 title_suggest_edge^20</str>
<str name="pf">title_suggest_edge</str>
<str name="sort">score desc</str>
Expand Down

0 comments on commit be4b5d1

Please sign in to comment.