-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Semantic search storage and routing #495
Changes from all commits
4d53ed1
6205a5f
bf3d142
b2173fb
64c919d
e57b0c1
234fe16
e6d7e94
26fff8e
2f9f39d
caeeb6d
8bf711f
d708149
994d67e
f3560a8
2f0ab0a
8a3b403
0d0d95a
1dca5b2
831a983
4f4b8d4
7b8028a
5536948
23a12da
4b24776
005cce7
c99f2ed
0ecd3c8
1864a43
15d6a58
f314315
9c1ba6c
b1b0ce8
3756a53
bbf1977
6209c64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from .models import SemanticQuery | ||
|
||
|
||
@admin.register(SemanticQuery) | ||
class SemanticQueryAdmin(admin.ModelAdmin): | ||
date_hierarchy = 'created' | ||
fields = ('label', 'creator', 'created', 'query') | ||
readonly_fields = ('created', 'query') | ||
autocomplete_fields = ('creator',) | ||
search_fields = ('label',) | ||
list_display = ('id', 'label', 'creator', 'created') | ||
list_display_links = ('id', 'label') | ||
list_filter = ('created', 'creator') | ||
show_full_result_count = False | ||
|
||
def view_on_site(self, obj): | ||
return '/explore/query/{}'.format(obj.id) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 2.0.13 on 2021-07-01 15:41 | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('items', '0003_init_permissions'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='SemanticQuery', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('label', models.CharField(blank=True, max_length=100)), | ||
('query', django.contrib.postgres.fields.jsonb.JSONField()), | ||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 2.0.13 on 2021-07-08 10:49 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('items', '0004_semanticquery'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='semanticquery', | ||
name='created', | ||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='semanticquery', | ||
name='creator', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from rest_framework import serializers | ||
|
||
from .models import SemanticQuery | ||
|
||
|
||
class SemanticQuerySerializerFull(serializers.ModelSerializer): | ||
class Meta: | ||
model = SemanticQuery | ||
fields = ['id', 'label', 'query'] | ||
|
||
|
||
class SemanticQuerySerializer(serializers.ModelSerializer): | ||
class Meta(SemanticQuerySerializerFull.Meta): | ||
extra_kwargs = { | ||
'query': {'write_only': True} | ||
} | ||
|
||
def create(self, validated_data): | ||
validated_data['creator'] = self.context['request'].user | ||
return super().create(validated_data) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,8 +59,10 @@ export default class Model extends BackboneModel { | |
extend(Model.prototype, { | ||
sync: syncWithCSRF, | ||
url: function() { | ||
const superUrl = BackboneModel.prototype.url.apply(this); | ||
if (this.isNew()) return superUrl; | ||
// Django requires the trailing slash, so add it. | ||
return BackboneModel.prototype.url.apply(this) + '/'; | ||
return superUrl + '/'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't follow what's happening here. When a new model is made it shouldn't append the trailing slash? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. By default, Backbone will generate |
||
}, | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import { Namespace } from '../common-rdf/vocabulary'; | |
import ldChannel from '../common-rdf/radio'; | ||
import Node from '../common-rdf/node'; | ||
import FlatItem from '../common-adapters/flat-item-model'; | ||
import semChannel from '../semantic-search/radio'; | ||
import SemanticQuery from '../semantic-search/model'; | ||
|
||
import Controller from './explorer-event-controller'; | ||
|
||
|
@@ -16,6 +18,12 @@ function obtainer<T extends readonly string[]>(namespace: Namespace<T>) { | |
export const getSource = obtainer(source); | ||
export const getItem = obtainer(itemNs); | ||
|
||
export function getQuery(serial: string) { | ||
const model = semChannel.request('userQueries').add({ id: serial }); | ||
model.fetch(); | ||
return model; | ||
} | ||
|
||
export function sourceWithoutAnnotations(control: Controller, node: Node) { | ||
return control.resetSource(node, false); | ||
} | ||
|
@@ -69,3 +77,9 @@ export function itemWithOccurrences(control: Controller, node: Node) { | |
export function searchResultsSources(control: Controller, queryParams: any) { | ||
return control.resetSourceListFromSearchResults(queryParams); | ||
} | ||
|
||
export | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JavaScript/TypeScript allows it and it keeps the lines within 80 columns. It seemed less disruptive than using Egyptian parens for the parameter list. Please feel free to format differently when you see code like this (I've done it in more places). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem. My IDE didn't format it as a function, but the code ran without a problem, so its the language server that's wrong :) |
||
function searchResultsSemantic(control: Controller, model: SemanticQuery) { | ||
model.when('query', () => semChannel.trigger('presentQuery', model)); | ||
control.resetSemanticSearch(model); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know this method, very useful!