Consult 2 class in Hibernate Search DSL - java

I'm using hibernate search DSL 4.4.0. And I met a problem recently.
E.g, I have 2 classes INDEXING and DATA_PROPERTY and I can't change them or creat a new class to associate 2 of them.
Now in the SQL, I use
SELECT IND.RDF_RESOURCE
FROM INDEXING IND, DATA_PROPERTY DP
WHERE IND.RDF_RESOURCE = DP.RDF_RESOURCE
AND IND.OBJECT_TYPE_ID_INDEXED IN (........)
AND DP.PARTITION_VALUE IN (......)
AND .......
Part of Lucene indexing:
mapping.entity(DatatypeProperty.class).indexed().providedId()
.property("rdfResource",ElementType.FIELD).field().analyze(Analyze.NO).store(Store.YES)
.property("partitionValue", ElementType.FIELD).field().analyze(Analyze.NO)
mapping.entity(Indexing.class).indexed().providedId()
.property("rdfResource",ElementType.FIELD).field().analyze(Analyze.NO).store(Store.YES)
There is no association between 2 of them.
How can I translate IND.RDF_RESOURCE = DP.RDF_RESOURCE in Hibernate Search DSL???
I have blocked here for a long time, thx for helping......

Related

Script fields in hibernate elasticsearch

I'm using hibernate-search-elasticsearch 5.8.2.Final and I can't figure out how to get script fields:
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-script-fields.html
Is there any way to accomplish this functionality?
This is not possible in Hibernate Search 5.8.
In Hibernate Search 5.10 you could get direct access to the REST client, send a REST request to Elasticsearch and get the result as a JSON string that you would have to parse yourself, but it is very low-level and you would not benefit from the Hibernate Search search APIs at all (no query DSL, no managed entity loading, no direct translation entity type => index name, ...).
If you want better support for this feature, don't hesitate to open a ticket on our JIRA, describing in details what you are trying to achieve and how you would have expected to be able to do that. We are currently working on Search 6.0 which brings a lot of improvements, in particular when it comes to using native features of Elasticsearch, so it just might be something we could slip into our backlog.
EDIT: I forgot to mention that, while you cannot use server-side scripts, you can still get the full source from your documents, and do some parsing in your application to achieve a similar result. This will work even in Search 5.8:
FullTextEntityManager fullTextEm = Search.getFullTextEntityManager(entityManager);
FullTextQuery query = fullTextEm.createFullTextQuery(
qb.keyword()
.onField( "tags" )
.matching( "round-based" )
.createQuery(),
VideoGame.class
)
.setProjection( ElasticsearchProjectionConstants.SCORE, ElasticsearchProjectionConstants.SOURCE );
Object[] projections = (Object[]) query.getSingleResult();
for (Object projection : projections) {
float score = (float) projection[0];
String source = (String) projection[1];
}
See this section of the documentation.

Boost one value of several on field with Spring Data Solr

I have a solr field visibility that has a set of possible values and I would like to perform a search using Spring Data Solr. I'd like to use in() and boost some but not all values if possible.
Here's an example of the search I need,
visibility:(visible^1000 archived)
or
visibility:(visible^1000 draft^500 archived)
Would this be possible in version 1.0.0.RELEASE or later versions? Currently I'm using 1.0.0.RELEASE.
Thanks, /w
I never managed to chain this query properly, but was enlightened by petrikainulainen.net on SimpleStringCriteria().
Criteria criteria = new SimpleStringCriteria("(visibility:(visible^1000) OR visibility:(draft^500) OR visibility:(archived))");
By doing as shown below you will give far higher boost to the docs that has the category as 'webpage'. Then add 'combined' criteria to your existing other criteria
Criteria webpage= new Criteria("category" ).is("webpage" ).boost((float) 1000);
Criteria document= new Criteria("category" ).is("document" ).boost((float) 2);
Criteria combined= webpage.or( document);

Can I use a manually created index and query nodes using Cypher?

Here I have created a manual/legacy index and added some nodes with certain properties into it.
IndexManager indexy = graphdb.index();
Index<Node>indexery = indexy.forNodes("Main_Twitter_Index");
indexery.add(one,"Name",one.getProperty("Name"));
indexery.add(one,"Email",one.getProperty("Email"));
indexery.add(four,"Name",four.getProperty("Name"));
indexery.add(four,"Email",four.getProperty("Email"));
Now, to query the nodes of that index neo4j suggests query, which uses a key-value pair binding. My question is can I query the same nodes added into the manual index using a simple cypher query like,
START n=node:Main_Twitter_Index(Name = 'Akina')
RETURN n
Which version of Neo4j are you using? The method you describe is the typical index search for anything before 2.0, before they added schema indexing. Your query should work, even in 2.0. Are you having problems running it?

Android SQLite Query with foreign key using stORM or an alternative

I have the following models
categories(id, name)
places(id, name, category_id)
i have a list view which displays Content based on the categories the user wants to see.
Data for Categories
1, River
2, Hill Station
3, Wild Life
4, Temples
If the user wants to see places of only category_id = 2 and 4.
How can i do a query to the database to give back a list of places which have category_id = 2 and 4.
I am using stORM library for the Database.
They have the following functions to do a query.
dao.listAll();
dao.listByExample(exampleObj);
If you switch to greenDAO, you can use a QueryBuilder, which supports IN and the likes:
http://greendao-orm.com/documentation/queries/
I use ormlite for this purpose. Check out section in the docs about the query-builder.

Association of 4 tables in hibernate

I have 4 tables involved in this query.
Campaign - many to one business
Business - one to many client
Client - one to one contact
Contact
In contact there is the field contact_name which is unique. I need to retrieve all campaigns related to contact(via client and business) which campaign field type equals 2.
What is the best way to do it with hibernate?
In SQL is will look like this:
select *
from campaign,contact, business, client
where campaign.type=2
and client.contact_id = contact.contact_id
and contact.name = 'Josh'
and client.business_id = business.business_id
and campaign.campaign_id = business.business_id
I think that the following should work.
from Compaign where Compaign.type=2 and compaign.business.client.contact.contact_name=:name
You can execute native SQL Queries too using createSQLQuery() method of Session.
You can also use Scalar Property to avoid the overhead of using ResultSetMetadata.
You can find more information on this from here

Categories

Resources