We need fulltext indexing in Neo4j Database with Spring Data Neo4j . Actually I am studying from that link http://neo4j.com/docs/milestone/indexing-create-advanced.html
but now methods of it are deprecated .
I study more about it from here http://docs.spring.io/autorepo/docs/spring-data-neo4j/3.2.0.M1/reference/pdf/spring-data-neo4j-reference.pdf
.I am confuse what to do . Michael Hunger yesterday told us about indexing on that Question How to filters data at node level in Neo4j Cypher .
We do indexing at Domain Level
#Indexed(indexName = "people-search", indexType=IndexType.FULLTEXT) String username
Please give more details on it
We get a solution
#Indexed(indexName = "peopleSearch", indexType=IndexType.FULLTEXT)
String postText
#Indexed(indexName = "peopleSearch", indexType=IndexType.FULLTEXT) String username
And then in Cypher we use
START item=node:peopleSearch("postText:v* OR username:*a")
return id(item) ,labels(item)
If you have any better approach then Provide us . Thanks
Related
I am trying to query a multiple nested object with Falcor. I have an user which has beside other the value follower which itself has properties like name.
I want to query the name of the user and the first 10 follower.
My Falcor server side can be seen on GitHub there is my router and resolver.
I query the user with user["KordonDev"]["name", "stars"]. And the follower with user["KordonDev"].follower[0.10]["name", "stars"].
The route for follower is user[{keys:logins}].follower[{integers:indexes}] but this doesn't catch the following query.
I tried to add it as string query.
user["KordonDev"]["name", "stars", "follower[0..10].name"] doesn't work.
The second try was to query with arrays of keys. ["user", "KordonDev", "follower", {"from":0, "to":10}, "name"] but here I don't know how to query the name of the user.
As far as I know and looking on the path parser. There is no way to do nested queries.
What you want to do is batch the query and do two queries.
user["KordonDev"]["name", "stars"]
user["KordonDev"]["follower"][0..10].name
It seems that falcor does not support this, there is even a somewhat old issue discussing how people trying to do nested queries.
to the point about the current syntax leading people to try this:
['lolomo', 0, 0, ['summary', ['item', 'summary']]]
I can see folks trying to do the same thing with the new syntax:
"lolomo[0][0]['summary', 'item.summary']"
As soon as they know they can do:
"lolomo[0][0]['summary', 'evidence']"
So it seems deep nested queries is not a functionality.
I recently started neo4j with spring-data. So far all has been working well. But now I wanted to create my first simple query. So I added a Graph Repository with a query with
#Query(value = "MATCH (agent:Person) Where agent.name = 'Agent' RETURN agent;", elementClass = Agent.class).
This doesnt return any matches, even though the findAll() method of the repository returns all entities from the db.
Can anyone explain why this is happening?
Environment: neo4j 2.0.0M3 and spring-data 2.2.1
Spring Data Neo4j is not yet compatible with Neo4j 2.0. Thus you can't use labels in your queries.
I have a Rails app on a Postgres database and I need to have a search field for the user to enter a string and look up in the database for possible address matches (within a city). In the database I have a column with full addresses.
I cannot make assumptions on the input, so I am thinking that I should first try to directly look up the address on the database somehow (using a LIKE query maybe?), and if that fails, request to a Geocoding API (i.e. Google) to return a well formatted addresses list matching the query and search those in my database.
I would appreciate any guidance on how to do this.
I don't think FTS (full text search) is what you want. You'll have to use an address API that can match addresses.
I've successfully and easily used SmartyStreets for something like this. They have a free account you can use.
http://smartystreets.com
Also if you did want to try going down the FTS route here is a Gist that explains how to do it.
https://gist.github.com/4365593
You may know it already, but postresql has a fulltext search engine integrated so it's a great time to take advantage of it. I suggest watching thats excellent railscast.
Then once implemented :
class Place < AR
def search_db_or_geokit(query)
res = db_search()
if res.empty?
res = geokit_search(query)
else
res
end
end
def geokit_search(query)
# ...
end
def db_search(query)
# ...
end
end
For the geocoding google search api there's probably a good gem out there like geokit
In my rails app i'm fetching data from mysql database, part of code:
#search = ArtLookup.find(:all, :conditions => ['MATCH (ARL_SEARCH_NUMBER) AGAINST(? IN BOOLEAN MODE) and ARL_KIND = 1', search_condition.gsub(/[^0-9A-Za-z]/, '')])
But main trouble that i have different suppliers price list's, and there i have different coding's for same variable in db, for example:
LEMFÖRDER
But how can i set dictionary for my search_condition so that if my search_condition is for example:
LEM?FORDER or
LEMFOERDER or
LEMFÖRDER
It will find my LEMFÖRDER in db?
I know that it could sound very strange, sorry for my english, but i explain all on my example...
I think that, in this case, you should start using a library to deal with full-text-search and additional search capabilities, like Solr or Sphinx.
Take a look at http://pat.github.com/ts/en/searching.html.
This kind of complexity is common and it is already implemented in many algorithms.
Hope it helps!
You could do this by using ActiveRecord's AREL engine like the following:
def lookup(*alternatives)
match_condition = 'MATCH (ARL_SEARCH_NUMBER) AGAINST(? IN BOOLEAN MODE)'
or_conditions = alternatives.map do |alternative|
ArtLookup.where(match_condition, alternative).
where_values.reduce(:and)
end
and_condition = ArtLookup.where('ARL_KIND = 1').where_values.reduce(:and)
# Build a disjunction
conditions = or_conditions.shift
or_conditions.each do |condition|
conditions = conditions.or(condition)
end
# Build the final conjunction
conditions = conditions.and(and_condition)
ArtLookup.where(conditions)
end
Then you can find the objects like the following:
#search = lookup('LEM?FORDER', 'LEMFOERDER', 'LEMFÖRDER')
Or directly provide an array:
alternatives = [
'LEM?FORDER',
'LEMFOERDER',
'LEMFÖRDER'
]
#search = lookup(*alternatives)
I'm aware of the fact that this is far too much code for the simple thing it's doing. But it should do it and I'm not aware of a much better way. I didn't test that code, so it could contain some minor mistakes.
If I've understood your question correctly, you want to have Mysql treat those three values as the same thing. Now, assuming that they are considered the same thing in a specific language (for example, ß = ss in German), Mysql will handle this automatically based on your collation settings, so selecting the correct collation should fix it for you.
I am running on Neo4j (1.4) using Neo4j.rb gem (1.2.2) on Rails 3.1
I bumped into problem where neo4j index was corrupted that I cant run the database anymore, as mentioned in several forums like this I deleted the db/index dir and it worked. However I need to rebuild the index again.
I could not find anywhere in the docs on how to rebuild the index, could anybody please help?
Thanks alot!
You should go into your database directory and remove
Directory named index
The file index.db
and later on traverse the hole set of nodes and edges, updating the properties of each node.
/purbon
My problem was similar - after upgrading to neo4j 1.5 (from 1.4) my indexes got corrupted.
My case:
I had two indexes:
__types__ : for indexing the type of persisted objects (provided by spring-data-neo4j 2.0.0.RC1)
User : for indexing the username field, so I could do lookups after them
This resulted in a major problem, where I could find all the nodes by their id, but could not do lookups after username, or list all objects of a certain type.
The fix ( I will provide java code, but the idea would be the same in other languages too):
/* begin a transaction */
Transaction tx = graphDatabaseService.beginTx();
/* for all nodes in the database */
for (Node node : graphDatabaseService.getAllNodes()) {
/* reconstruct the saved object based on the __type__ property on the node - the result is a class that was annotated with #NodeEntity */
DefaultDbNode ddn = neo4jTemplate.createEntityFromStoredType(node,
null);
/* reindex this node, adding it to the __types__ index, with key "className" (it is used by spring-data-neo4j) with the value __type__ */
graphDatabaseService.index().forNodes("__types__")
.add(node, "className", node.getProperty("__type__"));
/* if the reconstructed object is a User object */
if (ddn instanceof User) {
/* add it to the User index, with the key "username" (which is also the saved fields name) */
graphDatabaseService.index().forNodes("User")
.add(node, "username", node.getProperty("username"));
}
}
/* end transaction */
tx.success();
tx.finish();
Hope this helps you or someone out!
Thanks to all who tried to help. In my case I have successfully solved the problem by taking the following steps:
Step 1 Following the recommendation from Neo4j's Michael Hunger (via mailing list), I used a tool called checkindex to remove corrupt index entries Lucene and Solr's Checkindex
Step 2 Upon removal of corrupt index entries, the remaining problem is to build them so Lucene can start querying them again. This could simply be done using using Model.addindex(:index_name). Note that this operation needs to be wrapped within a Neo4j::Transaction. In my case I ran it on railsconsole but I suppose you could also code them within the rails app.
Example:
Neo4j::Transaction.run do
User.all.each do |user|
user.add_index(:first_name)
user.add_index(:email)
user.save
end
end
Hope this could help others who face the same problems.
Cheers